2

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.

Schneems
  • 14,918
  • 9
  • 57
  • 84

2 Answers2

1

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.

dombesz
  • 7,890
  • 5
  • 38
  • 47
0

I believe the shoulda syntax is:

should_respond_with :success

instead of:

should respond_with :success

Greg Fairbrother
  • 1,041
  • 8
  • 13
  • should_respond_with :success macro was deprecated in v2.11.x in favor of using should respond_with(:success) – Vizjerai Feb 21 '11 at 20:14