spec/subroute_spec.rb in lookout-rack-utils-1.5.0 vs spec/subroute_spec.rb in lookout-rack-utils-1.6.0
- old
+ new
@@ -15,10 +15,24 @@
end
get '/subrouted/:id' do |id|
subroute!('/test_route', :id => id)
end
+
+ delete '/test_delete' do
+ status 201
+ { :deleted => true }.to_json
+ end
+
+ get '/test_delete' do
+ subroute!('/test_delete', :request_method => 'DELETE')
+ end
+
+ get '/multiroute' do
+ subroute!('/test_delete', :request_method => 'DELETE')
+ subroute!('/test_route', :id => 1)
+ end
end
end
context "without params" do
it 'should return the status code and body of the route' do
@@ -32,9 +46,36 @@
subject(:subrouted) { get "/subrouted/#{id}?key=value" }
it 'should return expected value' do
expect([subrouted.status, subrouted.body]).to eql [200, body]
+ end
+ end
+
+ context 'changing the http verb' do
+ context 'to a valid verb' do
+ subject(:subrouted) { get "/test_delete" }
+
+ its(:status) { should be 201 }
+
+ it 'should return expected output' do
+ expect(JSON.parse(subrouted.body)['deleted']).to be_true
+ end
+ end
+
+ context 'to an invalid verb' do
+ subject(:subrouted) { subroute!('/test_delete_invalid', :request_path => 'DELATE') }
+
+ it 'should throw an error' do
+ expect { subrouted }.to raise_error
+ end
+ end
+
+ context 'with multiple subroutes' do
+ subject(:subrouted) { get '/multiroute' }
+ it 'should return the status and body of the second subroute' do
+ expect([subrouted.status, subrouted.body]).to eql [200, { :id => 1 }.to_json]
+ end
end
end
end
describe '#succeeded?' do