Hello community, here is the log from the commit of package rubygem-mocha for openSUSE:Factory checked in at 2016-10-18 10:40:17 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-mocha (Old) and /work/SRC/openSUSE:Factory/.rubygem-mocha.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-mocha" Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-mocha/rubygem-mocha.changes 2014-11-04 17:30:33.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.rubygem-mocha.new/rubygem-mocha.changes 2016-10-18 10:40:18.000000000 +0200 @@ -1,0 +2,6 @@ +Tue Oct 11 04:33:35 UTC 2016 - [email protected] + +- updated to version 1.2.0 + no changelog found + +------------------------------------------------------------------- Old: ---- mocha-1.1.0.gem New: ---- gem2rpm.yml mocha-1.2.0.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-mocha.spec ++++++ --- /var/tmp/diff_new_pack.FJG812/_old 2016-10-18 10:40:19.000000000 +0200 +++ /var/tmp/diff_new_pack.FJG812/_new 2016-10-18 10:40:19.000000000 +0200 @@ -1,7 +1,7 @@ # # spec file for package rubygem-mocha # -# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -15,19 +15,28 @@ # Please submit bugfixes or comments via http://bugs.opensuse.org/ # + +# +# This file was generated with a gem2rpm.yml and not just plain gem2rpm. +# All sections marked as MANUAL, license headers, summaries and descriptions +# can be maintained in that file. Please consult this file before editing any +# of those fields +# + Name: rubygem-mocha -Version: 1.1.0 +Version: 1.2.0 Release: 0 %define mod_name mocha %define mod_full_name %{mod_name}-%{version} BuildRoot: %{_tmppath}/%{name}-%{version}-build -BuildRequires: ruby-macros >= 5 -BuildRequires: %{ruby} BuildRequires: %{rubygem gem2rpm} +BuildRequires: %{ruby} +BuildRequires: ruby-macros >= 5 Url: http://gofreerange.com/mocha/docs Source: http://rubygems.org/gems/%{mod_full_name}.gem +Source1: gem2rpm.yml Summary: Mocking and stubbing library -License: Ruby or MIT +License: MIT and BSD-2-Clause Group: Development/Languages/Ruby %description ++++++ gem2rpm.yml ++++++ # --- # ## used by gem2rpm # :summary: this is a custom summary # ## used by gem2rpm # :description: |- # this is a custom description # # it can be multiline # ## used by gem2rpm # :license: MIT or Ruby # ## used by gem2rpm and gem_packages # :version_suffix: -x_y # ## used by gem2rpm and gem_packages # :disable_docs: true # ## used by gem2rpm # :disable_automatic_rdoc_dep: true # ## used by gem2rpm # :preamble: |- # BuildRequires: foobar # Requires: foobar # ## used by gem2rpm # :patches: # foo.patch: -p1 # bar.patch: # ## used by gem2rpm :sources: # - foo.desktop # - bar.desktop # :gem_install_args: '....' # ## used by gem2rpm # :pre_install: |- # %if 0%{?use_system_libev} # export USE_VENDORED_LIBEV="no" # %endif # ## used by gem2rpm # :post_install: |- # # delete custom files here or do other fancy stuff # install -D -m 0644 %{S:1} %{buildroot}%{_bindir}/gem2rpm-opensuse # ## used by gem2rpm # :testsuite_command: |- # (pushd %{buildroot}%{gem_base}/gems/%{mod_full_name} && rake test) # ## used by gem2rpm # :filelist: |- # /usr/bin/gem2rpm-opensuse # ## used by gem2rpm # :scripts: # :post: |- # /bin/echo foo # ## used by gem_packages # :main: # :preamble: |- # Requires: util-linux # Recommends: pwgen # :filelist: |- # /usr/bin/gem2rpm-opensuse # ## used by gem_packages # :custom: # apache: # :preamble: |- # Requires: ..... # :filelist: |- # /etc/apache2/conf.d/passenger.conf # :summary: Custom summary is optional # :description: |- # Custom description is optional # # bar # :post: |- # /bin/echo foo # ++++++ mocha-1.1.0.gem -> mocha-1.2.0.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.md new/README.md --- old/README.md 1970-01-01 01:00:00.000000000 +0100 +++ new/README.md 2016-10-10 16:40:22.000000000 +0200 @@ -1,4 +1,5 @@ -## Mocha [](https://secure.travis-ci.org/freerange/mocha) [](http://badge.fury.io/rb/mocha) +## Mocha [](https://secure.travis-ci.org/freerange/mocha) [](http://badge.fury.io/rb/mocha) [](#backers) [](#sponsors) + ### Description @@ -75,6 +76,22 @@ require 'mocha/mini_test' ``` +##### RSpec + +Assuming you are using the `rspec-rails` gem: + +```ruby +# Gemfile in Rails app +gem 'mocha' + +# Within `spec/spec_helper.rb` +RSpec.configure do |config| + config.mock_with :mocha +end +``` + +Note: There is no need to use a require statement to setup Mocha; RSpec does this itself. + #### Rails Plugin Install the Rails plugin... @@ -90,8 +107,9 @@ require 'mocha/mini_test' ``` -#### Know Issues +#### Known Issues +* Stubbing an aliased class method, where the original method is defined in a module that's used to `extend` the class doesn't work in Ruby 1.8.x. See stub_method_defined_on_module_and_aliased_test.rb for an example of this behaviour. * 0.13.x versions cause a harmless, but annoying, deprecation warning when used with Rails 3.2.0-3.2.12, 3.1.0-3.1.10 & 3.0.0-3.0.19. * 0.11.x versions don't work with Rails 3.2.13 (`TypeError: superclass mismatch for class ExpectationError`). See #115. * Versions 0.10.2, 0.10.3 & 0.11.0 of the Mocha gem were broken. Please do not use these versions. @@ -193,7 +211,7 @@ def find_all # Database.connection.execute('select * from orders... end - + def number_shipped_since(date) find_all.select { |order| order.shipped_on > date }.length end @@ -262,6 +280,75 @@ See this [list of contributors](https://github.com/freerange/mocha/graphs/contributors). +###Backers + +Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/mocha#backer)] + +<a href="https://opencollective.com/mocha/backer/0/website" target="_blank"><img src="https://opencollective.com/mocha/backer/0/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/1/website" target="_blank"><img src="https://opencollective.com/mocha/backer/1/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/2/website" target="_blank"><img src="https://opencollective.com/mocha/backer/2/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/3/website" target="_blank"><img src="https://opencollective.com/mocha/backer/3/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/4/website" target="_blank"><img src="https://opencollective.com/mocha/backer/4/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/5/website" target="_blank"><img src="https://opencollective.com/mocha/backer/5/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/6/website" target="_blank"><img src="https://opencollective.com/mocha/backer/6/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/7/website" target="_blank"><img src="https://opencollective.com/mocha/backer/7/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/8/website" target="_blank"><img src="https://opencollective.com/mocha/backer/8/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/9/website" target="_blank"><img src="https://opencollective.com/mocha/backer/9/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/10/website" target="_blank"><img src="https://opencollective.com/mocha/backer/10/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/11/website" target="_blank"><img src="https://opencollective.com/mocha/backer/11/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/12/website" target="_blank"><img src="https://opencollective.com/mocha/backer/12/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/13/website" target="_blank"><img src="https://opencollective.com/mocha/backer/13/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/14/website" target="_blank"><img src="https://opencollective.com/mocha/backer/14/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/15/website" target="_blank"><img src="https://opencollective.com/mocha/backer/15/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/16/website" target="_blank"><img src="https://opencollective.com/mocha/backer/16/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/17/website" target="_blank"><img src="https://opencollective.com/mocha/backer/17/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/18/website" target="_blank"><img src="https://opencollective.com/mocha/backer/18/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/19/website" target="_blank"><img src="https://opencollective.com/mocha/backer/19/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/20/website" target="_blank"><img src="https://opencollective.com/mocha/backer/20/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/21/website" target="_blank"><img src="https://opencollective.com/mocha/backer/21/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/22/website" target="_blank"><img src="https://opencollective.com/mocha/backer/22/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/23/website" target="_blank"><img src="https://opencollective.com/mocha/backer/23/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/24/website" target="_blank"><img src="https://opencollective.com/mocha/backer/24/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/25/website" target="_blank"><img src="https://opencollective.com/mocha/backer/25/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/26/website" target="_blank"><img src="https://opencollective.com/mocha/backer/26/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/27/website" target="_blank"><img src="https://opencollective.com/mocha/backer/27/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/28/website" target="_blank"><img src="https://opencollective.com/mocha/backer/28/avatar.svg"></a> +<a href="https://opencollective.com/mocha/backer/29/website" target="_blank"><img src="https://opencollective.com/mocha/backer/29/avatar.svg"></a> + +### Sponsors +Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/mocha#sponsor)] + +<a href="https://opencollective.com/mocha/sponsor/0/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/0/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/1/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/1/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/2/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/2/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/3/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/3/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/4/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/4/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/5/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/5/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/6/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/6/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/7/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/7/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/8/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/8/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/9/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/9/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/10/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/10/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/11/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/11/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/12/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/12/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/13/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/13/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/14/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/14/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/15/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/15/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/16/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/16/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/17/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/17/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/18/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/18/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/19/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/19/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/20/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/20/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/21/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/21/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/22/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/22/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/23/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/23/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/24/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/24/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/25/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/25/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/26/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/26/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/27/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/27/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/28/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/28/avatar.svg"></a> +<a href="https://opencollective.com/mocha/sponsor/29/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/29/avatar.svg"></a> + ### Translations * [Serbo-Croatian](http://science.webhostinggeeks.com/mocha) by [WHG Team](http://webhostinggeeks.com/). (may be out-of-date) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/RELEASE.md new/RELEASE.md --- old/RELEASE.md 1970-01-01 01:00:00.000000000 +0100 +++ new/RELEASE.md 2016-10-10 16:40:22.000000000 +0200 @@ -1,5 +1,22 @@ # Release Notes +## 1.2.0 + +* Always use prepended module to stub class & instance methods for Ruby v2+ - thanks to @grosser & @chrisroos (43d56671, #244) +* Always use prepended module to stub AnyInstance methods in Ruby v2+ - thanks to @chrisroos (#262) +* Always set visibility of stub method to match stubbed method on included module - thanks to @grosser & @chrisroos (e87c03b0, #248) +* Always set visibility to stub method to match stubbed method on superclass - thanks to @chrisroos (38d902ad) +* Allow stubbing of method to which any instance responds (#200) +* Allow `includes` matcher to take matcher arguments - thanks to @lazyatom (#217) +* Avoid exception in older version of Rubygems - thanks to @chrisroos (78d930a7) +* Add licenses to gemspec as requested by @coreyhaines (#201) +* Fix typo in README - thanks to @jaredbeck (6119460d) +* Added section about using Mocha with RSpec & Rails to README (#221) +* Fix documentation for Mocha::API#stub method - thanks to @raeno (599b1dcd) +* Added backers and sponsors from OpenCollective - thanks to @piamancini (#253) +* Fix typo in docs for equals - thanks to @alexcoco (#254) +* Add known issue for Ruby v1.8 to README - thanks to @chrisroos (2c642096) + ## 1.1.0 * Set visibility of any instance stub method. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Rakefile new/Rakefile --- old/Rakefile 1970-01-01 01:00:00.000000000 +0100 +++ new/Rakefile 2016-10-10 16:40:22.000000000 +0200 @@ -2,6 +2,8 @@ Bundler::GemHelper.install_tasks require "bundler/setup" +MOCHA_DOCS_HOST = ENV['MOCHA_DOCS_HOST'] || 'gofreerange.com' + require 'rake/testtask' desc "Run all tests" @@ -87,10 +89,18 @@ def benchmark_test_case(klass, iterations) require 'benchmark' + require 'mocha/detection/mini_test' if defined?(MiniTest) - MiniTest::Unit.output = StringIO.new - Benchmark.realtime { iterations.times { |i| MiniTest::Unit.new.run([klass]) } } + minitest_version = Gem::Version.new(Mocha::Detection::MiniTest.version) + if Gem::Requirement.new('>= 5.0.0').satisfied_by?(minitest_version) + result = Benchmark.realtime { iterations.times { |i| klass.run(MiniTest::CompositeReporter.new) } } + MiniTest::Runnable.runnables.delete(klass) + result + else + MiniTest::Unit.output = StringIO.new + Benchmark.realtime { iterations.times { |i| MiniTest::Unit.new.run([klass]) } } + end else load 'test/unit/ui/console/testrunner.rb' unless defined?(Test::Unit::UI::Console::TestRunner) unless $silent_option @@ -105,7 +115,7 @@ end end -unless ENV["MOCHA_NO_DOCS"] +if ENV["MOCHA_GENERATE_DOCS"] require 'yard' desc 'Remove generated documentation' @@ -127,10 +137,10 @@ desc "Generate documentation" task 'generate_docs' => ['clobber_yardoc', 'yardoc'] - desc "Publish docs to gofreerange.com/docs/mocha" + desc "Publish docs to #{MOCHA_DOCS_HOST}/docs/mocha" task 'publish_docs' => 'generate_docs' do path = "/home/freerange/docs/mocha" - system %{ssh gofreerange.com "sudo rm -fr #{path} && mkdir -p #{path}" && scp -r doc/* gofreerange.com:#{path}} + system %{ssh #{MOCHA_DOCS_HOST} "sudo rm -fr #{path} && mkdir -p #{path}" && scp -r doc/* #{MOCHA_DOCS_HOST}:#{path}} end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bin/build-matrix new/bin/build-matrix --- old/bin/build-matrix 1970-01-01 01:00:00.000000000 +0100 +++ new/bin/build-matrix 2016-10-10 16:40:22.000000000 +0200 @@ -33,7 +33,6 @@ ENV["RBENV_VERSION"] = ruby_version ENV["BUNDLE_GEMFILE"] = gemfile ENV["MOCHA_OPTIONS"] = "debug" - ENV["MOCHA_NO_DOCS"] = "true" reset_bundle execute( with_rbenv("bundle install --gemfile=#{gemfile}"), Files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gemfiles/Gemfile.test-unit.latest new/gemfiles/Gemfile.test-unit.latest --- old/gemfiles/Gemfile.test-unit.latest 1970-01-01 01:00:00.000000000 +0100 +++ new/gemfiles/Gemfile.test-unit.latest 2016-10-10 16:40:22.000000000 +0200 @@ -3,5 +3,9 @@ gemspec :path=>"../" group :development do - gem "test-unit" + if RUBY_VERSION < '1.9' + gem "test-unit", "~> 2" + else + gem "test-unit" + end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/mocha/any_instance_method.rb new/lib/mocha/any_instance_method.rb --- old/lib/mocha/any_instance_method.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/mocha/any_instance_method.rb 2016-10-10 16:40:22.000000000 +0200 @@ -1,3 +1,4 @@ +require 'mocha/ruby_version' require 'mocha/class_method' module Mocha @@ -13,20 +14,17 @@ end def hide_original_method - if method_exists?(method) + if @original_visibility = method_visibility(method) begin @original_method = stubbee.instance_method(method) - if @original_method && @original_method.owner == stubbee - @original_visibility = :public - if stubbee.protected_instance_methods.include?(method) - @original_visibility = :protected - elsif stubbee.private_instance_methods.include?(method) - @original_visibility = :private + if RUBY_V2_PLUS + @definition_target = PrependedModule.new + stubbee.__send__ :prepend, @definition_target + else + if @original_method && @original_method.owner == stubbee + stubbee.send(:remove_method, method) end - stubbee.send(:remove_method, method) end - - include_prepended_module if RUBY_VERSION >= '2.0' rescue NameError # deal with nasties like ActiveRecord::Associations::AssociationProxy end @@ -49,32 +47,22 @@ end def restore_original_method - if @original_method && @original_method.owner == stubbee - stubbee.send(:define_method, method, @original_method) - Module.instance_method(@original_visibility).bind(stubbee).call(method) + unless RUBY_V2_PLUS + if @original_method && @original_method.owner == stubbee + stubbee.send(:define_method, method, @original_method) + Module.instance_method(@original_visibility).bind(stubbee).call(method) + end end end - def method_exists?(method) - return true if stubbee.public_instance_methods(false).include?(method) - return true if stubbee.protected_instance_methods(false).include?(method) - return true if stubbee.private_instance_methods(false).include?(method) - return false + def method_visibility(method) + (stubbee.public_instance_methods(true).include?(method) && :public) || + (stubbee.protected_instance_methods(true).include?(method) && :protected) || + (stubbee.private_instance_methods(true).include?(method) && :private) end private - def include_prepended_module - possible_prepended_modules = stubbee.ancestors.take_while do |mod| - !(Class === mod) - end - - if possible_prepended_modules.any? - @definition_target = PrependedModule.new - stubbee.__send__ :prepend, @definition_target - end - end - def definition_target @definition_target ||= stubbee end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/mocha/api.rb new/lib/mocha/api.rb --- old/lib/mocha/api.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/mocha/api.rb 2016-10-10 16:40:22.000000000 +0200 @@ -70,7 +70,7 @@ # # @example Using stubbed_methods_vs_return_values Hash to setup stubbed methods. # def test_motor_starts_and_stops - # motor = mock('motor', :start => true, :stop => true) + # motor = stub('motor', :start => true, :stop => true) # assert motor.start # assert motor.stop # # an error will not be raised even if either Motor#start or Motor#stop has not been called @@ -78,7 +78,7 @@ # # @example Using the optional block to setup expectations & stubbed methods. # def test_motor_starts_and_stops - # motor = mock('motor') do + # motor = stub('motor') do # expects(:start).with(100.rpm).returns(true) # stubs(:stop).returns(true) # end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/mocha/class_method.rb new/lib/mocha/class_method.rb --- old/lib/mocha/class_method.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/mocha/class_method.rb 2016-10-10 16:40:22.000000000 +0200 @@ -1,3 +1,4 @@ +require 'mocha/ruby_version' require 'metaclass' module Mocha @@ -11,7 +12,7 @@ def initialize(stubbee, method) @stubbee = stubbee @original_method, @original_visibility = nil, nil - @method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym + @method = PRE_RUBY_V19 ? method.to_s : method.to_sym end def stub @@ -37,20 +38,17 @@ end def hide_original_method - if method_exists?(method) + if @original_visibility = method_visibility(method) begin @original_method = stubbee._method(method) - @original_visibility = :public - if stubbee.__metaclass__.protected_instance_methods.include?(method) - @original_visibility = :protected - elsif stubbee.__metaclass__.private_instance_methods.include?(method) - @original_visibility = :private + if RUBY_V2_PLUS + @definition_target = PrependedModule.new + stubbee.__metaclass__.__send__ :prepend, @definition_target + else + if @original_method && @original_method.owner == stubbee.__metaclass__ + stubbee.__metaclass__.send(:remove_method, method) + end end - if @original_method && @original_method.owner == stubbee.__metaclass__ - stubbee.__metaclass__.send(:remove_method, method) - end - - include_prepended_module if RUBY_VERSION >= '2.0' rescue NameError # deal with nasties like ActiveRecord::Associations::AssociationProxy end @@ -73,18 +71,20 @@ end def restore_original_method - if @original_method && @original_method.owner == stubbee.__metaclass__ - if RUBY_VERSION < '1.9' - original_method = @original_method - stubbee.__metaclass__.send(:define_method, method) do |*args, &block| - original_method.call(*args, &block) + unless RUBY_V2_PLUS + if @original_method && @original_method.owner == stubbee.__metaclass__ + if PRE_RUBY_V19 + original_method = @original_method + stubbee.__metaclass__.send(:define_method, method) do |*args, &block| + original_method.call(*args, &block) + end + else + stubbee.__metaclass__.send(:define_method, method, @original_method) end - else - stubbee.__metaclass__.send(:define_method, method, @original_method) end - end - if @original_visibility - Module.instance_method(@original_visibility).bind(stubbee.__metaclass__).call(method) + if @original_visibility + Module.instance_method(@original_visibility).bind(stubbee.__metaclass__).call(method) + end end end @@ -99,25 +99,17 @@ "#{stubbee}.#{method}" end - def method_exists?(method) + def method_visibility(method) symbol = method.to_sym - __metaclass__ = stubbee.__metaclass__ - __metaclass__.public_method_defined?(symbol) || __metaclass__.protected_method_defined?(symbol) || __metaclass__.private_method_defined?(symbol) + metaclass = stubbee.__metaclass__ + + (metaclass.public_method_defined?(symbol) && :public) || + (metaclass.protected_method_defined?(symbol) && :protected) || + (metaclass.private_method_defined?(symbol) && :private) end private - def include_prepended_module - possible_prepended_modules = stubbee.__metaclass__.ancestors.take_while do |mod| - !(Class === mod) - end - - if possible_prepended_modules.any? - @definition_target = PrependedModule.new - stubbee.__metaclass__.__send__ :prepend, @definition_target - end - end - def definition_target @definition_target ||= stubbee.__metaclass__ end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/mocha/class_methods.rb new/lib/mocha/class_methods.rb --- old/lib/mocha/class_methods.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/mocha/class_methods.rb 2016-10-10 16:40:22.000000000 +0200 @@ -34,6 +34,7 @@ def method_exists?(method, include_public_methods = true) if include_public_methods return true if @stubba_object.public_instance_methods(include_superclass_methods = true).include?(method) + return true if @stubba_object.allocate.respond_to?(method.to_sym) end return true if @stubba_object.protected_instance_methods(include_superclass_methods = true).include?(method) return true if @stubba_object.private_instance_methods(include_superclass_methods = true).include?(method) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/mocha/integration/monkey_patcher.rb new/lib/mocha/integration/monkey_patcher.rb --- old/lib/mocha/integration/monkey_patcher.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/mocha/integration/monkey_patcher.rb 2016-10-10 16:40:22.000000000 +0200 @@ -4,13 +4,21 @@ module Integration module MonkeyPatcher def self.apply(mod, run_method_patch) - unless mod < Mocha::API + if mod < Mocha::API + Debug.puts "Mocha::API already included in #{mod}" + else mod.send(:include, Mocha::API) end - unless mod.method_defined?(:run_before_mocha) - mod.send(:alias_method, :run_before_mocha, :run) - mod.send(:remove_method, :run) - mod.send(:include, run_method_patch) + if mod.method_defined?(:run_before_mocha) + Debug.puts "#{mod}#run_before_mocha method already defined" + else + if mod.method_defined?(:run) + mod.send(:alias_method, :run_before_mocha, :run) + mod.send(:remove_method, :run) + mod.send(:include, run_method_patch) + else + raise "Unable to monkey-patch #{mod}, because it does not define a `#run` method" + end end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/mocha/mockery.rb new/lib/mocha/mockery.rb --- old/lib/mocha/mockery.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/mocha/mockery.rb 2016-10-10 16:40:22.000000000 +0200 @@ -1,3 +1,4 @@ +require 'mocha/ruby_version' require 'mocha/central' require 'mocha/mock' require 'mocha/names' @@ -97,7 +98,7 @@ end def on_stubbing(object, method) - method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym + method = PRE_RUBY_V19 ? method.to_s : method.to_sym unless Mocha::Configuration.allow?(:stubbing_non_existent_method) unless object.method_exists?(method, include_public_methods = true) on_stubbing_non_existent_method(object, method) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/mocha/parameter_matchers/equals.rb new/lib/mocha/parameter_matchers/equals.rb --- old/lib/mocha/parameter_matchers/equals.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/mocha/parameter_matchers/equals.rb 2016-10-10 16:40:22.000000000 +0200 @@ -22,7 +22,7 @@ # object = mock() # object.expects(:method_1).with(equals(2)) # object.method_1(3) - # # error raised, because method_1 was not called with an +Object+ that equals 3 + # # error raised, because method_1 was not called with an +Object+ that equals 2 def equals(value) Equals.new(value) end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/mocha/parameter_matchers/includes.rb new/lib/mocha/parameter_matchers/includes.rb --- old/lib/mocha/parameter_matchers/includes.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/mocha/parameter_matchers/includes.rb 2016-10-10 16:40:22.000000000 +0200 @@ -22,6 +22,46 @@ # @example Actual parameter does not include all items. # object.method_1(['foo', 'baz']) # # error raised, because ['foo', 'baz'] does not include 'bar'. + # + # @example Actual parameter includes item which matches nested matcher. + # object = mock() + # object.expects(:method_1).with(includes(has_key(:key))) + # object.method_1(['foo', 'bar', {:key => 'baz'}]) + # # no error raised + # + # @example Actual parameter does not include item matching nested matcher. + # object.method_1(['foo', 'bar', {:other_key => 'baz'}]) + # # error raised, because no element matches `has_key(:key)` matcher + # + # @example Actual parameter is a String including substring. + # object = mock() + # object.expects(:method_1).with(includes('bar')) + # object.method_1('foobarbaz') + # # no error raised + # + # @example Actual parameter is a String not including substring. + # object.method_1('foobaz') + # # error raised, because 'foobaz' does not include 'bar' + # + # @example Actual parameter is a Hash including the given key. + # object = mock() + # object.expects(:method_1).with(includes(:bar)) + # object.method_1({:foo => 1, :bar => 2}) + # # no error raised + # + # @example Actual parameter is a Hash without the given key. + # object.method_1({:foo => 1, :baz => 2}) + # # error raised, because hash does not include key 'bar' + # + # @example Actual parameter is a Hash with a key matching the given matcher. + # object = mock() + # object.expects(:method_1).with(includes(regexp_matches(/ar/))) + # object.method_1({'foo' => 1, 'bar' => 2}) + # # no error raised + # + # @example Actual parameter is a Hash no key matching the given matcher. + # object.method_1({'foo' => 1, 'baz' => 3}) + # # error raised, because hash does not include a key matching /ar/ def includes(*items) Includes.new(*items) end @@ -38,9 +78,12 @@ def matches?(available_parameters) parameter = available_parameters.shift return false unless parameter.respond_to?(:include?) - if @items.size == 1 - return parameter.include?(@items.first) + if parameter.respond_to?(:any?) && !parameter.is_a?(String) + return parameter.any? { |(p,_)| @items.first.to_matcher.matches?([p]) } + else + return parameter.include?(@items.first) + end else includes_matchers = @items.map { |item| Includes.new(item) } AllOf.new(*includes_matchers).matches?([parameter]) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/mocha/ruby_version.rb new/lib/mocha/ruby_version.rb --- old/lib/mocha/ruby_version.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/mocha/ruby_version.rb 2016-10-10 16:40:22.000000000 +0200 @@ -0,0 +1,4 @@ +module Mocha + PRE_RUBY_V19 = Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('1.9') + RUBY_V2_PLUS = Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2') +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/mocha/version.rb new/lib/mocha/version.rb --- old/lib/mocha/version.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/mocha/version.rb 2016-10-10 16:40:22.000000000 +0200 @@ -1,3 +1,3 @@ module Mocha - VERSION = "1.1.0" + VERSION = "1.2.0" end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 1970-01-01 01:00:00.000000000 +0100 +++ new/metadata 2016-10-10 16:40:22.000000000 +0200 @@ -1,85 +1,99 @@ --- !ruby/object:Gem::Specification name: mocha version: !ruby/object:Gem::Version - version: 1.1.0 + version: 1.2.0 platform: ruby authors: - James Mead autorequire: bindir: bin cert_chain: [] -date: 2014-05-13 00:00:00.000000000 Z +date: 2016-10-10 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: metaclass requirement: !ruby/object:Gem::Requirement requirements: - - - ~> + - - "~>" - !ruby/object:Gem::Version version: 0.0.1 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - - ~> + - - "~>" - !ruby/object:Gem::Version version: 0.0.1 - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - - '>=' + - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - - '>=' + - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: introspection requirement: !ruby/object:Gem::Requirement requirements: - - - ~> + - - "~>" - !ruby/object:Gem::Version version: 0.0.1 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - - ~> + - - "~>" - !ruby/object:Gem::Version version: 0.0.1 - !ruby/object:Gem::Dependency + name: minitest + requirement: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: '0' + type: :development + prerelease: false + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: '0' +- !ruby/object:Gem::Dependency name: yard requirement: !ruby/object:Gem::Requirement requirements: - - - '>=' + - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - - '>=' + - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: redcarpet requirement: !ruby/object:Gem::Requirement requirements: - - - ~> + - - ">=" - !ruby/object:Gem::Version - version: '1' + version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - - ~> + - - ">=" - !ruby/object:Gem::Version - version: '1' + version: '0' description: Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes. email: [email protected] @@ -87,8 +101,8 @@ extensions: [] extra_rdoc_files: [] files: -- .gemtest -- .yardopts +- ".gemtest" +- ".yardopts" - CONTRIBUTING.md - COPYING.md - Gemfile @@ -199,6 +213,7 @@ - lib/mocha/pretty_parameters.rb - lib/mocha/receivers.rb - lib/mocha/return_values.rb +- lib/mocha/ruby_version.rb - lib/mocha/sequence.rb - lib/mocha/setup.rb - lib/mocha/single_return_value.rb @@ -252,6 +267,7 @@ - test/acceptance/stub_instance_method_defined_on_object_class_test.rb - test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb - test/acceptance/stub_instance_method_defined_on_superclass_test.rb +- test/acceptance/stub_method_defined_on_module_and_aliased_test.rb - test/acceptance/stub_module_method_test.rb - test/acceptance/stub_test.rb - test/acceptance/stubba_example_test.rb @@ -339,7 +355,9 @@ - yard-templates/default/layout/html/google_analytics.erb - yard-templates/default/layout/html/setup.rb homepage: http://gofreerange.com/mocha/docs -licenses: [] +licenses: +- MIT +- BSD-2-Clause metadata: {} post_install_message: rdoc_options: [] @@ -347,19 +365,18 @@ - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - - '>=' + - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - - '>=' + - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: mocha -rubygems_version: 2.0.14 +rubygems_version: 2.5.1 signing_key: specification_version: 3 summary: Mocking and stubbing library test_files: [] -has_rdoc: yard diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocha.gemspec new/mocha.gemspec --- old/mocha.gemspec 1970-01-01 01:00:00.000000000 +0100 +++ new/mocha.gemspec 2016-10-10 16:40:22.000000000 +0200 @@ -6,6 +6,7 @@ Gem::Specification.new do |s| s.name = "mocha" s.version = Mocha::VERSION + s.licenses = ['MIT', 'BSD-2-Clause'] s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["James Mead"] @@ -28,26 +29,47 @@ s.specification_version = 3 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_development_dependency("rake", ">= 0") + if RUBY_VERSION >= '1.9.3' + s.add_development_dependency("rake", ">= 0") + else + s.add_development_dependency("rake", "~> 10.0") + end s.add_development_dependency("introspection", "~> 0.0.1") - unless ENV["MOCHA_NO_DOCS"] + if RUBY_VERSION >= '2.2.0' + s.add_development_dependency("minitest") + end + if ENV["MOCHA_GENERATE_DOCS"] s.add_development_dependency("yard") - s.add_development_dependency("redcarpet", "~> 1") + s.add_development_dependency("redcarpet") end else - s.add_dependency("rake", ">= 0") + if RUBY_VERSION >= '1.9.3' + s.add_development_dependency("rake", ">= 0") + else + s.add_development_dependency("rake", "~> 10.0") + end s.add_dependency("introspection", "~> 0.0.1") - unless ENV["MOCHA_NO_DOCS"] + if RUBY_VERSION >= '2.2.0' + s.add_dependency("minitest") + end + if ENV["MOCHA_GENERATE_DOCS"] s.add_dependency("yard") - s.add_dependency("redcarpet", "~> 1") + s.add_dependency("redcarpet") end end else - s.add_dependency("rake", ">= 0") + if RUBY_VERSION >= '1.9.3' + s.add_development_dependency("rake", ">= 0") + else + s.add_development_dependency("rake", "~> 10.0") + end s.add_dependency("introspection", "~> 0.0.1") - unless ENV["MOCHA_NO_DOCS"] + if RUBY_VERSION >= '2.2.0' + s.add_dependency("minitest") + end + if ENV["MOCHA_GENERATE_DOCS"] s.add_dependency("yard") - s.add_dependency("redcarpet", "~> 1") + s.add_dependency("redcarpet") end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/acceptance/prepend_test.rb new/test/acceptance/prepend_test.rb --- old/test/acceptance/prepend_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/acceptance/prepend_test.rb 2016-10-10 16:40:22.000000000 +0200 @@ -1,5 +1,6 @@ require File.expand_path('../acceptance_test_helper', __FILE__) require 'mocha/setup' +require 'mocha/ruby_version' class PrependTest < Mocha::TestCase @@ -13,7 +14,7 @@ teardown_acceptance_test end - if RUBY_VERSION >= '2.0' + if Mocha::RUBY_V2_PLUS module Mod1 def my_method diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/acceptance/stub_any_instance_method_test.rb new/test/acceptance/stub_any_instance_method_test.rb --- old/test/acceptance/stub_any_instance_method_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/acceptance/stub_any_instance_method_test.rb 2016-10-10 16:40:22.000000000 +0200 @@ -22,7 +22,7 @@ instance = klass.new test_result = run_as_test do klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) - assert_method_visiblity instance, :my_instance_method, :public + assert_method_visibility instance, :my_instance_method, :public assert_equal :new_return_value, instance.my_instance_method end assert_passed(test_result) @@ -77,7 +77,7 @@ instance = klass.new test_result = run_as_test do klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) - assert_method_visiblity instance, :my_instance_method, :protected + assert_method_visibility instance, :my_instance_method, :protected end assert_passed(test_result) end @@ -109,7 +109,7 @@ instance = klass.new test_result = run_as_test do klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) - assert_method_visiblity instance, :my_instance_method, :private + assert_method_visibility instance, :my_instance_method, :private end assert_passed(test_result) end @@ -127,16 +127,18 @@ assert_equal 0, klass.any_instance.mocha.__expectations__.length end - def test_should_be_able_to_stub_a_superclass_method + def test_should_be_able_to_stub_a_public_superclass_method superklass = Class.new do def my_superclass_method :original_return_value end + public :my_superclass_method end klass = Class.new(superklass) instance = klass.new test_result = run_as_test do klass.any_instance.stubs(:my_superclass_method).returns(:new_return_value) + assert_method_visibility instance, :my_superclass_method, :public assert_equal :new_return_value, instance.my_superclass_method end assert_passed(test_result) @@ -145,6 +147,46 @@ assert_equal :original_return_value, instance.my_superclass_method end + def test_should_be_able_to_stub_a_protected_superclass_method + superklass = Class.new do + def my_superclass_method + :original_return_value + end + protected :my_superclass_method + end + klass = Class.new(superklass) + instance = klass.new + test_result = run_as_test do + klass.any_instance.stubs(:my_superclass_method).returns(:new_return_value) + assert_method_visibility instance, :my_superclass_method, :protected + assert_equal :new_return_value, instance.send(:my_superclass_method) + end + assert_passed(test_result) + assert instance.protected_methods(true).any? { |m| m.to_s == 'my_superclass_method' } + assert !klass.protected_methods(false).any? { |m| m.to_s == 'my_superclass_method' } + assert_equal :original_return_value, instance.send(:my_superclass_method) + end + + def test_should_be_able_to_stub_a_private_superclass_method + superklass = Class.new do + def my_superclass_method + :original_return_value + end + private :my_superclass_method + end + klass = Class.new(superklass) + instance = klass.new + test_result = run_as_test do + klass.any_instance.stubs(:my_superclass_method).returns(:new_return_value) + assert_method_visibility instance, :my_superclass_method, :private + assert_equal :new_return_value, instance.send(:my_superclass_method) + end + assert_passed(test_result) + assert instance.private_methods(true).any? { |m| m.to_s == 'my_superclass_method' } + assert !klass.private_methods(false).any? { |m| m.to_s == 'my_superclass_method' } + assert_equal :original_return_value, instance.send(:my_superclass_method) + end + def test_should_be_able_to_stub_method_if_ruby18_public_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy ruby18_klass = Class.new do class << self @@ -185,7 +227,7 @@ end test_result = run_as_test do ruby18_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) - assert_equal :new_return_value, ruby18_klass.new.my_instance_method + assert_equal :new_return_value, ruby18_klass.new.send(:my_instance_method) end assert_passed(test_result) end @@ -200,7 +242,7 @@ end test_result = run_as_test do ruby19_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) - assert_equal :new_return_value, ruby19_klass.new.my_instance_method + assert_equal :new_return_value, ruby19_klass.new.send(:my_instance_method) end assert_passed(test_result) end @@ -215,7 +257,7 @@ end test_result = run_as_test do ruby18_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) - assert_equal :new_return_value, ruby18_klass.new.my_instance_method + assert_equal :new_return_value, ruby18_klass.new.send(:my_instance_method) end assert_passed(test_result) end @@ -230,7 +272,7 @@ end test_result = run_as_test do ruby19_klass.any_instance.stubs(:my_instance_method).returns(:new_return_value) - assert_equal :new_return_value, ruby19_klass.new.my_instance_method + assert_equal :new_return_value, ruby19_klass.new.send(:my_instance_method) end assert_passed(test_result) end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/acceptance/stub_class_method_defined_on_class_test.rb new/test/acceptance/stub_class_method_defined_on_class_test.rb --- old/test/acceptance/stub_class_method_defined_on_class_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/acceptance/stub_class_method_defined_on_class_test.rb 2016-10-10 16:40:22.000000000 +0200 @@ -26,7 +26,7 @@ assert_snapshot_unchanged(klass) do test_result = run_as_test do klass.stubs(:my_class_method).returns(:new_return_value) - assert_method_visiblity klass, :my_class_method, :public + assert_method_visibility klass, :my_class_method, :public assert_equal :new_return_value, klass.my_class_method end assert_passed(test_result) @@ -47,7 +47,7 @@ assert_snapshot_unchanged(klass) do test_result = run_as_test do klass.stubs(:my_class_method).returns(:new_return_value) - assert_method_visiblity klass, :my_class_method, :protected + assert_method_visibility klass, :my_class_method, :protected assert_equal :new_return_value, klass.send(:my_class_method) end assert_passed(test_result) @@ -68,7 +68,7 @@ assert_snapshot_unchanged(klass) do test_result = run_as_test do klass.stubs(:my_class_method).returns(:new_return_value) - assert_method_visiblity klass, :my_class_method, :private + assert_method_visibility klass, :my_class_method, :private assert_equal :new_return_value, klass.send(:my_class_method) end assert_passed(test_result) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/acceptance/stub_instance_method_defined_on_class_test.rb new/test/acceptance/stub_instance_method_defined_on_class_test.rb --- old/test/acceptance/stub_instance_method_defined_on_class_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/acceptance/stub_instance_method_defined_on_class_test.rb 2016-10-10 16:40:22.000000000 +0200 @@ -23,7 +23,7 @@ assert_snapshot_unchanged(instance) do test_result = run_as_test do instance.stubs(:my_instance_method).returns(:new_return_value) - assert_method_visiblity instance, :my_instance_method, :public + assert_method_visibility instance, :my_instance_method, :public assert_equal :new_return_value, instance.my_instance_method end assert_passed(test_result) @@ -41,7 +41,7 @@ assert_snapshot_unchanged(instance) do test_result = run_as_test do instance.stubs(:my_instance_method).returns(:new_return_value) - assert_method_visiblity instance, :my_instance_method, :protected + assert_method_visibility instance, :my_instance_method, :protected assert_equal :new_return_value, instance.send(:my_instance_method) end assert_passed(test_result) @@ -59,7 +59,7 @@ assert_snapshot_unchanged(instance) do test_result = run_as_test do instance.stubs(:my_instance_method).returns(:new_return_value) - assert_method_visiblity instance, :my_instance_method, :private + assert_method_visibility instance, :my_instance_method, :private assert_equal :new_return_value, instance.send(:my_instance_method) end assert_passed(test_result) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/acceptance/stub_instance_method_defined_on_module_test.rb new/test/acceptance/stub_instance_method_defined_on_module_test.rb --- old/test/acceptance/stub_instance_method_defined_on_module_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/acceptance/stub_instance_method_defined_on_module_test.rb 2016-10-10 16:40:22.000000000 +0200 @@ -26,6 +26,7 @@ assert_snapshot_unchanged(instance) do test_result = run_as_test do instance.stubs(:my_module_method).returns(:new_return_value) + assert_method_visibility instance, :my_module_method, :public assert_equal :new_return_value, instance.my_module_method end assert_passed(test_result) @@ -46,6 +47,7 @@ assert_snapshot_unchanged(instance) do test_result = run_as_test do instance.stubs(:my_module_method).returns(:new_return_value) + assert_method_visibility instance, :my_module_method, :protected assert_equal :new_return_value, instance.send(:my_module_method) end assert_passed(test_result) @@ -66,6 +68,7 @@ assert_snapshot_unchanged(instance) do test_result = run_as_test do instance.stubs(:my_module_method).returns(:new_return_value) + assert_method_visibility instance, :my_module_method, :private assert_equal :new_return_value, instance.send(:my_module_method) end assert_passed(test_result) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb new/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb --- old/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb 2016-10-10 16:40:22.000000000 +0200 @@ -0,0 +1,39 @@ +require File.expand_path('../acceptance_test_helper', __FILE__) +require 'mocha/setup' + +unless Mocha::PRE_RUBY_V19 + class StubMethodDefinedOnModuleAndAliasedTest < Mocha::TestCase + include AcceptanceTest + + def setup + setup_acceptance_test + end + + def teardown + teardown_acceptance_test + end + + def test_stubbing_class_method_defined_by_aliasing_module_instance_method + mod = Module.new do + def module_instance_method + 'module-instance-method' + end + end + + klass = Class.new do + extend mod + class << self + alias_method :aliased_module_instance_method, :module_instance_method + end + end + + assert_snapshot_unchanged(klass) do + test_result = run_as_test do + klass.stubs(:aliased_module_instance_method).returns('stubbed-aliased-module-instance-method') + assert_equal 'stubbed-aliased-module-instance-method', klass.aliased_module_instance_method + end + assert_passed(test_result) + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/acceptance/stubbing_nil_test.rb new/test/acceptance/stubbing_nil_test.rb --- old/test/acceptance/stubbing_nil_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/acceptance/stubbing_nil_test.rb 2016-10-10 16:40:22.000000000 +0200 @@ -13,47 +13,49 @@ teardown_acceptance_test end - def test_should_allow_stubbing_method_on_nil - Mocha::Configuration.allow(:stubbing_method_on_nil) - test_result = run_as_test do - nil.stubs(:stubbed_method) + if RUBY_VERSION < '2.2.0' + def test_should_allow_stubbing_method_on_nil + Mocha::Configuration.allow(:stubbing_method_on_nil) + test_result = run_as_test do + nil.stubs(:stubbed_method) + end + assert_passed(test_result) + assert [email protected]?("stubbing method on nil: nil.stubbed_method") end - assert_passed(test_result) - assert [email protected]?("stubbing method on nil: nil.stubbed_method") - end - def test_should_warn_on_stubbing_method_on_nil - Mocha::Configuration.warn_when(:stubbing_method_on_nil) - test_result = run_as_test do - nil.stubs(:stubbed_method) + def test_should_warn_on_stubbing_method_on_nil + Mocha::Configuration.warn_when(:stubbing_method_on_nil) + test_result = run_as_test do + nil.stubs(:stubbed_method) + end + assert_passed(test_result) + assert @logger.warnings.include?("stubbing method on nil: nil.stubbed_method") end - assert_passed(test_result) - assert @logger.warnings.include?("stubbing method on nil: nil.stubbed_method") - end - def test_should_prevent_stubbing_method_on_nil - Mocha::Configuration.prevent(:stubbing_method_on_nil) - test_result = run_as_test do - nil.stubs(:stubbed_method) + def test_should_prevent_stubbing_method_on_nil + Mocha::Configuration.prevent(:stubbing_method_on_nil) + test_result = run_as_test do + nil.stubs(:stubbed_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing method on nil: nil.stubbed_method") end - assert_failed(test_result) - assert test_result.error_messages.include?("Mocha::StubbingError: stubbing method on nil: nil.stubbed_method") - end - def test_should_default_to_prevent_stubbing_method_on_non_mock_object - test_result = run_as_test do - nil.stubs(:stubbed_method) + def test_should_default_to_prevent_stubbing_method_on_non_mock_object + test_result = run_as_test do + nil.stubs(:stubbed_method) + end + assert_failed(test_result) + assert test_result.error_messages.include?("Mocha::StubbingError: stubbing method on nil: nil.stubbed_method") end - assert_failed(test_result) - assert test_result.error_messages.include?("Mocha::StubbingError: stubbing method on nil: nil.stubbed_method") - end - def test_should_allow_stubbing_method_on_non_nil_object - Mocha::Configuration.prevent(:stubbing_method_on_nil) - object = Object.new - test_result = run_as_test do - object.stubs(:stubbed_method) + def test_should_allow_stubbing_method_on_non_nil_object + Mocha::Configuration.prevent(:stubbing_method_on_nil) + object = Object.new + test_result = run_as_test do + object.stubs(:stubbed_method) + end + assert_passed(test_result) end - assert_passed(test_result) end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/acceptance/stubbing_non_existent_any_instance_method_test.rb new/test/acceptance/stubbing_non_existent_any_instance_method_test.rb --- old/test/acceptance/stubbing_non_existent_any_instance_method_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/acceptance/stubbing_non_existent_any_instance_method_test.rb 2016-10-10 16:40:22.000000000 +0200 @@ -64,6 +64,19 @@ assert_passed(test_result) end + def test_should_allow_stubbing_method_to_which_any_instance_responds + Mocha::Configuration.prevent(:stubbing_non_existent_method) + klass = Class.new do + def respond_to?(method, include_private = false) + (method == :method_to_which_instance_responds) + end + end + test_result = run_as_test do + klass.any_instance.stubs(:method_to_which_instance_responds) + end + assert_passed(test_result) + end + def test_should_allow_stubbing_existing_protected_any_instance_method Mocha::Configuration.prevent(:stubbing_non_existent_method) klass = Class.new do diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/assertions.rb new/test/assertions.rb --- old/test/assertions.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/assertions.rb 2016-10-10 16:40:22.000000000 +0200 @@ -1,6 +1,8 @@ +require 'mocha/ruby_version' + module Assertions - def assert_method_visiblity(object, method_name, visiblity) - method_key = RUBY_VERSION < '1.9' ? method_name.to_s : method_name.to_sym - assert object.send("#{visiblity}_methods", false).include?(method_key), "#{method_name} is not #{visiblity}" + def assert_method_visibility(object, method_name, visiblity) + method_key = Mocha::PRE_RUBY_V19 ? method_name.to_s : method_name.to_sym + assert object.send("#{visiblity}_methods").include?(method_key), "#{method_name} is not #{visiblity}" end -end \ No newline at end of file +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/minitest_result.rb new/test/minitest_result.rb --- old/test/minitest_result.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/minitest_result.rb 2016-10-10 16:40:22.000000000 +0200 @@ -20,7 +20,7 @@ end def failures - @tests.map(&:failures).flatten.select { |r| Minitest::Assertion === r }.map { |f| Failure.new(f) } + @tests.map(&:failures).flatten.select { |r| r.instance_of?(Minitest::Assertion) }.map { |f| Failure.new(f) } end def failure_count @@ -32,7 +32,7 @@ end def errors - @tests.map(&:failures).flatten.select { |r| Minitest::UnexpectedError === r } + @tests.map(&:failures).flatten.select { |r| r.instance_of?(Minitest::UnexpectedError) } end def error_count diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test_runner.rb new/test/test_runner.rb --- old/test/test_runner.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/test_runner.rb 2016-10-10 16:40:22.000000000 +0200 @@ -49,7 +49,7 @@ def assert_passed(test_result) flunk "Test failed unexpectedly with message: #{test_result.failures}" if test_result.failure_count > 0 - flunk "Test failed unexpectedly with message: #{test_result.errors}" if test_result.error_count > 0 + flunk "Test failed unexpectedly with message: #{test_result.errors.map(&:exception)}" if test_result.error_count > 0 end def assert_failed(test_result) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/unit/any_instance_method_test.rb new/test/unit/any_instance_method_test.rb --- old/test/unit/any_instance_method_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/unit/any_instance_method_test.rb 2016-10-10 16:40:22.000000000 +0200 @@ -7,6 +7,7 @@ include Mocha +unless RUBY_V2_PLUS def test_should_hide_original_method klass = Class.new { def method_x; end } method = AnyInstanceMethod.new(klass, :method_x) @@ -15,6 +16,7 @@ assert_equal false, klass.method_defined?(:method_x) end +end def test_should_not_raise_error_hiding_method_that_isnt_defined klass = Class.new diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/unit/class_method_test.rb new/test/unit/class_method_test.rb --- old/test/unit/class_method_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/unit/class_method_test.rb 2016-10-10 16:40:22.000000000 +0200 @@ -8,6 +8,7 @@ include Mocha +unless RUBY_V2_PLUS def test_should_hide_original_method klass = Class.new { def self.method_x; end } method = ClassMethod.new(klass, :method_x) @@ -16,6 +17,7 @@ assert_equal false, klass.respond_to?(:method_x) end +end def test_should_not_raise_error_hiding_method_that_isnt_defined klass = Class.new diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/unit/mock_test.rb new/test/unit/mock_test.rb --- old/test/unit/mock_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/unit/mock_test.rb 2016-10-10 16:40:22.000000000 +0200 @@ -1,4 +1,5 @@ require File.expand_path('../../test_helper', __FILE__) +require 'mocha/ruby_version' require 'mocha/mock' require 'mocha/expectation_error_factory' require 'set' @@ -44,7 +45,7 @@ assert_equal true, mock.eql?(mock) end - if RUBY_VERSION < '1.9' + if PRE_RUBY_V19 OBJECT_METHODS = STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS.reject { |m| m =~ /^__.*__$/ || ["method_missing", "singleton_method_undefined", "initialize"].include?(m)} else OBJECT_METHODS = STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS.reject { |m| m =~ /^__.*__$/ || [:object_id, :method_missing, :singleton_method_undefined, :initialize, :String, :singleton_method_added].include?(m) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/unit/object_inspect_test.rb new/test/unit/object_inspect_test.rb --- old/test/unit/object_inspect_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/unit/object_inspect_test.rb 2016-10-10 16:40:22.000000000 +0200 @@ -1,4 +1,5 @@ require File.expand_path('../../test_helper', __FILE__) +require 'mocha/ruby_version' require 'mocha/inspect' require 'method_definer' @@ -25,7 +26,7 @@ def test_should_use_underscored_id_instead_of_object_id_or_id_so_that_they_can_be_stubbed calls = [] object = Object.new - object.replace_instance_method(:id) { calls << :id; return 1 } if RUBY_VERSION < '1.9' + object.replace_instance_method(:id) { calls << :id; return 1 } if Mocha::PRE_RUBY_V19 object.replace_instance_method(:object_id) { calls << :object_id; return 1 } object.replace_instance_method(:__id__) { calls << :__id__; return 1 } object.replace_instance_method(:inspect) { "object-description" } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/unit/parameter_matchers/includes_test.rb new/test/unit/parameter_matchers/includes_test.rb --- old/test/unit/parameter_matchers/includes_test.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/unit/parameter_matchers/includes_test.rb 2016-10-10 16:40:22.000000000 +0200 @@ -1,6 +1,9 @@ require File.expand_path('../../../test_helper', __FILE__) require 'mocha/parameter_matchers/includes' +require 'mocha/parameter_matchers/object' +require 'mocha/parameter_matchers/has_key' +require 'mocha/parameter_matchers/regexp_matches' require 'mocha/inspect' class IncludesTest < Mocha::TestCase @@ -56,4 +59,44 @@ matcher = includes(:x) assert !matcher.matches?([:x]) end + + def test_should_match_object_including_value_which_matches_nested_matcher + matcher = includes(has_key(:key)) + assert matcher.matches?([[:non_matching_element, {:key => 'value'}]]) + end + + def test_should_not_match_object_which_doesnt_include_value_that_matches_nested_matcher + matcher = includes(has_key(:key)) + assert !matcher.matches?([[:non_matching_element, {:other_key => 'other-value'}]]) + end + + def test_should_match_string_argument_containing_substring + matcher = includes('bar') + assert matcher.matches?(['foobarbaz']) + end + + def test_should_not_match_string_argument_without_substring + matcher = includes('bar') + assert !matcher.matches?(['foobaz']) + end + + def test_should_match_hash_argument_containing_given_key + matcher = includes(:key) + assert matcher.matches?([{:thing => 1, :key => 2}]) + end + + def test_should_not_match_hash_argument_missing_given_key + matcher = includes(:key) + assert !matcher.matches?([{:thing => 1, :other => :key}]) + end + + def test_should_match_hash_when_nested_matcher_matches_key + matcher = includes(regexp_matches(/ar/)) + assert matcher.matches?([{'foo' => 1, 'bar' => 2}]) + end + + def test_should_not_match_hash_when_nested_matcher_doesn_not_match_key + matcher = includes(regexp_matches(/az/)) + assert !matcher.matches?([{'foo' => 1, 'bar' => 2}]) + end end
