grape-swagger/spec/lib/optional_object_spec.rb

44 lines
1.2 KiB
Ruby
Raw Normal View History

2016-03-16 08:18:07 +08:00
require 'spec_helper'
describe GrapeSwagger::DocMethods::OptionalObject do
subject { described_class }
specify { expect(subject).to eql GrapeSwagger::DocMethods::OptionalObject }
specify { expect(subject).to respond_to :build }
describe 'build' do
let(:key) { :host }
let!(:request) { Rack::Request.new(Rack::MockRequest.env_for('http://example.com:8080/')) }
2016-03-16 08:18:07 +08:00
describe 'no option given for host, take from request' do
2016-05-07 03:00:36 +08:00
let(:options) { { foo: 'foo' } }
2016-03-16 08:18:07 +08:00
specify do
expect(subject.build(key, options, request)).to eql request.host_with_port
2016-03-16 08:18:07 +08:00
end
end
let(:value) { 'grape-swagger.example.com' }
2016-03-16 08:18:07 +08:00
describe 'option is a string' do
let(:options) { { host: value } }
2016-03-16 08:18:07 +08:00
specify do
expect(subject.build(key, options, request)).to eql value
end
end
describe 'option is a lambda' do
let(:options) { { host: -> { value } } }
2016-03-16 08:18:07 +08:00
specify do
expect(subject.build(key, options, request)).to eql value
end
end
describe 'option is a proc' do
let(:options) { { host: proc { |request| request.host =~ /^example/ ? '/api-example' : '/api' } } }
specify do
expect(subject.build(key, options, request)).to eql '/api-example'
end
end
2016-03-16 08:18:07 +08:00
end
end