From 6a0e43629008ad1f78388822ca46fbbd5432a65e Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Sun, 23 Aug 2020 22:27:37 -0600 Subject: [PATCH] Remove warnings that fail the build --- lib/shoulda/matchers/independent.rb | 1 - .../delegate_method_matcher/stubbed_target.rb | 37 ---------------- .../matchers/doublespeak/double_spec.rb | 1 + .../stubbed_target_spec.rb | 43 ------------------- .../delegate_method_matcher_spec.rb | 6 ++- 5 files changed, 5 insertions(+), 83 deletions(-) delete mode 100644 lib/shoulda/matchers/independent/delegate_method_matcher/stubbed_target.rb delete mode 100644 spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb diff --git a/lib/shoulda/matchers/independent.rb b/lib/shoulda/matchers/independent.rb index 3996e0232..5ff4dca24 100644 --- a/lib/shoulda/matchers/independent.rb +++ b/lib/shoulda/matchers/independent.rb @@ -1,5 +1,4 @@ require 'shoulda/matchers/independent/delegate_method_matcher' -require 'shoulda/matchers/independent/delegate_method_matcher/stubbed_target' require 'shoulda/matchers/independent/delegate_method_matcher/target_not_defined_error' module Shoulda diff --git a/lib/shoulda/matchers/independent/delegate_method_matcher/stubbed_target.rb b/lib/shoulda/matchers/independent/delegate_method_matcher/stubbed_target.rb deleted file mode 100644 index c2c6f449b..000000000 --- a/lib/shoulda/matchers/independent/delegate_method_matcher/stubbed_target.rb +++ /dev/null @@ -1,37 +0,0 @@ -module Shoulda - module Matchers - module Independent - class DelegateMethodMatcher - # @private - class StubbedTarget - def initialize(method) - @received_method = false - @received_arguments = [] - stub_method(method) - end - - def has_received_method? - received_method - end - - def has_received_arguments?(*args) - args == received_arguments - end - - protected - - def stub_method(method) - class_eval do - define_method method do |*args| - @received_method = true - @received_arguments = args - end - end - end - - attr_reader :received_method, :received_arguments - end - end - end - end -end diff --git a/spec/unit/shoulda/matchers/doublespeak/double_spec.rb b/spec/unit/shoulda/matchers/doublespeak/double_spec.rb index 737e20da7..815829c6b 100644 --- a/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +++ b/spec/unit/shoulda/matchers/doublespeak/double_spec.rb @@ -233,6 +233,7 @@ module Shoulda::Matchers::Doublespeak doubles[0].activate was_called = false + klass.__send__(:remove_method, method_name) klass.__send__(:define_method, method_name) do was_called = true end diff --git a/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb b/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb deleted file mode 100644 index f44dcbf52..000000000 --- a/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'unit_spec_helper' - -describe Shoulda::Matchers::Independent::DelegateMethodMatcher::StubbedTarget do - subject(:target) { described_class.new(:stubbed_method) } - - describe '#has_received_method?' do - it 'returns true when the method has been called on the target' do - target.stubbed_method - - expect(target).to have_received_method - end - - it 'returns false when the method has not been called on the target' do - expect(target).not_to have_received_method - end - end - - describe '#has_received_arguments?' do - context 'method is called with specified arguments' do - it 'returns true' do - target.stubbed_method(:arg1, :arg2) - - expect(target).to have_received_arguments(:arg1, :arg2) - end - end - - context 'method is not called with specified arguments' do - it 'returns false' do - target.stubbed_method - - expect(target).not_to have_received_arguments(:arg1) - end - end - - context 'method is called with arguments in incorrect order' do - it 'returns false' do - target.stubbed_method(:arg2, :arg1) - - expect(target).not_to have_received_arguments(:arg1, :arg2) - end - end - end -end diff --git a/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb b/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb index 80e952ece..d0106b4c6 100644 --- a/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb @@ -418,7 +418,7 @@ def country person = Person.new expect { - expect(person).to delegate_method(:hello). to(:country).with_prefix + expect(person).to delegate_method(:hello).to(:country).with_prefix }.to fail_with_message(message) end end @@ -592,7 +592,9 @@ def country; end MESSAGE expectation = lambda do - expect(person).to delegate_method(:hello).to(:country).allow_nil + silence_warnings do + expect(person).to delegate_method(:hello).to(:country).allow_nil + end end expect(&expectation).to fail_with_message(message)