spec/grape/dsl/inside_route_spec.rb in grape-0.11.0 vs spec/grape/dsl/inside_route_spec.rb in grape-0.12.0
- old
+ new
@@ -105,10 +105,29 @@
it 'returns status set' do
subject.status 501
expect(subject.status).to eq 501
end
+
+ it 'accepts symbol for status' do
+ subject.status :see_other
+ expect(subject.status).to eq 303
+ end
+
+ it 'raises error if unknow symbol is passed' do
+ expect { subject.status :foo_bar }
+ .to raise_error(ArgumentError, 'Status code :foo_bar is invalid.')
+ end
+
+ it 'accepts unknown Fixnum status codes' do
+ expect { subject.status 210 }.to_not raise_error
+ end
+
+ it 'raises error if status is not a fixnum or symbol' do
+ expect { subject.status Object.new }
+ .to raise_error(ArgumentError, 'Status code must be Fixnum or Symbol.')
+ end
end
describe '#header' do
describe 'set' do
before do
@@ -174,10 +193,26 @@
it 'returns default' do
expect(subject.body).to be nil
end
end
+ describe '#file' do
+ describe 'set' do
+ before do
+ subject.file 'file'
+ end
+
+ it 'returns value' do
+ expect(subject.file).to eq 'file'
+ end
+ end
+
+ it 'returns default' do
+ expect(subject.file).to be nil
+ end
+ end
+
describe '#route' do
before do
subject.env['rack.routing_args'] = {}
subject.env['rack.routing_args'][:route_info] = 'dummy'
end
@@ -218,33 +253,54 @@
end
end
end
end
- describe 'with' do
- describe 'multiple entities' do
- let(:entity_mock1) do
- entity_mock1 = Object.new
- allow(entity_mock1).to receive(:represent).and_return(dummy1: 'dummy1')
- entity_mock1
+ describe 'multiple entities' do
+ let(:entity_mock1) do
+ entity_mock1 = Object.new
+ allow(entity_mock1).to receive(:represent).and_return(dummy1: 'dummy1')
+ entity_mock1
+ end
+
+ let(:entity_mock2) do
+ entity_mock2 = Object.new
+ allow(entity_mock2).to receive(:represent).and_return(dummy2: 'dummy2')
+ entity_mock2
+ end
+
+ describe 'instance' do
+ before do
+ subject.present 'dummy1', with: entity_mock1
+ subject.present 'dummy2', with: entity_mock2
end
- let(:entity_mock2) do
- entity_mock2 = Object.new
- allow(entity_mock2).to receive(:represent).and_return(dummy2: 'dummy2')
- entity_mock2
+ it 'presents both dummy objects' do
+ expect(subject.body[:dummy1]).to eq 'dummy1'
+ expect(subject.body[:dummy2]).to eq 'dummy2'
end
+ end
+ end
- describe 'instance' do
- before do
- subject.present 'dummy1', with: entity_mock1
- subject.present 'dummy2', with: entity_mock2
- end
+ describe 'non mergeable entity' do
+ let(:entity_mock1) do
+ entity_mock1 = Object.new
+ allow(entity_mock1).to receive(:represent).and_return(dummy1: 'dummy1')
+ entity_mock1
+ end
- it 'presents both dummy objects' do
- expect(subject.body[:dummy1]).to eq 'dummy1'
- expect(subject.body[:dummy2]).to eq 'dummy2'
- end
+ let(:entity_mock2) do
+ entity_mock2 = Object.new
+ allow(entity_mock2).to receive(:represent).and_return('not a hash')
+ entity_mock2
+ end
+
+ describe 'instance' do
+ it 'fails' do
+ subject.present 'dummy1', with: entity_mock1
+ expect do
+ subject.present 'dummy2', with: entity_mock2
+ end.to raise_error ArgumentError, 'Representation of type String cannot be merged.'
end
end
end
end