Functional Tests with custom routes

Say I have a custom route like this…

map.connect ‘item/:id/some_action’, :controller => ‘object’, :action =>
‘change_color’, :conditions => {:method => :put}

I’ve been writing my tests like this…

describe ObjectController
describe “PUT item/:id/some_action” do
[…]
put :change_color, {:id => ‘blue’}
[…]
end
end

So the test doesn’t actually test the url - “item/blue/some_action”, but
rather the underlying Controller/Action that implements it.

Is there a way to write my tests “in terms of” the url - something
like…

describe ObjectController
describe “PUT item/:id/some_action” do
[…]
put “item/blue/some_action”
[…]
end
end

Or are controller tests simply not the place to do this, and I should do
it in Cucumber or something?

Cheers

…not the place to do this, and I should do it in Cucumber or
something?

Yes!

The concept of testing controllers, views and models separately, is
related to isolation of concerns. Your controller test is just that,
testing the controller, regardless of routing, views, models, etc.
You’re unit testing, so to speak, just object#change_color. This is why
mocks and stubs are created as well, to remove the coupling of the three
so you can test each on it’s own.

Grain of salt disclaimer, I’m not to far down my BDD journey with Rails
with RSpec and Cucumber myself… I’m using the RSpec Book as my
guide, and finding useful in helping me balance theory and practical
application (e.g. writing good tests). I’m not plugging it, I’m just
letting you know my background.

b

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs