簡體   English   中英

RSpec和FactoryGirl的Rails引擎

[英]Rails Engine with RSpec and FactoryGirl

我遵循了FactoryGirl的一些教程和文檔,以用於RSpec。 目前,嘗試使用FactoryGirl.create時出現一個錯誤:

describe "GenericRecipesController" do
  describe "GET 'index'" do
    it "displays list of generic recipes" do
        generic_recipe = FactoryGirl.create(:generic_recipe)
        visit '/recipe'
        response.should be_success
    end
  end
end

錯誤:

 GenericRecipesController GET 'index' displays list of generic recipes
 Failure/Error: generic_recipe = FactoryGirl.create(:generic_recipe)
 NameError:
   uninitialized constant GenericRecipe
 # ./spec/integration/generic_recipes_spec.rb:8:in `block (3 levels) in <top (required)>'

其余的代碼在那里

您可以嘗試以下方法:

factory :generic_recipe, class: EdibleRecipe::GenericRecipe do
    # ...
end

我認為模塊中的嵌套模型存在問題

更新 :刪除文件/spec/support/factories.rb中的文件/spec/factories.rb

factory :generic_recipe, class: EdibleRecipe::GenericRecipe do

當您運行測試時,可能會看到“無法加載表”。 使

rake db:migrate RAILS_ENV=test 

然后再試一次。

您的應用似乎沒有GenericRecipe模型。 Factory Girl正在尋找一個名為GenericReciper的模型,但找不到它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM