从RSpec 2.11升级到2.12

时间:2013-01-31 02:14:33

标签: ruby-on-rails rspec capybara

我正在升级RSpec并特别遇到2个元素的问题。我是following this tutorial,具体来说,我遇到了方法

的问题
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

我收到错误

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

此外我还有其他错误

before {put user_path(user)}

给出

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

对于第一个错误,我试图遵循steps in the RSpec docs,但我似乎无法弄清楚如何从Capybara页面获取RSpec响应对象(调用click_button的结果)。对于第二个错误,我真的很茫然。看起来RSpec刚刚删除了put函数,我不知道如何取回它。

1 个答案:

答案 0 :(得分:2)

这不是RSpec问题,而是请求/集成与功能/控制器规范问题。

Capybara,或者更具体的“请求”或“集成”规范不提供对put()或get()等请求方法的访问 - 这些只是在实时规范/控制器/的控制器规范中。当你直接测试控制器时,与cookies [] hash和other variables available相同。

See this gist进行解决方案。

相关问题