Rspec doesn't see my model Class. uninitialized constant error

后端 未结 7 1892
予麋鹿
予麋鹿 2021-01-30 19:09

I\'m writing tests on Rspec for my models in Ruby on Rails application. And I receive this error while starting \'rspec spec\'

command:
/spec/models/client_spec         


        
7条回答
  •  北恋
    北恋 (楼主)
    2021-01-30 20:03

    Things have moved a bit since this thread has been created, I have experienced the uninitialized constant ClassName (NameError) error too using Ruby 2.1, Rails 4.2, rspec-rails 3.3.

    I have solved my problems reading the rspec-rails gem documentation :

    https://github.com/rspec/rspec-rails#model-specs

    where it confirms what Swards says about requiring "rails_helper" not "spec_helper" anymore.

    Also my model specification looks more like the one from the gem docs

    RSpec.describe Url, :type => :model do
        it 'is invalid without first_name', :focus => true do
            client = Client.new
            client.should_not be_valid
        end
    end
    

提交回复
热议问题