Schneems
Schneems

Reputation: 15828

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.

Upvotes: 2

Views: 698

Answers (2)

Greg Fairbrother
Greg Fairbrother

Reputation: 1041

I believe the shoulda syntax is:

should_respond_with :success

instead of:

should respond_with :success

Upvotes: 0

dombesz
dombesz

Reputation: 7899

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.

Upvotes: 1

Related Questions