solidusでECサイトを実装しています。
そこで、Rspecでcontrollerのテストを書いているのですが、うまく通りません。
controllerはこれです。
@taxonomies = Spree::Taxonomy.all
Spree::Taxonomyモデルは商品の分類の際に使用される値が入っているモデルで、
現状は、"Categories"と"Brand"の2つが入っています。
テストコードはこれです。
RSpec.describe Potepan::CategoriesController, type: :controller do describe "#show" do let(:taxonomy){ create(:taxonomy) } it "has right value in @taxonomies" do expect(assigns(:taxonomies)).to eq taxonomy end end end
FactoryBotのTaxonomyはこれです。
FactoryBot.define do factory :taxonomy, class: 'Spree::Taxonomy' do name { 'Brand' } end end
エラー文はこれです。
Failure/Error: expect(assigns(:taxonomies)).to eq taxonomy expected: #<Spree::Taxonomy id: 491, name: "Brand", created_at: "2019-02-24 06:32:26", updated_at: "2019-02-24 06:32:26", position: 2> got: #<ActiveRecord::Relation [#<Spree::Taxonomy id: 490, name: "Brand", created_at: "2019-02-24 06:32:26"... name: "Brand", created_at: "2019-02-24 06:32:26", updated_at: "2019-02-24 06:32:26", position: 2>]> (compared using ==) Diff: @@ -1,7 +1,13 @@ -#<Spree::Taxonomy:0x0000564e2ec5bb10 - id: 491, - name: "Brand", - created_at: Sun, 24 Feb 2019 15:32:26 JST +09:00, - updated_at: Sun, 24 Feb 2019 15:32:26 JST +09:00, - position: 2> +[#<Spree::Taxonomy:0x0000564e2b441d10 + id: 490, + name: "Brand", + created_at: Sun, 24 Feb 2019 15:32:26 JST +09:00, + updated_at: Sun, 24 Feb 2019 15:32:26 JST +09:00, + position: 1>, + #<Spree::Taxonomy:0x0000564e2b441b08 + id: 491, + name: "Brand", + created_at: Sun, 24 Feb 2019 15:32:26 JST +09:00, + updated_at: Sun, 24 Feb 2019 15:32:26 JST +09:00, + position: 2>] # ./spec/controllers/potepan/categories_controller_spec.rb:11:in `block (3 levels) in <top (required)>'
よろしくお願いします。
あなたの回答
tips
プレビュー