导轨新手。尝试遵循迈克尔哈特尔的教程。
尝试添加辅助方法来模拟 RSpec 测试中的日志时遇到了困难:
describe "when the a user has logged in and attempts to visit the page" do
let(:user) { FactoryGirl.create :user }
before do
log_in user
end
it "should redirect the user to next page" do
specify { response.should redirect_to loggedin_path }
end
end
在我的 spec/support/utilities.rb 中:
def log_in user
visit root_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Log in"
cookies[:remember_token] = user.remember_token
end
错误:
Failure/Error: log_in user
NoMethodError:
undefined method `cookie_jar' for nil:NilClass
是什么赋予了?
编辑,完整的堆栈跟踪:
Index page when the a user has logged in and attempts to visit the page should redirect the user to next page
Failure/Error: log_in user
NoMethodError:
undefined method `cookie_jar' for nil:NilClass
# ./spec/support/utilities.rb:8:in `log_in'
# ./spec/features/pages/index_spec.rb:20:in `block (3 levels) in <top (required)>'