[rspec-users] Making sure a action exists (aka specing a controller action)
dchelimsky at gmail.com
Wed Jul 22 13:23:38 EDT 2009
On Wed, Jul 22, 2009 at 11:19 AM, Marcelo de Moraes
Serpa<celoserpa at gmail.com> wrote:
> 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
> 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!
So it looks like you've uncovered a rspec-rails bug. I'm not sure when
it appeared because I'm pretty sure there was a time when this would
work as you expect, but right now there are no specs for missing
actions - only missing templates - so something in rspec-rails is
consuming the fact that the action is missing.
I added https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/860
- please feel free to follow and/or add comments to that ticket.
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users