Ruby on rails RSpec中的未初始化常量错误
我正在尝试使用水豚和FactoryGirl以及RSpec测试我的邮件程序。我最后犯了一个错误:Ruby on rails RSpec中的未初始化常量错误,ruby-on-rails,rspec,capybara,factory-bot,Ruby On Rails,Rspec,Capybara,Factory Bot,我正在尝试使用水豚和FactoryGirl以及RSpec测试我的邮件程序。我最后犯了一个错误: /spec/mailers/password_resets_spec.rb:3:in `<top (required)>': uninitialized constant PasswordResets (NameError) from /home/alex/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/confi
/spec/mailers/password_resets_spec.rb:3:in `<top (required)>': uninitialized constant PasswordResets (NameError)
from /home/alex/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in `block in load_spec_files'
from /home/alex/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in `each'
from /home/alex/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in `load_spec_files'
from /home/alex/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:102:in `setup'
from /home/alex/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:88:in `run'
from /home/alex/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:73:in `run'
from /home/alex/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:41:in `invoke'
from /home/alex/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/exe/rspec:4:in `<top (required)>'
from /home/alex/.rvm/gems/ruby-2.2.1/bin/rspec:23:in `load'
from /home/alex/.rvm/gems/ruby-2.2.1/bin/rspec:23:in `<main>'
from /home/alex/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
from /home/alex/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
spec/spec\u helper.rb
require "spec_helper"
describe PasswordResets do
it "emails user when requesting password reset" do
user = FactoryGirl(:user)
visit login_path
click_link "Forgot your password?"
fill_in "Email", with: user.email
click_button "Reset Password"
end
end
require 'simplecov'
SimpleCov.start
require 'factory_girl_rails'
require 'capybara/rspec'
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
end
我做错了什么?要描述的第一个参数是对该示例组的描述。您可以将密码重置放在字符串中
describe 'PasswordResets' do
要描述的第一个参数是该示例组的描述。您可以将密码重置放在字符串中
describe 'PasswordResets' do
我可以看到两个问题 1)
PasswordResets
可能不是邮件程序的正确类名。通常以Mailer
结尾,类似于PasswordResetMailer
。但是如果它实际上是密码重置
,那么我们转到2)
2) 如果您使用的是Rails应用程序,则您的规范文件需要
要求使用“Rails\u helper”
,而不是spec\u helper
。这将设置具有所有正确自动加载功能的Rails,以找到正确的常量。这也会影响规范中用户模型的加载,以及其他方面。我在这里看到两个问题
1) PasswordResets
可能不是邮件程序的正确类名。通常以Mailer
结尾,类似于PasswordResetMailer
。但是如果它实际上是密码重置
,那么我们转到2)
2) 如果您使用的是Rails应用程序,则您的规范文件需要
要求使用“Rails\u helper”
,而不是spec\u helper
。这将设置具有所有正确自动加载功能的Rails,以找到正确的常量。这也会影响规范中用户模型的加载,以及其他事情。我已经花了一个小时。你能意识到吗?谢谢)它可以是一个描述,也可以是您实际测试的类名。通常对于特性规格来说,它是一个描述,但是对于其他所有东西,它是类名。我已经花了一个小时。你能意识到吗?谢谢)它可以是一个描述,也可以是您实际测试的类名。通常,对于特性规格,它是一个描述,但对于其他所有内容,它是类名。