Jon
Jon

Reputation: 4055

Upgrading from RSpec 2.11 to 2.12

I'm upgrading RSpec and having problems with 2 elements in particular. I'm following this tutorial and, specifically, I'm having trouble with the method

def sign_in(user)
  visit root_path
  fill_in "Email", with: user.email
  fill_in "Password", with: user.password
  click_button "Sign in"
  # Sign in when not using Capybara as well.
  cookies[:remember_token] = user.remember_token
end

where I get an error

undefined local variable or method `cookies' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_3::Nested_3::Nested_1:0x79b9c90>

Additionally I have another error

before {put user_path(user)}

gives

undefined method `put' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_3::Nested_1::Nested_2::Nested_3:0x7939830>

For the first, error, I was trying to follow the steps in the RSpec docs but I can't seem to figure out how to get an RSpec response object from a Capybara page (the result of calling click_button). For the second error, I'm really at a loss. It looks like RSpec just removed the put function, and I don't know how to get it back.

Upvotes: 2

Views: 456

Answers (1)

Bryan Liff
Bryan Liff

Reputation: 439

This is not an RSpec problem, rather an Request/Integration vs Functional/Controller spec issue.

Capybara, or more specifically 'request' or 'integration' specs do not provide access to the request methods like put() or get() - these are only in controller specs that live specs/controllers/. The same with the cookies[] hash and other variables available when you are testing the controllers directly.

See this gist for a work-around.

Upvotes: 2

Related Questions