所有
我指的是https://github.com/plataformatec/devise/wiki/How-To:-Controllers-and-Views-tests-with-Rails-3-(and-rspec),并试图设置管理员和常规设计用户使用工厂女孩为我的控制器规格。我正在使用设计中的可确认模块。
在spec / support / controller_macros.rb中,我打电话确认!从工厂获取用户对象后。 代码/评论说
> "user.confirm! # or set a confirmed_at inside the factory. Only > necessary if you are using the confirmable module"
当我在用户工厂,spec / factories / users.rb中设置“confirmed_at”的值并运行我的控制器规格(rake spec:controllers)时,它在我没有设置“confirmed_at”的值时工作但是并依靠确认!在spec / support / controller_macros.rb中,似乎确认了!找不到。
我甚至试过在“包括Devise :: TestHelpers”中加入 spec / support / controller_macros.rb文件但仍然失败。
我得到的错误是
Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `confirm!' for #<User:0x71d9c7901e48> # ./spec/support/controller_macros.rb:8:in `login_user'
我的spec / spec_helper.rb内容如下。
----------- spec / spec_helper.rb - start ---------------------------- < / p>
ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'webrat' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| config.mock_with :rspec config.include Devise::TestHelpers, :type => :controller config.extend ControllerMacros, :type => :controller # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. config.use_transactional_fixtures = true end
----------- spec / spec_helper.rb - end ---------------------------- < / p>
导致确认的可能是错误的!不被发现/工作?
谢谢:)
答案 0 :(得分:3)
确认!如果您使用的是:确认设计模块,这是必要的。
在你的user.rb(设计模型)中:在您的设计选项中确认或如果您不想使用此模块(此模块向用户发送确认电子邮件。)删除确认!来自你的controller_macros.rb。