当我运行rspec spec / models / user_spec.rb进行测试时,我收到了这个错误:
/home/alex/dev/greenbull/spec/models/user_spec.rb:3:in `<top (required)>':
uninitialized constant User (NameError)
这是/ spec文件夹结构
|-models
| |_
| |-task.rb
| |-user.rb
| |-task_spec.rb
| |-user_spec.rb
|
|-factories
| |_
| |-tasks.rb
| |-users.rb
|
|-spec_helper.rb
spec_helper.rb
require 'rubygems'
require 'factory_girl'
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
规格/模型/ user.rb
class User
end
为什么会这样?我做错了吗?
答案 0 :(得分:1)
spec文件不应该是这样的,它会是这样的
require 'spec_helper'
describe User do
describe 'my spec' do
it 'works' do
expect(true).to eq true
end
end
end
答案 1 :(得分:0)
app根文件夹中有一个名为.rspec的隐藏文件,我在这里指定了--require rails_helper