You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Testing resources in rails via routing specs in RSpec can be verbose.
For an entire resource, that means tests for all 7 actions:
it'get to show'doexpect({:get=>"admin/posts/1"}).toroute_to({:controller=>"admin/posts",:action=>"show",:id=>"1"})endit'get to index'doexpect({:get=>"admin/posts"}).toroute_to({:controller=>"admin/posts",:action=>"index"})endit'get to new'doexpect({:get=>"admin/posts/new"}).toroute_to({:controller=>"admin/posts",:action=>"new"})endit'get to edit'doexpect({:get=>"admin/posts/1/edit"}).toroute_to({:controller=>"admin/posts",:action=>"edit",:id=>"1"})endit'post to create'doexpect({:post=>"admin/posts"}).toroute_to({:controller=>"admin/posts",:action=>"create"})endit'delete to destroy'doexpect({:delete=>"admin/posts/1"}).toroute_to({:controller=>"admin/posts",:action=>"destroy",:id=>"1"})endit'patch to update'doexpect({:patch=>"admin/posts/1"}).toroute_to({:controller=>"admin/posts",:action=>"update",:id=>"1"})end
I have a few custom matchers to help with this, currently the DSL is:
You could implement and share these as a gem if you found others were interested, however it's not something we'd bring into rspec-rails. rspec-rails is a pretty thin wrapper around the test helpers rails provides, if they were to bring this into their helpers (probably as assert_resourceful_routes) we'd similarly then expose it.
As an aside however this isn't particularly useful testing, you're asserting that rails is doing it's job with 20 LOC in your tests for 1 LOC in your router, generally things like that don't need to be continually tested, it just adds to your build time with little chance of going wrong after it's committed.
Testing resources in rails via routing specs in RSpec can be verbose.
For an entire resource, that means tests for all 7 actions:
I have a few custom matchers to help with this, currently the DSL is:
or
Would the RSpec team be interested in those matchers or is the use case here too specific?
The text was updated successfully, but these errors were encountered: