【问题标题】:unitialized constant Rspec (Name Error) on Rspec.describeRspec.describe 上的未初始化常量 Rspec(名称错误)
【发布时间】: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


    【解决方案1】:

    你有一个错字

    RSpec.describe Document::Date, :type => :model do
      pending "add some examples to (or delete) #{__FILE__}"
    end
    

    它是RSpec,而不是Rspec。请注意大写的 S

    【讨论】:

      猜你喜欢
      • 2015-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-15
      • 2018-03-10
      • 1970-01-01
      相关资源
      最近更新 更多