简体   繁体   中英

unitialized constant Rspec (Name Error) on Rspec.describe

When I run my tests, I get this error:

top (required) : uninitialized constant Rspec (NameError)

This is the model test that fails, unless I remove '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

I understand that it is better to use Rspec.describe instead of describe. (something about monkey patching, not really sure what this is).

Of course I could just use describe by itself, which is what I'm doing now just to make my tests work. I just want to know more about what may be happening.

All under the ROOT_APP/spec directory:

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

I tried putting the spec_helper code into the rails_helper.rb file so there's only one file and I get the same error.

Thank you for any answers/advice.

You have a typo :

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

It is RSpec , not Rspec . Note the upper case S .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM