Skip to content

Commit 2b1b0c6

Browse files
committed
Add specs for Routing#route
1 parent 51fba2b commit 2b1b0c6

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

spec/grape/dsl/routing_spec.rb

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,43 @@ class Dummy
6464
expect(app2.inheritable_setting.to_hash[:namespace_stackable]).to eq(:mount_path => ['/app1', '/app2'])
6565
end
6666
end
67-
xdescribe '.route' do
68-
it 'does some thing'
67+
68+
describe '.route' do
69+
before do
70+
allow(subject).to receive(:endpoints).and_return([])
71+
allow(subject).to receive(:route_end)
72+
allow(subject).to receive(:reset_validations!)
73+
end
74+
75+
it 'marks end of the route' do
76+
expect(subject).to receive(:route_end)
77+
subject.route(:any)
78+
end
79+
80+
it 'resets validations' do
81+
expect(subject).to receive(:reset_validations!)
82+
subject.route(:any)
83+
end
84+
85+
it 'defines a new endpoint' do
86+
expect { subject.route(:any) }
87+
.to change{ subject.endpoints.count }.from(0).to(1)
88+
end
89+
90+
it 'generates correct endpoint options' do
91+
allow(subject).to receive(:route_setting).with(:description).and_return(fiz: 'baz')
92+
allow(Grape::DSL::Configuration).to receive(:stacked_hash_to_hash).and_return(nuz: 'naz')
93+
94+
expect(Grape::Endpoint).to receive(:new) do |inheritable_setting, endpoint_options|
95+
puts endpoint_options
96+
expect(endpoint_options[:method]).to eq :get
97+
expect(endpoint_options[:path]).to eq '/foo'
98+
expect(endpoint_options[:for]).to eq subject
99+
expect(endpoint_options[:route_options]).to eq(foo: 'bar', fiz: 'baz', params: { nuz: 'naz' })
100+
end.and_yield
101+
102+
subject.route(:get, '/foo', { foo: 'bar' }, &proc{})
103+
end
69104
end
70105

71106
describe '.get' do

0 commit comments

Comments
 (0)