看 Ruby on Rails Tutorial 遇到的问题,它说可以在spec/support/utilities.rb
中定义方法,然后在spec/requests/user_pages_spec.rb
文件中可以调用
utilities.rb 文件
include ApplicationHelper
def valid_signin(user)
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
Rspec::Matchers.define :have_error_message do |message|
match do |page|
page.should have_selector('div.alert.alert-error', text: message)
end
end
def sign_in(user)
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 method `sign_in' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_1::Nested_2:0x007f91a4710d80>
有人能帮我讲讲吗?