1
@product.industry_products.build
と残りの部分が私のアクションで定義されているかどうかはどのようにしてテストできますか?rspec matcher for new action
products_controller
def new
@product = Product.new
authorize @product
@product.industry_products.build
@product.product_features.build
@product.product_usecases.build
@product.product_competitions.build
end
products_controller_spec.rb
context "GET new" do
let!(:profile) { create(:profile, user: @user) }
before(:each) do
get :new
end
it "assigns product" do
expect(assigns(:product)).to be_a_new(Product)
end
it { is_expected.to respond_with 200 }
it { is_expected.to render_template :new }
end
Anthony、私はモデル仕様でこれらのテストを行っています。その場合、インスタンス変数がコントローラに設定されているかどうかをテストする必要はないと思いますか? –
この場合、はい。テストする場合は、 'expect(assigns(:project).industry_products.size).to eq(1)'を使用するだけです。あるいは、より良いことに、 'industry_products'フィールドがあなたのフォームに現実に現れるようにしてください。 –