Hello community, here is the log from the commit of package rubygem-rspec-mocks for openSUSE:Factory checked in at 2015-12-01 10:02:20 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-rspec-mocks (Old) and /work/SRC/openSUSE:Factory/.rubygem-rspec-mocks.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "rubygem-rspec-mocks" Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-rspec-mocks/rubygem-rspec-mocks.changes 2015-07-20 11:19:52.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.rubygem-rspec-mocks.new/rubygem-rspec-mocks.changes 2015-12-01 10:02:21.000000000 +0100 @@ -1,0 +2,25 @@ +Fri Nov 13 05:39:04 UTC 2015 - coolo@suse.com + +- updated to version 3.4.0 + see installed Changelog.md + + ### 3.4.0 / 2015-11-11 + [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.3.2...v3.4.0) + + Enhancements: + + * Make `expect(...).to have_received` work without relying upon + rspec-expectations. (Myron Marston, #978) + * Add option for failing tests when expectations are set on `nil`. + (Liz Rush, #983) + + Bug Fixes: + + * Fix `have_received { ... }` so that any block passed when the message + was received is forwarded to the `have_received` block. (Myron Marston, #1006) + * Fix infinite loop in error generator when stubbing `respond_to?`. + (Alex Dowad, #1022) + * Fix issue with using `receive` on subclasses (at a class level) with 1.8.7. + (Alex Dowad, #1026) + +------------------------------------------------------------------- Old: ---- rspec-mocks-3.3.2.gem New: ---- rspec-mocks-3.4.0.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-rspec-mocks.spec ++++++ --- /var/tmp/diff_new_pack.7GLWpg/_old 2015-12-01 10:02:22.000000000 +0100 +++ /var/tmp/diff_new_pack.7GLWpg/_new 2015-12-01 10:02:22.000000000 +0100 @@ -24,7 +24,7 @@ # Name: rubygem-rspec-mocks -Version: 3.3.2 +Version: 3.4.0 Release: 0 %define mod_name rspec-mocks %define mod_full_name %{mod_name}-%{version} @@ -49,7 +49,7 @@ %install %gem_install \ - --doc-files="Changelog.md License.txt README.md" \ + --doc-files="Changelog.md LICENSE.md README.md" \ -f %gem_packages ++++++ rspec-mocks-3.3.2.gem -> rspec-mocks-3.4.0.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/.document new/.document --- old/.document 2015-07-15 19:12:26.000000000 +0200 +++ new/.document 2015-11-12 08:48:44.000000000 +0100 @@ -1,5 +1,5 @@ lib/**/*.rb - README.md -License.txt +LICENSE.md Changelog.md diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/.yardopts new/.yardopts --- old/.yardopts 2015-07-15 19:12:26.000000000 +0200 +++ new/.yardopts 2015-11-12 08:48:44.000000000 +0100 @@ -3,4 +3,4 @@ --markup markdown - Changelog.md -License.txt +LICENSE.md diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Changelog.md new/Changelog.md --- old/Changelog.md 2015-07-15 19:12:26.000000000 +0200 +++ new/Changelog.md 2015-11-12 08:48:44.000000000 +0100 @@ -1,3 +1,22 @@ +### 3.4.0 / 2015-11-11 +[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.3.2...v3.4.0) + +Enhancements: + +* Make `expect(...).to have_received` work without relying upon + rspec-expectations. (Myron Marston, #978) +* Add option for failing tests when expectations are set on `nil`. + (Liz Rush, #983) + +Bug Fixes: + +* Fix `have_received { ... }` so that any block passed when the message + was received is forwarded to the `have_received` block. (Myron Marston, #1006) +* Fix infinite loop in error generator when stubbing `respond_to?`. + (Alex Dowad, #1022) +* Fix issue with using `receive` on subclasses (at a class level) with 1.8.7. + (Alex Dowad, #1026) + ### 3.3.2 / 2015-07-15 [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.3.1...v3.3.2) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/LICENSE.md new/LICENSE.md --- old/LICENSE.md 1970-01-01 01:00:00.000000000 +0100 +++ new/LICENSE.md 2015-11-12 08:48:44.000000000 +0100 @@ -0,0 +1,25 @@ +The MIT License (MIT) +===================== + +* Copyright © 2012 David Chelimsky, Myron Marston +* Copyright © 2006 David Chelimsky, The RSpec Development Team +* Copyright © 2005 Steven Baker + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/License.txt new/License.txt --- old/License.txt 2015-07-15 19:12:26.000000000 +0200 +++ new/License.txt 1970-01-01 01:00:00.000000000 +0100 @@ -1,24 +0,0 @@ -(The MIT License) - -Copyright (c) 2012 David Chelimsky, Myron Marston -Copyright (c) 2006 David Chelimsky, The RSpec Development Team -Copyright (c) 2005 Steven Baker - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.md new/README.md --- old/README.md 2015-07-15 19:12:26.000000000 +0200 +++ new/README.md 2015-11-12 08:48:44.000000000 +0100 @@ -16,6 +16,20 @@ gem lib, :git => "git://github.com/rspec/#{lib}.git", :branch => 'master' end ``` +## Contributing + +Once you've set up the environment, you'll need to cd into the working +directory of whichever repo you want to work in. From there you can run the +specs and cucumber features, and make patches. + +NOTE: You do not need to use rspec-dev to work on a specific RSpec repo. You +can treat each RSpec repo as an independent project. + +For information about contributing to RSpec, please refer to the following markdown files: +* [Build details](BUILD_DETAIL.md) +* [Code of Conduct](CODE_OF_CONDUCT.md) +* [Detailed contributing guide](CONTRIBUTING.md) +* [Development setup guide](DEVELOPMENT.md) ## Test Doubles @@ -346,7 +360,7 @@ ## Delegating to the Original Implementation When working with a partial mock object, you may occasionally -want to set a message expecation without interfering with how +want to set a message expectation without interfering with how the object responds to the message. You can use `and_call_original` to achieve this: @@ -425,6 +439,7 @@ ## Also see -* [http://github.com/rspec/rspec](http://github.com/rspec/rspec) -* [http://github.com/rspec/rspec-core](http://github.com/rspec/rspec-core) -* [http://github.com/rspec/rspec-expectations](http://github.com/rspec/rspec-expectations) +* [https://github.com/rspec/rspec](https://github.com/rspec/rspec) +* [https://github.com/rspec/rspec-core](https://github.com/rspec/rspec-core) +* [https://github.com/rspec/rspec-expectations](https://github.com/rspec/rspec-expectations) +* [https://github.com/rspec/rspec-rails](https://github.com/rspec/rspec-rails) Files old/checksums.yaml.gz and new/checksums.yaml.gz differ Files old/checksums.yaml.gz.sig and new/checksums.yaml.gz.sig differ Files old/data.tar.gz.sig and new/data.tar.gz.sig differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/configuration.rb new/lib/rspec/mocks/configuration.rb --- old/lib/rspec/mocks/configuration.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/configuration.rb 2015-11-12 08:48:44.000000000 +0100 @@ -3,12 +3,29 @@ # Provides configuration options for rspec-mocks. class Configuration def initialize + @allow_message_expectations_on_nil = nil @yield_receiver_to_any_instance_implementation_blocks = true @verify_doubled_constant_names = false @transfer_nested_constants = false @verify_partial_doubles = false end + # Sets whether RSpec will warn, ignore, or fail a test when + # expectations are set on nil. + # By default, when this flag is not set, warning messages are issued when + # expectations are set on nil. This is to prevent false-positives and to + # catch potential bugs early on. + # When set to `true`, warning messages are suppressed. + # When set to `false`, it will raise an error. + # + # @example + # RSpec.configure do |config| + # config.mock_with :rspec do |mocks| + # mocks.allow_message_expectations_on_nil = false + # end + # end + attr_accessor :allow_message_expectations_on_nil + def yield_receiver_to_any_instance_implementation_blocks? @yield_receiver_to_any_instance_implementation_blocks end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/error_generator.rb new/lib/rspec/mocks/error_generator.rb --- old/lib/rspec/mocks/error_generator.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/error_generator.rb 2015-11-12 08:48:44.000000000 +0100 @@ -69,12 +69,7 @@ end def default_error_message(expectation, expected_args, actual_args) - [ - intro, - "received", - expectation.message.inspect, - unexpected_arguments_message(expected_args, actual_args), - ].join(" ") + "#{intro} received #{expectation.message.inspect} #{unexpected_arguments_message(expected_args, actual_args)}" end # rubocop:disable Style/ParameterLists @@ -213,6 +208,16 @@ notify MockExpectationAlreadyInvokedError.new(error_message) end + def raise_expectation_on_nil_error(method_name) + __raise expectation_on_nil_message(method_name) + end + + def expectation_on_nil_message(method_name) + "An expectation of `:#{method_name}` was set on `nil`. " \ + "To allow expectations on `nil` and suppress this message, set `config.allow_expectations_on_nil` to `true`. " \ + "To disallow expectations on `nil`, set `config.allow_expectations_on_nil` to `false`" + end + private def received_part_of_expectation_error(actual_received_count, args) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/example_methods.rb new/lib/rspec/mocks/example_methods.rb --- old/lib/rspec/mocks/example_methods.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/example_methods.rb 2015-11-12 08:48:44.000000000 +0100 @@ -197,6 +197,7 @@ # By default warning messages are issued when expectations are set on # nil. This is to prevent false-positives and to catch potential bugs # early on. + # @deprecated Use {RSpec::Mocks::Configuration#allow_message_expectations_on_nil} instead. def allow_message_expectations_on_nil RSpec::Mocks.space.proxy_for(nil).warn_about_expectations = false end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/instance_method_stasher.rb new/lib/rspec/mocks/instance_method_stasher.rb --- old/lib/rspec/mocks/instance_method_stasher.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/instance_method_stasher.rb 2015-11-12 08:48:44.000000000 +0100 @@ -31,7 +31,6 @@ def stashed_method_name "obfuscated_by_rspec_mocks__#{@method}" end - private :stashed_method_name # @private def restore diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/matchers/have_received.rb new/lib/rspec/mocks/matchers/have_received.rb --- old/lib/rspec/mocks/matchers/have_received.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/matchers/have_received.rb 2015-11-12 08:48:44.000000000 +0100 @@ -36,11 +36,11 @@ end def failure_message - generate_failure_message + capture_failure_message end def failure_message_when_negated - generate_failure_message + capture_failure_message end def description @@ -54,6 +54,14 @@ end end + def setup_expectation(subject, &block) + notify_failure_message unless matches?(subject, &block) + end + + def setup_negative_expectation(subject, &block) + notify_failure_message unless does_not_match?(subject, &block) + end + def setup_allowance(_subject, &_block) disallow("allow", " as it would have no effect") end @@ -95,13 +103,17 @@ end end - def generate_failure_message + def capture_failure_message RSpec::Support.with_failure_notifier(Proc.new { |err, _opt| return err.message }) do - mock_proxy.check_for_unexpected_arguments(@expectation) - @expectation.generate_error + notify_failure_message end end + def notify_failure_message + mock_proxy.check_for_unexpected_arguments(@expectation) + @expectation.generate_error + end + def expected_messages_received_in_order? mock_proxy.replay_received_message_on @expectation, &@block @expectation.expected_messages_received? && @expectation.ensure_expected_ordering_received! diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/message_expectation.rb new/lib/rspec/mocks/message_expectation.rb --- old/lib/rspec/mocks/message_expectation.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/message_expectation.rb 2015-11-12 08:48:44.000000000 +0100 @@ -2,7 +2,7 @@ module Mocks # A message expectation that only allows concrete return values to be set # for a message. While this same effect can be achieved using a standard - # MessageExpecation, this version is much faster and so can be used as an + # MessageExpectation, this version is much faster and so can be used as an # optimization. # # @private @@ -169,7 +169,7 @@ # Tells the object to yield one or more args to a block when the message # is received. # - # @return [MessageExpecation] self, to support further chaining. + # @return [MessageExpectation] self, to support further chaining. # @example # stream.stub(:open).and_yield(StringIO.new) def and_yield(*args, &block) @@ -191,7 +191,7 @@ # Constrain a message expectation to be received a specific number of # times. # - # @return [MessageExpecation] self, to support further chaining. + # @return [MessageExpectation] self, to support further chaining. # @example # expect(dealer).to receive(:deal_card).exactly(10).times def exactly(n, &block) @@ -204,7 +204,7 @@ # Constrain a message expectation to be received at least a specific # number of times. # - # @return [MessageExpecation] self, to support further chaining. + # @return [MessageExpectation] self, to support further chaining. # @example # expect(dealer).to receive(:deal_card).at_least(9).times def at_least(n, &block) @@ -223,7 +223,7 @@ # Constrain a message expectation to be received at most a specific # number of times. # - # @return [MessageExpecation] self, to support further chaining. + # @return [MessageExpectation] self, to support further chaining. # @example # expect(dealer).to receive(:deal_card).at_most(10).times def at_most(n, &block) @@ -235,7 +235,7 @@ # Syntactic sugar for `exactly`, `at_least` and `at_most` # - # @return [MessageExpecation] self, to support further chaining. + # @return [MessageExpectation] self, to support further chaining. # @example # expect(dealer).to receive(:deal_card).exactly(10).times # expect(dealer).to receive(:deal_card).at_least(10).times @@ -247,7 +247,7 @@ # Expect a message not to be received at all. # - # @return [MessageExpecation] self, to support further chaining. + # @return [MessageExpectation] self, to support further chaining. # @example # expect(car).to receive(:stop).never def never @@ -258,7 +258,7 @@ # Expect a message to be received exactly one time. # - # @return [MessageExpecation] self, to support further chaining. + # @return [MessageExpectation] self, to support further chaining. # @example # expect(car).to receive(:go).once def once(&block) @@ -269,7 +269,7 @@ # Expect a message to be received exactly two times. # - # @return [MessageExpecation] self, to support further chaining. + # @return [MessageExpectation] self, to support further chaining. # @example # expect(car).to receive(:go).twice def twice(&block) @@ -280,7 +280,7 @@ # Expect a message to be received exactly three times. # - # @return [MessageExpecation] self, to support further chaining. + # @return [MessageExpectation] self, to support further chaining. # @example # expect(car).to receive(:go).thrice def thrice(&block) @@ -302,7 +302,7 @@ # A message expectation will fail if the message is received with different # arguments. # - # @return [MessageExpecation] self, to support further chaining. + # @return [MessageExpectation] self, to support further chaining. # @example # allow(cart).to receive(:add) { :failure } # allow(cart).to receive(:add).with(Book.new(:isbn => 1934356379)) { :success } @@ -330,7 +330,7 @@ # Expect messages to be received in a specific order. # - # @return [MessageExpecation] self, to support further chaining. + # @return [MessageExpectation] self, to support further chaining. # @example # expect(api).to receive(:prepare).ordered # expect(api).to receive(:run).ordered @@ -345,7 +345,7 @@ end # @private - # Contains the parts of `MessageExpecation` that aren't part of + # Contains the parts of `MessageExpectation` that aren't part of # rspec-mocks' public API. The class is very big and could really use # some collaborators it delegates to for this stuff but for now this was # the simplest way to split the public from private stuff to make it diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/method_double.rb new/lib/rspec/mocks/method_double.rb --- old/lib/rspec/mocks/method_double.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/method_double.rb 2015-11-12 08:48:44.000000000 +0100 @@ -3,7 +3,7 @@ # @private class MethodDouble # @private - attr_reader :method_name, :object, :expectations, :stubs + attr_reader :method_name, :object, :expectations, :stubs, :method_stasher # @private def initialize(object, method_name, proxy) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/mutex.rb new/lib/rspec/mocks/mutex.rb --- old/lib/rspec/mocks/mutex.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/mutex.rb 1970-01-01 01:00:00.000000000 +0100 @@ -1,73 +0,0 @@ -module RSpec - module Mocks - # On 1.8.7, it's in the stdlib. - # We don't want to load the stdlib, b/c this is a test tool, and can affect - # the test environment, causing tests to pass where they should fail. - # - # So we're transcribing/modifying it from - # https://github.com/ruby/ruby/blob/v1_8_7_374/lib/thread.rb#L56 - # Some methods we don't need are deleted. Anything I don't - # understand (there's quite a bit, actually) is left in. - # - # Some formating changes are made to appease the robot overlord: - # https://travis-ci.org/rspec/rspec-core/jobs/54410874 - # @private - class Mutex - def initialize - @waiting = [] - @locked = false - @waiting.taint - taint - end - - # @private - def lock - while Thread.critical = true && @locked - @waiting.push Thread.current - Thread.stop - end - @locked = true - Thread.critical = false - self - end - - # @private - def unlock - return unless @locked - Thread.critical = true - @locked = false - wakeup_and_run_waiting_thread - self - end - - # @private - def synchronize - lock - begin - yield - ensure - unlock - end - end - - private - - def wakeup_and_run_waiting_thread - begin - t = @waiting.shift - t.wakeup if t - rescue ThreadError - retry - end - Thread.critical = false - begin - t.run if t - rescue ThreadError - :noop - end - end - - # Avoid warnings for library wide checks spec - end unless defined?(::RSpec::Mocks::Mutex) || defined?(::Mutex) - end -end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/proxy.rb new/lib/rspec/mocks/proxy.rb --- old/lib/rspec/mocks/proxy.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/proxy.rb 2015-11-12 08:48:44.000000000 +0100 @@ -89,11 +89,11 @@ @error_generator.raise_expectation_on_unstubbed_method(expected_method_name) end - @messages_received.each do |(actual_method_name, args, _)| + @messages_received.each do |(actual_method_name, args, received_block)| next unless expectation.matches?(actual_method_name, *args) expectation.safe_invoke(nil) - block.call(*args) if block + block.call(*args, &received_block) if block end end @@ -371,20 +371,36 @@ return super unless unbound_method unbound_method.bind(object) + # :nocov: + rescue TypeError + if RUBY_VERSION == '1.8.7' + # In MRI 1.8.7, a singleton method on a class cannot be rebound to its subclass + if unbound_method && unbound_method.owner.ancestors.first != unbound_method.owner + # This is a singleton method; we can't do anything with it + # But we can work around this using a different implementation + double = method_double_from_ancestor_for(message) + return object.method(double.method_stasher.stashed_method_name) + end + end + raise + # :nocov: end protected def original_unbound_method_handle_from_ancestor_for(message) - method_double = @method_doubles.fetch(message) do + double = method_double_from_ancestor_for(message) + double && double.original_method.unbind + end + + def method_double_from_ancestor_for(message) + @method_doubles.fetch(message) do # The fact that there is no method double for this message indicates # that it has not been redefined by rspec-mocks. We need to continue # looking up the ancestor chain. return superclass_proxy && - superclass_proxy.original_unbound_method_handle_from_ancestor_for(message) + superclass_proxy.method_double_from_ancestor_for(message) end - - method_double.original_method.unbind end def superclass_proxy @@ -406,33 +422,62 @@ # @private class ProxyForNil < PartialDoubleProxy def initialize(order_group) - @warn_about_expectations = true + set_expectation_behavior super(nil, order_group) end + attr_accessor :disallow_expectations attr_accessor :warn_about_expectations - alias warn_about_expectations? warn_about_expectations def add_message_expectation(method_name, opts={}, &block) - warn(method_name) if warn_about_expectations? + warn_or_raise!(method_name) super end def add_negative_message_expectation(location, method_name, &implementation) - warn(method_name) if warn_about_expectations? + warn_or_raise!(method_name) super end def add_stub(method_name, opts={}, &implementation) - warn(method_name) if warn_about_expectations? + warn_or_raise!(method_name) super end private + def set_expectation_behavior + case RSpec::Mocks.configuration.allow_message_expectations_on_nil + when false + @warn_about_expectations = false + @disallow_expectations = true + when true + @warn_about_expectations = false + @disallow_expectations = false + else + @warn_about_expectations = true + @disallow_expectations = false + end + end + + def warn_or_raise!(method_name) + # This method intentionally swallows the message when + # neither disallow_expectations nor warn_about_expectations + # are set to true. + if disallow_expectations + raise_error(method_name) + elsif warn_about_expectations + warn(method_name) + end + end + def warn(method_name) - source = CallerFilter.first_non_rspec_line - Kernel.warn("An expectation of :#{method_name} was set on nil. Called from #{source}. Use allow_message_expectations_on_nil to disable warnings.") + warning_msg = @error_generator.expectation_on_nil_message(method_name) + RSpec.warning(warning_msg) + end + + def raise_error(method_name) + @error_generator.raise_expectation_on_nil_error(method_name) end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/reentrant_mutex.rb new/lib/rspec/mocks/reentrant_mutex.rb --- old/lib/rspec/mocks/reentrant_mutex.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/reentrant_mutex.rb 1970-01-01 01:00:00.000000000 +0100 @@ -1,53 +0,0 @@ -module RSpec - module Mocks - # Allows a thread to lock out other threads from a critical section of code, - # while allowing the thread with the lock to reenter that section. - # - # Based on Monitor as of 2.2 - - # https://github.com/ruby/ruby/blob/eb7ddaa3a47bf48045d26c72eb0f263a53524ebc/l... - # - # Depends on Mutex, but Mutex is only available as part of core since 1.9.1: - # exists - http://ruby-doc.org/core-1.9.1/Mutex.html - # dne - http://ruby-doc.org/core-1.9.0/Mutex.html - # - # @private - class ReentrantMutex - def initialize - @owner = nil - @count = 0 - @mutex = Mutex.new - end - - def synchronize - enter - yield - ensure - exit - end - - private - - def enter - @mutex.lock if @owner != Thread.current - @owner = Thread.current - @count += 1 - end - - def exit - @count -= 1 - return unless @count == 0 - @owner = nil - @mutex.unlock - end - end - - if defined? ::Mutex - # On 1.9 and up, this is in core, so we just use the real one - Mutex = ::Mutex - else # For 1.8.7 - # :nocov: - RSpec::Support.require_rspec_mocks "mutex" - # :nocov: - end - end -end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/space.rb new/lib/rspec/mocks/space.rb --- old/lib/rspec/mocks/space.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/space.rb 2015-11-12 08:48:44.000000000 +0100 @@ -1,4 +1,4 @@ -RSpec::Support.require_rspec_mocks 'reentrant_mutex' +RSpec::Support.require_rspec_support 'reentrant_mutex' module RSpec module Mocks @@ -145,7 +145,7 @@ private def new_mutex - Mocks::ReentrantMutex.new + Support::ReentrantMutex.new end def proxy_not_found_for(id, object) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/syntax.rb new/lib/rspec/mocks/syntax.rb --- old/lib/rspec/mocks/syntax.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/syntax.rb 2015-11-12 08:48:44.000000000 +0100 @@ -48,7 +48,7 @@ end def unstub(message) - ::RSpec::Mocks::Syntax.warn_unless_should_configured(__method__, "`allow(...).to_receive(...).and_call_original` or explicitly enable `:should`") + ::RSpec::Mocks::Syntax.warn_unless_should_configured(__method__, "`allow(...).to receive(...).and_call_original` or explicitly enable `:should`") ::RSpec::Mocks.space.proxy_for(self).remove_stub(message) end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/targets.rb new/lib/rspec/mocks/targets.rb --- old/lib/rspec/mocks/targets.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/targets.rb 2015-11-12 08:48:44.000000000 +0100 @@ -19,7 +19,7 @@ method_name = options.fetch(:from) define_method(method_name) do |matcher, &block| case matcher - when Matchers::Receive + when Matchers::Receive, Matchers::HaveReceived define_matcher(matcher, matcher_method, &block) when Matchers::ReceiveMessages, Matchers::ReceiveMessageChain raise_negation_unsupported(method_name, matcher) @@ -47,7 +47,7 @@ def raise_unsupported_matcher(method_name, matcher) raise UnsupportedMatcherError, - "only the `receive` or `receive_messages` matchers are supported " \ + "only the `receive`, `have_received` and `receive_messages` matchers are supported " \ "with `#{expression}(...).#{method_name}`, but you have provided: #{matcher}" end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/verifying_message_expecation.rb new/lib/rspec/mocks/verifying_message_expecation.rb --- old/lib/rspec/mocks/verifying_message_expecation.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/verifying_message_expecation.rb 1970-01-01 01:00:00.000000000 +0100 @@ -1,54 +0,0 @@ -RSpec::Support.require_rspec_support 'method_signature_verifier' - -module RSpec - module Mocks - # A message expectation that knows about the real implementation of the - # message being expected, so that it can verify that any expectations - # have the valid arguments. - # @api private - class VerifyingMessageExpectation < MessageExpectation - # A level of indirection is used here rather than just passing in the - # method itself, since method look up is expensive and we only want to - # do it if actually needed. - # - # Conceptually the method reference makes more sense as a constructor - # argument since it should be immutable, but it is significantly more - # straight forward to build the object in pieces so for now it stays as - # an accessor. - attr_accessor :method_reference - - def initialize(*args) - super - end - - # @private - def with(*args, &block) - super(*args, &block).tap do - validate_expected_arguments! do |signature| - example_call_site_args = [:an_arg] * signature.min_non_kw_args - example_call_site_args << :kw_args_hash if signature.required_kw_args.any? - @argument_list_matcher.resolve_expected_args_based_on(example_call_site_args) - end - end - end - - private - - def validate_expected_arguments! - return if method_reference.nil? - - method_reference.with_signature do |signature| - args = yield signature - verifier = Support::LooseSignatureVerifier.new(signature, args) - - unless verifier.valid? - # Fail fast is required, otherwise the message expecation will fail - # as well ("expected method not called") and clobber this one. - @failed_fast = true - @error_generator.raise_invalid_arguments_error(verifier) - end - end - end - end - end -end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/verifying_message_expectation.rb new/lib/rspec/mocks/verifying_message_expectation.rb --- old/lib/rspec/mocks/verifying_message_expectation.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/rspec/mocks/verifying_message_expectation.rb 2015-11-12 08:48:44.000000000 +0100 @@ -0,0 +1,54 @@ +RSpec::Support.require_rspec_support 'method_signature_verifier' + +module RSpec + module Mocks + # A message expectation that knows about the real implementation of the + # message being expected, so that it can verify that any expectations + # have the valid arguments. + # @api private + class VerifyingMessageExpectation < MessageExpectation + # A level of indirection is used here rather than just passing in the + # method itself, since method look up is expensive and we only want to + # do it if actually needed. + # + # Conceptually the method reference makes more sense as a constructor + # argument since it should be immutable, but it is significantly more + # straight forward to build the object in pieces so for now it stays as + # an accessor. + attr_accessor :method_reference + + def initialize(*args) + super + end + + # @private + def with(*args, &block) + super(*args, &block).tap do + validate_expected_arguments! do |signature| + example_call_site_args = [:an_arg] * signature.min_non_kw_args + example_call_site_args << :kw_args_hash if signature.required_kw_args.any? + @argument_list_matcher.resolve_expected_args_based_on(example_call_site_args) + end + end + end + + private + + def validate_expected_arguments! + return if method_reference.nil? + + method_reference.with_signature do |signature| + args = yield signature + verifier = Support::LooseSignatureVerifier.new(signature, args) + + unless verifier.valid? + # Fail fast is required, otherwise the message expectation will fail + # as well ("expected method not called") and clobber this one. + @failed_fast = true + @error_generator.raise_invalid_arguments_error(verifier) + end + end + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/verifying_proxy.rb new/lib/rspec/mocks/verifying_proxy.rb --- old/lib/rspec/mocks/verifying_proxy.rb 2015-07-15 19:12:26.000000000 +0200 +++ new/lib/rspec/mocks/verifying_proxy.rb 2015-11-12 08:48:44.000000000 +0100 @@ -1,4 +1,4 @@ -RSpec::Support.require_rspec_mocks 'verifying_message_expecation' +RSpec::Support.require_rspec_mocks 'verifying_message_expectation' RSpec::Support.require_rspec_mocks 'method_reference' module RSpec diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/rspec/mocks/version.rb new/lib/rspec/mocks/version.rb --- old/lib/rspec/mocks/version.rb 2015-07-15 19:12:27.000000000 +0200 +++ new/lib/rspec/mocks/version.rb 2015-11-12 08:48:44.000000000 +0100 @@ -3,7 +3,7 @@ # Version information for RSpec mocks. module Version # Version of RSpec mocks currently in use in SemVer format. - STRING = '3.3.2' + STRING = '3.4.0' end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2015-07-15 19:12:26.000000000 +0200 +++ new/metadata 2015-11-12 08:48:44.000000000 +0100 @@ -1,7 +1,7 @@ --- !ruby/object:Gem::Specification name: rspec-mocks version: !ruby/object:Gem::Version - version: 3.3.2 + version: 3.4.0 platform: ruby authors: - Steven Baker @@ -45,7 +45,7 @@ ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ F3MdtaDehhjC -----END CERTIFICATE----- -date: 2015-07-15 00:00:00.000000000 Z +date: 2015-11-12 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rspec-support @@ -53,14 +53,14 @@ requirements: - - "~>" - !ruby/object:Gem::Version - version: 3.3.0 + version: 3.4.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version - version: 3.3.0 + version: 3.4.0 - !ruby/object:Gem::Dependency name: diff-lcs requirement: !ruby/object:Gem::Requirement @@ -115,14 +115,14 @@ requirements: - - "~>" - !ruby/object:Gem::Version - version: '0.5' + version: 0.6.2 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version - version: '0.5' + version: 0.6.2 - !ruby/object:Gem::Dependency name: minitest requirement: !ruby/object:Gem::Requirement @@ -137,20 +137,6 @@ - - "~>" - !ruby/object:Gem::Version version: '5.2' -- !ruby/object:Gem::Dependency - name: thread_order - requirement: !ruby/object:Gem::Requirement - requirements: - - - "~>" - - !ruby/object:Gem::Version - version: 1.1.0 - type: :development - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - "~>" - - !ruby/object:Gem::Version - version: 1.1.0 description: RSpec's 'test double' framework, with support for stubbing and mocking email: rspec@googlegroups.com executables: [] @@ -160,7 +146,7 @@ - ".document" - ".yardopts" - Changelog.md -- License.txt +- LICENSE.md - README.md - lib/rspec/mocks.rb - lib/rspec/mocks/any_instance.rb @@ -190,18 +176,16 @@ - lib/rspec/mocks/method_double.rb - lib/rspec/mocks/method_reference.rb - lib/rspec/mocks/mutate_const.rb -- lib/rspec/mocks/mutex.rb - lib/rspec/mocks/object_reference.rb - lib/rspec/mocks/order_group.rb - lib/rspec/mocks/proxy.rb -- lib/rspec/mocks/reentrant_mutex.rb - lib/rspec/mocks/space.rb - lib/rspec/mocks/standalone.rb - lib/rspec/mocks/syntax.rb - lib/rspec/mocks/targets.rb - lib/rspec/mocks/test_double.rb - lib/rspec/mocks/verifying_double.rb -- lib/rspec/mocks/verifying_message_expecation.rb +- lib/rspec/mocks/verifying_message_expectation.rb - lib/rspec/mocks/verifying_proxy.rb - lib/rspec/mocks/version.rb homepage: http://github.com/rspec/rspec-mocks @@ -228,6 +212,6 @@ rubygems_version: 2.2.2 signing_key: specification_version: 4 -summary: rspec-mocks-3.3.2 +summary: rspec-mocks-3.4.0 test_files: [] has_rdoc: Files old/metadata.gz.sig and new/metadata.gz.sig differ