[rspec-users] Possible improvements to routing spec API

David Chelimsky dchelimsky at gmail.com
Tue Jul 6 09:14:13 EDT 2010


On Jul 5, 2010, at 2:59 PM, Lalish-Menagh, Trevor wrote:
> OK, I will chime in here, since I think I might have opened up this
> can of worms. :)
> 
> I agree with David that we should stick with wrapping the Rails public
> APIs. That is: assert_generates, assert_recognizes, and assert_routing
> (http://edgeapi.rubyonrails.org/classes/ActionDispatch/Assertions/RoutingAssertions.html).
> 
> OK, here is my thoughts on a format:
> http://gist.github.com/464636
> 
> I want it to be readable in English, so let's try:
> describe "routing" do
>  specify "days#index" do
>    route get('/days').should generate 'days#index' # wraps assert_generates
>  end
> end
> 
> specify [that the] route [path] get('/days') should generate [the
> options] 'days#index'
> 
> OK! Next:
> describe "routing" do
>  specify "days#index" do
>    routing 'days#index'.should recognize get('/days') # wraps assert_recognizes
>  end
> end
> 
> specify [that the] route [options] 'days#index' should recognize [the
> path] get('/days')
> 
> (Might need some work... but it is uniform). Next:
> describe "routing" do
>  specify "days#index" do
>    route get('/days').should be 'days#index' # wraps assert_routing
>  end
> end
> 
> specify [that the] route [path] get('/days') should be [the options]
> 'days#index'
> 
> Finally, this makes nested routes (my original issue) look nice:
> describe "routing" do
>  specify "days#index" do
>    route 'days#index'.should recognize get('/students/1/days') with
> :student_id => '1'
>  end
> end
> 
> specify [that the] route [options] 'days#index' should recognize [the
> path] get('/students/1/days') with [extras] :student_id => '1'
> 
> You could also write out the options longhand to include the extras,
> but I think this is too ugly:
> describe "routing" do
>  specify "days#index" do
>    route {:controller => 'days', :action => 'index', :student_id =>
> '1'}.should recognize ('/students/1/days')
>  end
> end
> 
> specify [that the] route [options] {:controller => 'days', :action =>
> 'index', :student_id => '1'} should recognize [the path]
> ('/students/1/days')
> 
> What do you think?
> 
> Trevor

Hey Trevor,

These are all great DSL ideas, but they strike me as being sufficiently different from anything else in either RSpec or Rails that it would be for confusing for users.

Do you have any thoughts on the other proposals?

Cheers,
David


More information about the rspec-users mailing list