Helps track why the controller is down.

I have user_controller_spec.rb that fails and I'm not sure why.

require 'spec_helper' describe UsersController do describe "GET 'index'" do it "should be successful" do get 'index' response.should be_success end end end 

When I run rspec, it says:

 Failures: 1) UsersController GET 'index' should be successful Failure/Error: response.should be_success expected success? to return true, got false # ./spec/controllers/users_controller_spec.rb:8 Finished in 0.17047 seconds 1 example, 1 failure 

Going to / home / page in the browser works fine.

Is there a way to get a more detailed reason for the failure?

Note:

This is rails3 and I am using rspec.

I also have a capybara stone, and a search for my solution shows that the only link to capybara is in my gem and gem.lock file.

+6
source share
2 answers

Perhaps you are not just displaying the page, but also redirecting it. To check what might be wrong, I would do something like in my specification:

 response.should == 1 

to find out what the actual answer is. This will give you a good idea of ​​what is going on.

+1
source

You can try to output the body of the response to find out what the message is. There may be anything from the user in which you are logged in, because you do not have the correct permissions (or anonymously visit the page so that you are logged in to see), to a strange presentation error in the test environment.

 get 'index' puts response.body.inspect puts response.status.inspect ... response.should be_success 

response.body will contain the HTML output of the response, so you should be able to say why it failed (I hope it will have a stack trace or will have a redirect or something else). Also keep in mind that redirecting is not a "success". If I remember be_success , make sure that the HTTP status code is one of the 200s, redirects are usually 302 or 304, so do not consider. If redirection is intended, try response.should be_redirect .

+2
source

Source: https://habr.com/ru/post/888464/


All Articles