在文件規範/支持/ factory_girl.rb我RSpec的軌道沒有不加載在規格/支持文件
fail "At least this file is being required"
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
,我有一些規範代碼
require 'pmc_article'
require 'pmc_article_parser'
require 'factory_girl'
require_relative './factories/pmc_article_factory'
RSpec.describe PMCArticle do
let(:pmc_article) do
build(:pmc_article)
end
it 'parses pmid' do
expect(pmc_article.article_id_pmid).to eq '123456'
end
end
但是當我運行bundle exec rspec
我得到
1) PMCArticle parses pmid
Failure/Error: build(:pmc_article)
NoMethodError:
undefined method `build' for #<RSpec::ExampleGroups::PMCArticle:0x007feac3cc5078>
# ./spec/pmc_article_spec.rb:8:in `block (2 levels) in <top (required)>'
# ./spec/pmc_article_spec.rb:12:in `block (2 levels) in <top (required)>'
我認爲rspec的失敗,要求spec/support/factory_girl.rb
,即使factory girl getting started guide說我應該把文件放在那裏。
我在啓動項目時運行命令行命令來初始化rspec,這是在我爲項目使用工廠女孩之前。
爲什麼RSpec不在spec/support中加載文件?
這將需要Rails加載,對吧? – 2015-07-27 01:02:48
我不明白。如果問題中提到「RSpec without Rails」,沒有使用Rails標記,但答案使用了'Rails.root',('·_·')... – 2017-12-08 16:13:02