Ruby初心者です。
現在Rspecでテストを書いております。
FactoryBotを使用し、showページのテストを実行した際に
以下のようなエラーが出てしまいテストを通すことができません。
Failure/Error: product = FactoryBot.create(:product) NameError: uninitialized constant Product # ./spec/controllers/products_controller_spec.rb:6:in `block (3 levels) in <main>' # -e:1:in `<main>' # ------------------ # --- Caused by: --- # NameError: # uninitialized constant Product # ./spec/controllers/products_controller_spec.rb:6:in `block (3 levels) in <main>'
products_controller_spec.rb
require 'rails_helper' RSpec.describe ProductsController, type: :controller do describe "#show" do before do product = FactoryBot.create(:product) end it "rsponds successfully" do get :show, params: {id: product.id} expect(rsponse).to be_success end end end
factories/product.rb
FactoryBot.define do factory :product do meta_description nil meta_keywords nil meta_title nil name {|n| "Products#{n}"} promotionable true slug {|n| "products#{n}"} end end
ご教授頂けると、幸いです。
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。