From d439a5074b0e87ebd6a7b568906454f18963a838 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 2 Mar 2021 11:51:42 +0100 Subject: [PATCH] Remove unnecessary delegation specs The custom RSpec matchers they use raises the following deprecation warning ``` Using `stub` from rspec-mocks' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` instead. Called from /home/runner/work/openfoodnetwork/openfoodnetwork/spec/support/matchers/delegate_matchers.rb:22:in `block (2 levels) in '. ``` It's not worth maintaining those matchers to test such implementation-related thing. Whether or not any delegations work is something that will be caught by integration tests or directly stubbing the collaborator object's methods. This stems from https://github.com/openfoodfoundation/openfoodnetwork/pull/6902. --- spec/models/enterprise_spec.rb | 9 ----- spec/models/spree/addresses_spec.rb | 4 --- spec/support/matchers/delegate_matchers.rb | 41 ---------------------- 3 files changed, 54 deletions(-) delete mode 100644 spec/support/matchers/delegate_matchers.rb diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 48643c23e9..930358a350 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -189,15 +189,6 @@ describe Enterprise do end end - describe "delegations" do - # subject { FactoryBot.create(:distributor_enterprise, :address => FactoryBot.create(:address)) } - - it { is_expected.to delegate(:latitude).to(:address) } - it { is_expected.to delegate(:longitude).to(:address) } - it { is_expected.to delegate(:city).to(:address) } - it { is_expected.to delegate(:state_name).to(:address) } - end - describe "callbacks" do it "restores permalink to original value when it is changed and invalid" do e1 = create(:enterprise, permalink: "taken") diff --git a/spec/models/spree/addresses_spec.rb b/spec/models/spree/addresses_spec.rb index 00c44e3d31..52f51cc91f 100644 --- a/spec/models/spree/addresses_spec.rb +++ b/spec/models/spree/addresses_spec.rb @@ -10,10 +10,6 @@ describe Spree::Address do it { is_expected.to have_one(:enterprise) } end - describe "delegation" do - it { is_expected.to delegate(:name).to(:state).with_prefix } - end - describe "destroy" do it "can be deleted" do expect { address.destroy }.to_not raise_error diff --git a/spec/support/matchers/delegate_matchers.rb b/spec/support/matchers/delegate_matchers.rb deleted file mode 100644 index e9d0ae53e6..0000000000 --- a/spec/support/matchers/delegate_matchers.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -# RSpec matcher to spec delegations. -# -# Usage: -# -# describe Post do -# it { should delegate(:name).to(:author).with_prefix } # post.author_name -# it { should delegate(:month).to(:created_at) } -# it { should delegate(:year).to(:created_at) } -# end - -RSpec::Matchers.define :delegate do |method| - match do |delegator| - @method = @prefix ? :"#{@to}_#{method}" : method - @delegator = delegator - begin - @delegator.send(@to) - rescue NoMethodError - raise "#{@delegator} does not respond to #{@to}!" - end - @delegator.stub(@to).and_return double('receiver') - @delegator.send(@to).stub(method).and_return :called - @delegator.send(@method) == :called - end - - description do - "delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}" - end - - failure_message do |_text| - "expected #{@delegator} to delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}" - end - - failure_message_when_negated do |_text| - "expected #{@delegator} not to delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}" - end - - chain(:to) { |receiver| @to = receiver } - chain(:with_prefix) { @prefix = true } -end