我正在尝试在我的ruby应用上测试登录,但我不断收到错误:未定义的方法`永久'用于规范:
require 'rails_helper'
RSpec.describe "Logging in", :type => :request do
it "Signs in valid user" do
val_user = FactoryGirl.create(:user)
get signin_path
expect(response).to be_success
sign_in(val_user)
expect(response).to be_success
expect(response).to render_template(root_path)
expect(flash[:success]).to be_present
end
end
规格/支持/ utilities.rb
module Utilities
def sign_in(user)
cookies[:remember_token] = user.remember_token
request.session[:user] = user.id
end
end
我之前在spec / support的spec_test_helper.rb文件中有我的sign_in方法,但是堆栈溢出的另一个帖子告诉我将它移动到实用程序并从行中删除.permanent:
cookies.permanent[:remember_token] = user.remember_token
这是回溯:
# ./app/helpers/sessions_helper.rb:4:in `sign_in'
# ./spec/requests/log_in_spec.rb:10:in `(root)'
# org/jruby/RubyBasicObject.java:1562:in `instance_exec'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:177:in `run'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:385:in `with_around_and_singleton_context_hooks'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:343:in `with_around_example_hooks'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:474:in `run'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:612:in `run_around_example_hooks_for'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:474:in `run'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:343:in `with_around_example_hooks'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:385:in `with_around_and_singleton_context_hooks'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:174:in `run'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:549:in `run_examples'
# org/jruby/RubyArray.java:2412:in `map'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:545:in `run_examples'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:512:in `run'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:110:in `run_specs'
# org/jruby/RubyArray.java:2412:in `map'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:110:in `run_specs'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1526:in `with_suite_hooks'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:109:in `run_specs'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/reporter.rb:62:in `report'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:108:in `run_specs'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:86:in `run'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:70:in `run'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:38:in `invoke'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/gems/rspec-core-3.2.3/exe/rspec:4:in `(root)'
# org/jruby/RubyKernel.java:1087:in `load'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/bin/rspec:1:in `(root)'
# org/jruby/RubyKernel.java:1107:in `eval'
# /Users/ssuhli200/.rvm/gems/jruby-1.7.18@cimport/bin/jruby_executable_hooks:15:in `(root)'
请帮忙!