简体   繁体   中英

Get HTTP response Using Shoulda Ruby on Rails

I'm migrating over to shoulda from rspec and I can't seem to get access to the http response. Can someone point out what I may be doing wrong?

  context "doing somethin" do
      setup do
        get :index
      end
      @response.body
      should respond_with :success
  end

When i run this i get an error saying that @response is a nill object.

If you want to access the response you should first wrap into a "should" like this:

context "doing somethin" do
  setup do
    get :index
  end

  should "i access..." do
   assert response.status, 200
  end
end

It's like you try to use the response outside a test, each should represents a test case, and a context is like a before(:each) in rspec.

I believe the shoulda syntax is:

should_respond_with :success

instead of:

should respond_with :success

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM