0
嘿,大家我试图测试一个用户必须被认证的控制器,但我仍然得到NoMethodError: undefined method `authenticates_with_sorcery!'
,即使控制器本身工作和用户模型也一样。所以基本上:如果我在服务器上执行操作,如果我运行rake spec
它不起作用。在rspec中使用魔法NoMethodError:未定义方法`authenticates_with_sorcery!'
用户模型
class User < ActiveRecord::Base
authenticates_with_sorcery!
validates :password, presence: true, confirmation: true, length: { minimum: 8 }
validates :email, presence: true, uniqueness: true
validates :password_confirmation, presence: true
end
用户厂
FactoryGirl.define do
factory :user do
email "[email protected]"
password "password"
password_confirmation "password"
end
end
控制器规格
require 'rails_helper'
RSpec.describe Admin::ImagesController, :type => :controller do
before(:each) do
create(:user)
login_user_post("[email protected]", "secret")
end
describe "GET 'new'" do
it "returns http success" do
get 'new', venue_id: 1
expect(response).to be_success
end
end
end
spec_helper.rb 需要 'factory_girl_rails' 需要 '巫术'
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.include Sorcery::TestHelpers::Rails
config.include Sorcery::TestHelpers::Rails::Controller, type: :controller
config.include Sorcery::TestHelpers::Rails::Integration, type: :feature
end
如果我现在运行rake spec
我得到:
1) Admin::ImagesController GET 'new' returns http success
Failure/Error: create(:user)
NoMethodError:
undefined method `authenticates_with_sorcery!' for #<Class:0x007fc1221c1430>
# ./app/models/user.rb:2:in `<class:User>'
# ./app/models/user.rb:1:in `<top (required)>'
# ./spec/controllers/admin/images_controller_spec.rb:6:in `block (2 levels) in <top (required)>'
任何帮助,非常感谢!
是你的gemfile中的任何特定组中的魔法宝石?它可能会从测试组中丢失吗? – Marc
它没有组。 – tomr