【发布时间】:2015-02-04 03:58:56
【问题描述】:
当我运行测试时,我得到了这个错误:
top (required) : uninitialized constant Rspec (NameError)
这是失败的模型测试,除非我删除“Rspec”。
ROOT_APP/spec/models/document/date_spec.rb:
require 'rails_helper'
Rspec.describe Document::Date, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end
我知道最好使用 Rspec.describe 而不是 describe。 (关于猴子补丁,不太确定这是什么)。
当然,我可以单独使用 describe,这就是我现在所做的,只是为了让我的测试正常工作。我只是想了解更多可能发生的事情。
全部在ROOT_APP/spec目录下:
rails_helper.rb
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'spec_helper'
require 'factory_girl'
require 'capybara/rspec'
require 'capybara/rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
RSpec.configure do |config|
config.infer_spec_type_from_file_location!
config.include(MailerMacros)
config.before(:each) { reset_email }
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
config.include FactoryGirl::Syntax::Methods
end
spec_helper.rb
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
我尝试将 spec_helper 代码放入 rails_helper.rb 文件,所以只有一个文件,我得到了同样的错误。
感谢您的任何回答/建议。
【问题讨论】:
标签: ruby-on-rails rspec