Skip to content

Commit

Permalink
Split Paths specs into separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
drewish committed Apr 2, 2019
1 parent 473324a commit fd643be
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 75 deletions.
76 changes: 76 additions & 0 deletions spec/rspec/rails/swagger/helpers_paths_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require 'swagger_helper'

RSpec.describe RSpec::Rails::Swagger::Helpers::Paths do
let(:klass) do
Class.new do
include RSpec::Rails::Swagger::Helpers::Paths
attr_accessor :metadata
def describe *args ; end
end
end
subject { klass.new }

it "requires the path start with a /" do
expect{ subject.path("foo") }.to raise_exception(ArgumentError)
expect{ subject.path("/foo") }.not_to raise_exception
end

describe 'swagger_doc' do
context 'with value specified in parent context' do
before { subject.metadata = {swagger_doc: 'default.json'} }

it "defaults to the parent value" do
expect(subject).to receive(:describe).with("/ping", {
swagger_object: :path_item,
swagger_doc: 'default.json',
swagger_path_item: {path: '/ping'}
})

subject.path('/ping')
end

it "uses the argument when provided" do
expect(subject).to receive(:describe).with("/ping", {
swagger_object: :path_item,
swagger_doc: 'overridden.json',
swagger_path_item: {path: '/ping'}
})

subject.path('/ping', swagger_doc: 'overridden.json')
end
end

context 'without a parent swagger_doc' do
it "defaults to the first swagger document" do
expect(subject).to receive(:describe).with("/ping", {
swagger_object: :path_item,
swagger_doc: RSpec.configuration.swagger_docs.keys.first,
swagger_path_item: {path: '/ping'}
})

subject.path('/ping')
end

it "uses the argument when provided" do
expect(subject).to receive(:describe).with("/ping", {
swagger_object: :path_item,
swagger_doc: 'overridden.json',
swagger_path_item: {path: '/ping'}
})

subject.path('/ping', swagger_doc: 'overridden.json')
end
end
end

it "passes tags through to the metadata" do
expect(subject).to receive(:describe).with("/ping", {
swagger_object: :path_item,
swagger_doc: RSpec.configuration.swagger_docs.keys.first,
swagger_path_item: {path: '/ping'},
tags: ['tag1']
})

subject.path('/ping', tags: ['tag1'])
end
end
75 changes: 0 additions & 75 deletions spec/rspec/rails/swagger/helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,80 +1,5 @@
require 'swagger_helper'

RSpec.describe RSpec::Rails::Swagger::Helpers::Paths do
let(:klass) do
Class.new do
include RSpec::Rails::Swagger::Helpers::Paths
attr_accessor :metadata
def describe *args ; end
end
end
subject { klass.new }

it "requires the path start with a /" do
expect{ subject.path("foo") }.to raise_exception(ArgumentError)
expect{ subject.path("/foo") }.not_to raise_exception
end

describe 'swagger_doc' do
context 'with value specified in parent context' do
before { subject.metadata = {swagger_doc: 'default.json'} }

it "defaults to the parent value" do
expect(subject).to receive(:describe).with("/ping", {
swagger_object: :path_item,
swagger_doc: 'default.json',
swagger_path_item: {path: '/ping'}
})

subject.path('/ping')
end

it "uses the argument when provided" do
expect(subject).to receive(:describe).with("/ping", {
swagger_object: :path_item,
swagger_doc: 'overridden.json',
swagger_path_item: {path: '/ping'}
})

subject.path('/ping', swagger_doc: 'overridden.json')
end
end

context 'without a parent swagger_doc' do
it "defaults to the first swagger document" do
expect(subject).to receive(:describe).with("/ping", {
swagger_object: :path_item,
swagger_doc: RSpec.configuration.swagger_docs.keys.first,
swagger_path_item: {path: '/ping'}
})

subject.path('/ping')
end

it "uses the argument when provided" do
expect(subject).to receive(:describe).with("/ping", {
swagger_object: :path_item,
swagger_doc: 'overridden.json',
swagger_path_item: {path: '/ping'}
})

subject.path('/ping', swagger_doc: 'overridden.json')
end
end
end

it "passes tags through to the metadata" do
expect(subject).to receive(:describe).with("/ping", {
swagger_object: :path_item,
swagger_doc: RSpec.configuration.swagger_docs.keys.first,
swagger_path_item: {path: '/ping'},
tags: ['tag1']
})

subject.path('/ping', tags: ['tag1'])
end
end

RSpec.describe RSpec::Rails::Swagger::Helpers::PathItem do
let(:klass) do
Class.new do
Expand Down

0 comments on commit fd643be

Please sign in to comment.