From f70607259a1731d7010b0eb9db55fc0606954208 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 12 May 2023 13:34:34 +1000 Subject: [PATCH] Spec Variant#product_and_full_name with real data Mocking skips a lot of code execution which we want to test as well. --- spec/models/spree/variant_spec.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index a27f72b622..c7b0c74936 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -409,23 +409,27 @@ describe Spree::Variant do end describe "generating the product and variant name" do - let(:v) { Spree::Variant.new } - let(:p) { double(:product, name: 'product') } - before { allow(v).to receive(:product) { p } } + let(:product) { variant.product } context "when full_name starts with the product name" do - before { allow(v).to receive(:full_name) { p.name + " - something" } } + before do + product.name = "Apple" + variant.display_as = "Apple Pink Lady" + end it "does not show the product name twice" do - expect(v.product_and_full_name).to eq('product - something') + expect(variant.product_and_full_name).to eq "Apple Pink Lady" end end context "when full_name does not start with the product name" do - before { allow(v).to receive(:full_name) { "display_name (unit)" } } + before do + product.name = "Apple" + variant.display_as = "Pink Lady" + end it "prepends the product name to the full name" do - expect(v.product_and_full_name).to eq('product - display_name (unit)') + expect(variant.product_and_full_name).to eq "Apple - Pink Lady" end end end