[rspec-users] Making sure a action exists (aka specing a controller action)
Marcelo de Moraes Serpa
celoserpa at gmail.com
Wed Jul 22 12:19:24 EDT 2009
Hello list!
In my efforts of following BDD in a disciplined manner, I found myself
needing to spec a Rails action.
The behavior I wanted to test was: "This controller should handle the
index action", and since it is not good practice to go to the
implementation before specing, I decided to spec the action too, so I
could start defining it. I did:
describe MyController do
it "should handle get requests to the index action" do
get :index
response.should be_success
end
The problem is the assertion. Even if you don't have the action, the
http response will be 200 OK. I tried to check for the "Unknown
Action" text (with the have_text matcher) but strangely enough, even
if you don't have the action defined in the controller, the response
body is always empty (which doesn't happen if you request from
mongrel, which shows an "Unknown action" page.
Any ideas on how I could assert that the index action exists and that
it fails when it is not there? Maybe this test doesn't make sense? Any
suggestions welcome!
Thanks,
Marcelo.
More information about the rspec-users
mailing list