mocha 1.2.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +38 -7
  3. data/RELEASE.md +32 -1
  4. data/lib/mocha/any_instance_method.rb +1 -1
  5. data/lib/mocha/api.rb +11 -5
  6. data/lib/mocha/deprecation.rb +7 -4
  7. data/lib/mocha/inspect.rb +0 -10
  8. data/lib/mocha/instance_method.rb +0 -8
  9. data/lib/mocha/mini_test.rb +4 -2
  10. data/lib/mocha/minitest.rb +3 -0
  11. data/lib/mocha/mock.rb +14 -2
  12. data/lib/mocha/parameter_matchers.rb +1 -1
  13. data/lib/mocha/parameter_matchers/{query_string.rb → equivalent_uri.rb} +18 -9
  14. data/lib/mocha/parameter_matchers/includes.rb +2 -1
  15. data/lib/mocha/version.rb +1 -1
  16. data/mocha.gemspec +1 -0
  17. data/test/acceptance/failure_messages_test.rb +1 -1
  18. data/test/acceptance/mock_with_initializer_block_test.rb +21 -14
  19. data/test/acceptance/parameter_matcher_test.rb +4 -40
  20. data/test/acceptance/sequence_test.rb +5 -5
  21. data/test/acceptance/stub_module_method_test.rb +45 -7
  22. data/test/acceptance/stubba_test_result_test.rb +12 -3
  23. data/test/acceptance/stubbing_on_non_mock_object_test.rb +16 -4
  24. data/test/deprecation_disabler.rb +1 -0
  25. data/test/execution_point.rb +6 -4
  26. data/test/integration/mini_test_test.rb +1 -1
  27. data/test/unit/any_instance_method_test.rb +2 -0
  28. data/test/unit/array_inspect_test.rb +1 -1
  29. data/test/unit/class_method_test.rb +7 -3
  30. data/test/unit/expectation_test.rb +1 -1
  31. data/test/unit/hash_inspect_test.rb +1 -1
  32. data/test/unit/mock_test.rb +8 -0
  33. data/test/unit/mockery_test.rb +11 -5
  34. data/test/unit/parameter_matchers/equals_test.rb +1 -1
  35. data/test/unit/parameter_matchers/equivalent_uri_test.rb +51 -0
  36. data/test/unit/parameter_matchers/has_entry_test.rb +2 -2
  37. data/test/unit/parameter_matchers/has_value_test.rb +1 -1
  38. data/test/unit/parameter_matchers/includes_test.rb +5 -0
  39. data/test/unit/sequence_test.rb +1 -1
  40. data/test/unit/string_inspect_test.rb +2 -2
  41. metadata +7 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41ba040450c12b37d2cce4a23948f3944b97a003
4
- data.tar.gz: 386b73723224bcaf481cc15324ba0dbe5534e423
3
+ metadata.gz: b1a4df2eb13604de6b309bc453307d375c055620
4
+ data.tar.gz: 9144ebfe812beea562fc8c9ebdfb87326cb5ffa6
5
5
  SHA512:
6
- metadata.gz: 2c5537469c485a8fb71dc4c41a16355b5e9401eab0b157554f7f4c374b4b468b0a30ebd17fcd8b8c76b8cf4babdf2d3118e4147b5a65ca88d5c9a1ab7ded31c9
7
- data.tar.gz: d0f420d06bf65eb02c49fbaa0077cb6f2c2d6f7f1ab41d5e622aec3ee761a2f0824ac2bdad2d602cfc83c508a11e3121e6166cbf61140801cbfd6ad3a7a4fc11
6
+ metadata.gz: 1cf5b923bb4a91c6b3a1dac90aca3084229955743ae64c41cbecf561e8fd572f419d09d155ff3c9b6d0616258ca526d70677d79f9861e8987f99ee5b312bbb90
7
+ data.tar.gz: 9e635e0f0897d0437acffe0cfe4755ecae028da76513445a5b4b56ee48be878ae0070fa24d3fc8bddad02a69d790223909b936fdcdb6f53114feeec8c69cd3c4
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ## Mocha [![build status](https://secure.travis-ci.org/freerange/mocha.png)](https://secure.travis-ci.org/freerange/mocha) [![Gem Version](https://badge.fury.io/rb/mocha.png)](http://badge.fury.io/rb/mocha) [![OpenCollective](https://opencollective.com/mocha/backers/badge.svg)](#backers) [![OpenCollective](https://opencollective.com/mocha/sponsors/badge.svg)](#sponsors)
1
+ ## Mocha [![Build Status](https://travis-ci.org/freerange/mocha.svg?branch=master)](https://travis-ci.org/freerange/mocha) [![Gem Version](https://badge.fury.io/rb/mocha.png)](http://badge.fury.io/rb/mocha) [![OpenCollective](https://opencollective.com/mocha/backers/badge.svg)](#backers) [![OpenCollective](https://opencollective.com/mocha/sponsors/badge.svg)](#sponsors)
2
2
 
3
3
 
4
4
  ### Description
@@ -33,7 +33,7 @@ require 'mocha/test_unit'
33
33
  require 'rubygems'
34
34
  gem 'mocha'
35
35
  require 'minitest/unit'
36
- require 'mocha/mini_test'
36
+ require 'mocha/minitest'
37
37
  ```
38
38
 
39
39
  #### Bundler
@@ -59,7 +59,7 @@ gem "mocha"
59
59
 
60
60
  # Elsewhere after Bundler has loaded gems e.g. after `require 'bundler/setup'`
61
61
  require "minitest/unit"
62
- require "mocha/mini_test"
62
+ require "mocha/minitest"
63
63
  ```
64
64
 
65
65
  #### Rails
@@ -73,12 +73,12 @@ If you're loading Mocha using Bundler within a Rails application, you should set
73
73
  gem 'mocha'
74
74
 
75
75
  # At bottom of test_helper.rb (or at least after `require 'rails/test_help'`)
76
- require 'mocha/mini_test'
76
+ require 'mocha/minitest'
77
77
  ```
78
78
 
79
79
  ##### RSpec
80
80
 
81
- Assuming you are using the `rspec-rails` gem:
81
+ RSpec includes a mocha adapter. Just tell RSpec you want to mock with `:mocha`:
82
82
 
83
83
  ```ruby
84
84
  # Gemfile in Rails app
@@ -104,12 +104,13 @@ Note: As of version 0.9.8, the Mocha plugin is not automatically setup at plugin
104
104
 
105
105
  ```ruby
106
106
  # At bottom of test_helper.rb (or at least after `require 'rails/test_help'`)
107
- require 'mocha/mini_test'
107
+ require 'mocha/minitest'
108
108
  ```
109
109
 
110
110
  #### Known Issues
111
111
 
112
112
  * In Mocha v1.2.0 there is a scenario where stubbing a class method originally defined in a module hangs the Ruby interpreter due to [a bug in Ruby v2.3.1](https://bugs.ruby-lang.org/issues/12832). See #272. This was fixed in Mocha v1.2.1.
113
+ * Since v1.1.0 Mocha has used prepended modules internally for stubbing methods. There is [an obscure Ruby bug](https://bugs.ruby-lang.org/issues/12876) in many (but not all) versions of Ruby between v2.0 & v2.3 which under certain circumstances may cause your Ruby interpreter to hang. See the Ruby bug report for more details. The bug has been fixed in Ruby v2.3.3 & v2.4.0.
113
114
  * 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.
114
115
  * 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.
115
116
  * 0.11.x versions don't work with Rails 3.2.13 (`TypeError: superclass mismatch for class ExpectationError`). See #115.
@@ -281,7 +282,7 @@ See the [documentation](http://gofreerange.com/mocha/docs/Mocha/Mock.html) for `
281
282
 
282
283
  See this [list of contributors](https://github.com/freerange/mocha/graphs/contributors).
283
284
 
284
- ###Backers
285
+ ### Backers
285
286
 
286
287
  Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/mocha#backer)]
287
288
 
@@ -317,6 +318,7 @@ Support us with a monthly donation and help us continue our activities. [[Become
317
318
  <a href="https://opencollective.com/mocha/backer/29/website" target="_blank"><img src="https://opencollective.com/mocha/backer/29/avatar.svg"></a>
318
319
 
319
320
  ### Sponsors
321
+
320
322
  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)]
321
323
 
322
324
  <a href="https://opencollective.com/mocha/sponsor/0/website" target="_blank"><img src="https://opencollective.com/mocha/sponsor/0/avatar.svg"></a>
@@ -354,6 +356,35 @@ Become a sponsor and get your logo on our README on Github with a link to your s
354
356
 
355
357
  * [Serbo-Croatian](http://science.webhostinggeeks.com/mocha) by [WHG Team](http://webhostinggeeks.com/). (may be out-of-date)
356
358
 
359
+ ### Releasing a new version
360
+
361
+ * Update the RELEASE.md file with a summary of changes
362
+ * Bump the version in `lib/mocha/version.rb`
363
+ * Commit & push to Github
364
+ * Check Travis CI build is passing - https://travis-ci.org/freerange/mocha
365
+
366
+ * Sign in to rubygems.org and find API key - https://rubygems.org/profile/edit
367
+
368
+ ```bash
369
+ $ curl -u james@floehopper.org https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials`
370
+ ```
371
+
372
+ * Sign in to Google Analytics - https://analytics.google.com/analytics/web/
373
+ * Find the web property ID for Go Free Range Ltd > Mocha Documentation (UA-45002715-2)
374
+
375
+ ```bash
376
+ $ MOCHA_GENERATE_DOCS=true bundle install
377
+
378
+ $ MOCHA_GENERATE_DOCS=true GOOGLE_ANALYTICS_WEB_PROPERTY_ID=UA-45002715-2 rake release
379
+ mocha 1.2.0 built to pkg/mocha-1.2.0.gem.
380
+ Tagged v1.2.0.
381
+ Pushed git commits and tags.
382
+ Pushed mocha 1.2.0 to rubygems.org.
383
+ [runs tests]
384
+ [generates docs]
385
+ [deploys docs]
386
+ ```
387
+
357
388
  ### History
358
389
 
359
390
  Mocha was initially harvested from projects at [Reevoo](http://www.reevoo.com/). It's syntax is heavily based on that of [jMock](http://www.jmock.org).
data/RELEASE.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # Release Notes
2
2
 
3
+ ## 1.4.0
4
+
5
+ * Fix deprecation warning for `assert_nil` in `ClassMethodTest` (#308 & #309)
6
+ * Display file and line number in deprecation warning - thanks to @chrisarcand (#310, #312 & #313)
7
+ * Rename `mocha/mini_test.rb` to `mocha/minitest.rb` - thanks to @grosser (#320 & #322)
8
+ * Fix warning when delegating to mock in Ruby 2.4 - thanks to @tjvc (#321 & #323)
9
+ * Updates to Travis CI configuration ([73af600..9732726](https://github.com/freerange/mocha/compare/73af600...9732726) & 0426e5e)
10
+
11
+ ## 1.3.0
12
+
13
+ * Ensure all tests run individually - thanks to @chrisroos (#267)
14
+ * Update Travis CI build status badge to show master branch status (#264)
15
+ * Correct RSpec section of the README - thanks to @myronmarston (0cc039c8)
16
+ * Fix pretty printing of quotes in `String#mocha_inspect` (#215 & #223)
17
+ * Add release instructions to README - thanks to @chrisroos (70a5febd & 3c664df7)
18
+ * Require at least Ruby v1.8.7 in gemspec - thanks to @knappe (3e20be8e)
19
+ * Remove redundant InstanceMethod#method_exists? - thanks to @chrisroos (8f58eddf)
20
+ * Reduce risk of hitting bug 12832 in Ruby v2.3 - thanks to @chrisroos (#277 & eca7560c)
21
+ * Fix JRuby build - thanks to @headius (jruby/jruby#4250) & @chrisroos (#274)
22
+ * Add latest stable version of JRuby to Travis CI build matrix (#288)
23
+ * Fix Ruby v1.8.7 builds on Travis CI (928b5a40 & 460dce5b)
24
+ * Deprecate passing block to mock object constructor (#290)
25
+ * Add a known issue to README for Ruby bug 12876 (#276)
26
+ * Add Ruby 2.4 and ruby-head to Travis CI build matrix - thanks to @junaruga (#297)
27
+ * Fix `Mocha::ParameterMatchers#includes` for `Array` values - thanks to @timcraft (#302)
28
+ * Use faster container-based virtual environments for Travis CI builds (#305)
29
+ * Rename `Mocha::ParameterMatchers::QueryStringMatches` to `QueryString` (#306)
30
+ * Handle blank parameter value for query string matcher - thanks to @weynsee (#303 & #304)
31
+ * Rename `Mocha::ParameterMatchers::QueryString` -> `EquivalentUri` (#307)
32
+ * Use `do ... end` instead of `{ ... }` in acceptance tests - thanks to @chrisroos (#294)
33
+
3
34
  ## 1.2.1
4
35
 
5
36
  * Fixed #272. Workaround Ruby bug 12832 which caused interpreter to hang. See https://bugs.ruby-lang.org/issues/12832. Thanks to @chrisroos & @petems (6f1c8b9b, #273).
@@ -395,7 +426,7 @@ Hash with wrong number of entries.
395
426
 
396
427
  ## 0.5.0
397
428
 
398
- - Parameter Matchers - Ive added a few Hamcrest-style parameter matchers which are designed to be used inside Expectation#with. The following matchers are currently available: anything(), includes(), has_key(), has_value(), has_entry(), all_of() & any_of(). More to follow soon. The idea is eventually to get rid of the nasty parameter_block option on Expectation#with.
429
+ - Parameter Matchers - I've added a few Hamcrest-style parameter matchers which are designed to be used inside Expectation#with. The following matchers are currently available: anything(), includes(), has_key(), has_value(), has_entry(), all_of() & any_of(). More to follow soon. The idea is eventually to get rid of the nasty parameter_block option on Expectation#with.
399
430
 
400
431
  object = mock()
401
432
  object.expects(:method).with(has_key('key_1'))
@@ -16,11 +16,11 @@ module Mocha
16
16
  def hide_original_method
17
17
  if @original_visibility = method_visibility(method)
18
18
  begin
19
- @original_method = stubbee.instance_method(method)
20
19
  if RUBY_V2_PLUS
21
20
  @definition_target = PrependedModule.new
22
21
  stubbee.__send__ :prepend, @definition_target
23
22
  else
23
+ @original_method = stubbee.instance_method(method)
24
24
  if @original_method && @original_method.owner == stubbee
25
25
  stubbee.send(:remove_method, method)
26
26
  end
@@ -25,7 +25,9 @@ module Mocha
25
25
  #
26
26
  # @param [String] name identifies mock object in error messages.
27
27
  # @param [Hash] expected_methods_vs_return_values expected method name symbols as keys and corresponding return values as values - these expectations are setup as if {Mock#expects} were called multiple times.
28
- # @yield optional block to be evaluated against the mock object instance, giving an alternative way to setup expectations.
28
+ # @yield optional block to be evaluated in the context of the mock object instance, giving an alternative way to setup stubbed methods.
29
+ # @yield note that the block is evaulated by calling Mock#instance_eval and so things like instance variables declared in the test will not be available within the block.
30
+ # @yield deprecated: use Object#tap or define stubs/expectations with an explicit receiver instead.
29
31
  # @return [Mock] a new mock object
30
32
  #
31
33
  # @overload def mock(name, &block)
@@ -39,7 +41,7 @@ module Mocha
39
41
  # assert motor.stop
40
42
  # # an error will be raised unless both Motor#start and Motor#stop have been called
41
43
  # end
42
- # @example Using the optional block to setup expectations & stubbed methods.
44
+ # @example Using the optional block to setup expectations & stubbed methods [deprecated].
43
45
  # def test_motor_starts_and_stops
44
46
  # motor = mock('motor') do
45
47
  # expects(:start).with(100.rpm).returns(true)
@@ -61,7 +63,9 @@ module Mocha
61
63
  #
62
64
  # @param [String] name identifies mock object in error messages.
63
65
  # @param [Hash] stubbed_methods_vs_return_values stubbed method name symbols as keys and corresponding return values as values - these stubbed methods are setup as if {Mock#stubs} were called multiple times.
64
- # @yield optional block to be evaluated against the mock object instance, giving an alternative way to setup stubbed methods.
66
+ # @yield optional block to be evaluated in the context of the mock object instance, giving an alternative way to setup stubbed methods.
67
+ # @yield note that the block is evaulated by calling Mock#instance_eval and so things like instance variables declared in the test will not be available within the block.
68
+ # @yield deprecated: use Object#tap or define stubs/expectations with an explicit receiver instead.
65
69
  # @return [Mock] a new mock object
66
70
  #
67
71
  # @overload def stub(name, &block)
@@ -76,7 +80,7 @@ module Mocha
76
80
  # # an error will not be raised even if either Motor#start or Motor#stop has not been called
77
81
  # end
78
82
  #
79
- # @example Using the optional block to setup expectations & stubbed methods.
83
+ # @example Using the optional block to setup expectations & stubbed methods [deprecated].
80
84
  # def test_motor_starts_and_stops
81
85
  # motor = stub('motor') do
82
86
  # expects(:start).with(100.rpm).returns(true)
@@ -98,7 +102,9 @@ module Mocha
98
102
  #
99
103
  # @param [String] name identifies mock object in error messages.
100
104
  # @param [Hash] stubbed_methods_vs_return_values stubbed method name symbols as keys and corresponding return values as values - these stubbed methods are setup as if {Mock#stubs} were called multiple times.
101
- # @yield optional block to be evaluated against the mock object instance, giving an alternative way to setup stubbed methods.
105
+ # @yield optional block to be evaluated in the context of the mock object instance, giving an alternative way to setup stubbed methods.
106
+ # @yield note that the block is evaulated by calling Mock#instance_eval and so things like instance variables declared in the test will not be available within the block.
107
+ # @yield deprecated: use Object#tap or define stubs/expectations with an explicit receiver instead.
102
108
  # @return [Mock] a new mock object
103
109
  #
104
110
  # @overload def stub_everything(name, &block)
@@ -1,4 +1,4 @@
1
- require 'mocha/debug'
1
+ require 'mocha/backtrace_filter'
2
2
 
3
3
  module Mocha
4
4
 
@@ -10,13 +10,16 @@ module Mocha
10
10
 
11
11
  def warning(message)
12
12
  @messages << message
13
- $stderr.puts "\n*** Mocha deprecation warning: #{message}\n\n" unless mode == :disabled
14
- $stderr.puts caller.join("\n ") if mode == :debug
13
+ unless mode == :disabled
14
+ filter = BacktraceFilter.new
15
+ location = filter.filtered(caller)[0]
16
+ $stderr.puts "Mocha deprecation warning at #{location}: #{message}"
17
+ end
15
18
  end
16
19
 
17
20
  end
18
21
 
19
- self.mode = Debug::OPTIONS['debug'] ? :debug : :enabled
22
+ self.mode = :enabled
20
23
  self.messages = []
21
24
 
22
25
  end
@@ -10,12 +10,6 @@ module Mocha
10
10
  end
11
11
  end
12
12
 
13
- module StringMethods
14
- def mocha_inspect
15
- inspect.gsub(/\"/, "'")
16
- end
17
- end
18
-
19
13
  module ArrayMethods
20
14
  def mocha_inspect
21
15
  "[#{collect { |member| member.mocha_inspect }.join(', ')}]"
@@ -46,10 +40,6 @@ class Object
46
40
  include Mocha::ObjectMethods
47
41
  end
48
42
 
49
- class String
50
- include Mocha::StringMethods
51
- end
52
-
53
43
  class Array
54
44
  include Mocha::ArrayMethods
55
45
  end
@@ -3,14 +3,6 @@ require 'mocha/class_method'
3
3
  module Mocha
4
4
 
5
5
  class InstanceMethod < ClassMethod
6
-
7
- def method_exists?(method)
8
- return true if stubbee.public_methods(false).include?(method)
9
- return true if stubbee.protected_methods(false).include?(method)
10
- return true if stubbee.private_methods(false).include?(method)
11
- return false
12
- end
13
-
14
6
  end
15
7
 
16
8
  end
@@ -1,3 +1,5 @@
1
- require "mocha/integration/mini_test"
1
+ require 'mocha/deprecation'
2
2
 
3
- Mocha::Integration::MiniTest.activate
3
+ Mocha::Deprecation.warning("`require 'mocha/mini_test'` has been deprecated. Please use `require 'mocha/minitest' instead.")
4
+
5
+ require 'mocha/minitest'
@@ -0,0 +1,3 @@
1
+ require "mocha/integration/mini_test"
2
+
3
+ Mocha::Integration::MiniTest.activate
@@ -8,6 +8,8 @@ require 'mocha/parameters_matcher'
8
8
  require 'mocha/unexpected_invocation'
9
9
  require 'mocha/argument_iterator'
10
10
  require 'mocha/expectation_error_factory'
11
+ require 'mocha/deprecation'
12
+ require 'mocha/ruby_version'
11
13
 
12
14
  module Mocha
13
15
 
@@ -259,7 +261,10 @@ module Mocha
259
261
  @everything_stubbed = false
260
262
  @responder = nil
261
263
  @unexpected_invocation = nil
262
- instance_eval(&block) if block
264
+ if block
265
+ Deprecation.warning('Passing a block is deprecated. Use Object#tap or define stubs/expectations with an explicit receiver instead.')
266
+ instance_eval(&block)
267
+ end
263
268
  end
264
269
 
265
270
  # @private
@@ -310,7 +315,7 @@ module Mocha
310
315
  end
311
316
 
312
317
  # @private
313
- def respond_to?(symbol, include_private = false)
318
+ def respond_to_missing?(symbol, include_private = false)
314
319
  if @responder then
315
320
  if @responder.method(:respond_to?).arity > 1
316
321
  @responder.respond_to?(symbol, include_private)
@@ -322,6 +327,13 @@ module Mocha
322
327
  end
323
328
  end
324
329
 
330
+ # @private
331
+ if PRE_RUBY_V19
332
+ def respond_to?(symbol, include_private = false)
333
+ respond_to_missing?(symbol, include_private)
334
+ end
335
+ end
336
+
325
337
  # @private
326
338
  def __verified__?(assertion_counter = nil)
327
339
  @expectations.verified?(assertion_counter)
@@ -25,4 +25,4 @@ require 'mocha/parameter_matchers/optionally'
25
25
  require 'mocha/parameter_matchers/regexp_matches'
26
26
  require 'mocha/parameter_matchers/responds_with'
27
27
  require 'mocha/parameter_matchers/yaml_equivalent'
28
- require 'mocha/parameter_matchers/query_string'
28
+ require 'mocha/parameter_matchers/equivalent_uri'
@@ -1,5 +1,7 @@
1
+ require 'mocha/deprecation'
1
2
  require 'mocha/parameter_matchers/base'
2
3
  require 'uri'
4
+ require 'cgi'
3
5
 
4
6
  module Mocha
5
7
  module ParameterMatchers
@@ -7,27 +9,34 @@ module Mocha
7
9
  # Matches a URI without regard to the ordering of parameters in the query string.
8
10
  #
9
11
  # @param [String] uri URI to match.
10
- # @return [QueryStringMatches] parameter matcher.
12
+ # @return [EquivalentUri] parameter matcher.
11
13
  #
12
14
  # @see Expectation#with
13
15
  #
14
- # @example Actual URI has equivalent query string.
16
+ # @example Actual URI is equivalent.
15
17
  # object = mock()
16
- # object.expects(:method_1).with(has_equivalent_query_string('http://example.com/foo?a=1&b=2))
18
+ # object.expects(:method_1).with(equivalent_uri('http://example.com/foo?a=1&b=2))
17
19
  # object.method_1('http://example.com/foo?b=2&a=1')
18
20
  # # no error raised
19
21
  #
20
- # @example Actual URI does not have equivalent query string.
22
+ # @example Actual URI is not equivalent.
21
23
  # object = mock()
22
- # object.expects(:method_1).with(has_equivalent_query_string('http://example.com/foo?a=1&b=2))
24
+ # object.expects(:method_1).with(equivalent_uri('http://example.com/foo?a=1&b=2))
23
25
  # object.method_1('http://example.com/foo?a=1&b=3')
24
26
  # # error raised, because the query parameters were different
27
+ def equivalent_uri(uri)
28
+ EquivalentUri.new(uri)
29
+ end
30
+
31
+ # @deprecated Use {#equivalent_uri} instead.
25
32
  def has_equivalent_query_string(uri)
26
- QueryStringMatches.new(uri)
33
+ Mocha::Deprecation.warning("`has_equivalent_query_string` is deprecated. Please use `equivalent_uri` instead.")
34
+
35
+ equivalent_uri(uri)
27
36
  end
28
37
 
29
38
  # Parameter matcher which matches URIs with equivalent query strings.
30
- class QueryStringMatches < Base
39
+ class EquivalentUri < Base
31
40
 
32
41
  # @private
33
42
  def initialize(uri)
@@ -43,13 +52,13 @@ module Mocha
43
52
 
44
53
  # @private
45
54
  def mocha_inspect
46
- "has_equivalent_query_string(#{@uri.mocha_inspect})"
55
+ "equivalent_uri(#{@uri.mocha_inspect})"
47
56
  end
48
57
 
49
58
  private
50
59
  # @private
51
60
  def explode(uri)
52
- query_hash = (uri.query || '').split('&').inject({}){ |h, kv| h.merge(Hash[*kv.split('=')]) }
61
+ query_hash = CGI.parse(uri.query || '')
53
62
  URI::Generic::COMPONENT.inject({}){ |h, k| h.merge(k => uri.__send__(k)) }.merge(:query => query_hash)
54
63
  end
55
64
 
@@ -80,7 +80,8 @@ module Mocha
80
80
  return false unless parameter.respond_to?(:include?)
81
81
  if @items.size == 1
82
82
  if parameter.respond_to?(:any?) && !parameter.is_a?(String)
83
- return parameter.any? { |(p,_)| @items.first.to_matcher.matches?([p]) }
83
+ parameter = parameter.keys if parameter.is_a?(Hash)
84
+ return parameter.any? { |p| @items.first.to_matcher.matches?([p]) }
84
85
  else
85
86
  return parameter.include?(@items.first)
86
87
  end
@@ -1,3 +1,3 @@
1
1
  module Mocha
2
- VERSION = "1.2.1"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -7,6 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.name = "mocha"
8
8
  s.version = Mocha::VERSION
9
9
  s.licenses = ['MIT', 'BSD-2-Clause']
10
+ s.required_ruby_version = '>= 1.8.7'
10
11
 
11
12
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
13
  s.authors = ["James Mead"]
@@ -58,7 +58,7 @@ class FailureMessagesTest < Mocha::TestCase
58
58
  test_result = run_as_test do
59
59
  'Foo'.expects(:bar)
60
60
  end
61
- assert_match Regexp.new("'Foo'"), test_result.failures[0].message
61
+ assert_match Regexp.new(%{"Foo"}), test_result.failures[0].message
62
62
  end
63
63
 
64
64
  end
@@ -1,5 +1,6 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/setup'
3
+ require 'deprecation_disabler'
3
4
 
4
5
  class MockWithInitializerBlockTest < Mocha::TestCase
5
6
 
@@ -15,35 +16,41 @@ class MockWithInitializerBlockTest < Mocha::TestCase
15
16
 
16
17
  def test_should_expect_two_method_invocations_and_receive_both_of_them
17
18
  test_result = run_as_test do
18
- mock = mock() do
19
- expects(:method_1)
20
- expects(:method_2)
19
+ DeprecationDisabler.disable_deprecations do
20
+ mock = mock() do
21
+ expects(:method_1)
22
+ expects(:method_2)
23
+ end
24
+ mock.method_1
25
+ mock.method_2
21
26
  end
22
- mock.method_1
23
- mock.method_2
24
27
  end
25
28
  assert_passed(test_result)
26
29
  end
27
30
 
28
31
  def test_should_expect_two_method_invocations_but_receive_only_one_of_them
29
32
  test_result = run_as_test do
30
- mock = mock() do
31
- expects(:method_1)
32
- expects(:method_2)
33
+ DeprecationDisabler.disable_deprecations do
34
+ mock = mock() do
35
+ expects(:method_1)
36
+ expects(:method_2)
37
+ end
38
+ mock.method_1
33
39
  end
34
- mock.method_1
35
40
  end
36
41
  assert_failed(test_result)
37
42
  end
38
43
 
39
44
  def test_should_stub_methods
40
45
  test_result = run_as_test do
41
- mock = mock() do
42
- stubs(:method_1).returns(1)
43
- stubs(:method_2).returns(2)
46
+ DeprecationDisabler.disable_deprecations do
47
+ mock = mock() do
48
+ stubs(:method_1).returns(1)
49
+ stubs(:method_2).returns(2)
50
+ end
51
+ assert_equal 1, mock.method_1
52
+ assert_equal 2, mock.method_2
44
53
  end
45
- assert_equal 1, mock.method_1
46
- assert_equal 2, mock.method_2
47
54
  end
48
55
  assert_passed(test_result)
49
56
  end
@@ -243,60 +243,24 @@ class ParameterMatcherTest < Mocha::TestCase
243
243
  assert_failed(test_result)
244
244
  end
245
245
 
246
- def test_should_match_parameter_that_has_identical_query_string
246
+ def test_should_match_parameter_that_is_equivalent_uri
247
247
  test_result = run_as_test do
248
248
  mock = mock()
249
- mock.expects(:method).with(has_equivalent_query_string('http://example.com/foo?a=1&b=2'))
249
+ mock.expects(:method).with(equivalent_uri('http://example.com/foo?b=2&a=1'))
250
250
  mock.method('http://example.com/foo?a=1&b=2')
251
251
  end
252
252
  assert_passed(test_result)
253
253
  end
254
254
 
255
- def test_should_match_parameter_that_has_rearranged_query_string
255
+ def test_should_not_match_parameter_that_is_not_equivalent
256
256
  test_result = run_as_test do
257
257
  mock = mock()
258
- mock.expects(:method).with(has_equivalent_query_string('http://example.com/foo?b=2&a=1'))
258
+ mock.expects(:method).with(equivalent_uri('http://example.com/foo?a=1'))
259
259
  mock.method('http://example.com/foo?a=1&b=2')
260
260
  end
261
- assert_passed(test_result)
262
- end
263
-
264
- def test_should_not_match_parameter_that_does_not_have_the_same_query_parameters
265
- test_result = run_as_test do
266
- mock = mock()
267
- mock.expects(:method).with(has_equivalent_query_string('http://example.com/foo?a=1'))
268
- mock.method('http://example.com/foo?a=1&b=2')
269
- end
270
- assert_failed(test_result)
271
- end
272
-
273
- def test_should_not_match_parameter_that_has_no_query_parameters_when_they_are_expected
274
- test_result = run_as_test do
275
- mock = mock()
276
- mock.expects(:method).with(has_equivalent_query_string('http://example.com/foo'))
277
- mock.method('http://example.com/foo?a=1&b=2')
278
- end
279
- assert_failed(test_result)
280
- end
281
-
282
- def test_should_not_match_parameter_that_has_the_same_query_string_bit_which_differs_otherwise
283
- test_result = run_as_test do
284
- mock = mock()
285
- mock.expects(:method).with(has_equivalent_query_string('http://a.example.com/foo?a=1&b=2'))
286
- mock.method('http://b.example.com/foo?a=1&b=2')
287
- end
288
261
  assert_failed(test_result)
289
262
  end
290
263
 
291
- def test_should_match_parameter_with_no_domain_or_scheme
292
- test_result = run_as_test do
293
- mock = mock()
294
- mock.expects(:method).with(has_equivalent_query_string('/foo?a=1&b=2'))
295
- mock.method('/foo?a=1&b=2')
296
- end
297
- assert_passed(test_result)
298
- end
299
-
300
264
  def test_should_match_parameter_when_value_is_divisible_by_four
301
265
  test_result = run_as_test do
302
266
  mock = mock()
@@ -148,7 +148,7 @@ class SequenceTest < Mocha::TestCase
148
148
  mock.first
149
149
  end
150
150
  assert_failed(test_result)
151
- assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message
151
+ assert_match Regexp.new(%{in sequence "one"}), test_result.failures.first.message
152
152
  end
153
153
 
154
154
  def test_should_allow_expectations_to_be_in_more_than_one_sequence
@@ -166,8 +166,8 @@ class SequenceTest < Mocha::TestCase
166
166
  mock.second
167
167
  end
168
168
  assert_failed(test_result)
169
- assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message
170
- assert_match Regexp.new("in sequence 'two'"), test_result.failures.first.message
169
+ assert_match Regexp.new(%{in sequence "one"}), test_result.failures.first.message
170
+ assert_match Regexp.new(%{in sequence "two"}), test_result.failures.first.message
171
171
  end
172
172
 
173
173
  def test_should_have_shortcut_for_expectations_to_be_in_more_than_one_sequence
@@ -185,8 +185,8 @@ class SequenceTest < Mocha::TestCase
185
185
  mock.second
186
186
  end
187
187
  assert_failed(test_result)
188
- assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message
189
- assert_match Regexp.new("in sequence 'two'"), test_result.failures.first.message
188
+ assert_match Regexp.new(%{in sequence "one"}), test_result.failures.first.message
189
+ assert_match Regexp.new(%{in sequence "two"}), test_result.failures.first.message
190
190
  end
191
191
 
192
192
  end
@@ -14,7 +14,11 @@ class StubModuleMethodTest < Mocha::TestCase
14
14
  end
15
15
 
16
16
  def test_should_stub_method_within_test
17
- mod = Module.new { def self.my_module_method; :original_return_value; end }
17
+ mod = Module.new do
18
+ def self.my_module_method
19
+ :original_return_value
20
+ end
21
+ end
18
22
  test_result = run_as_test do
19
23
  mod.stubs(:my_module_method).returns(:new_return_value)
20
24
  assert_equal :new_return_value, mod.my_module_method
@@ -23,7 +27,14 @@ class StubModuleMethodTest < Mocha::TestCase
23
27
  end
24
28
 
25
29
  def test_should_leave_stubbed_public_method_unchanged_after_test
26
- mod = Module.new { class << self; def my_module_method; :original_return_value; end; public :my_module_method; end }
30
+ mod = Module.new do
31
+ class << self
32
+ def my_module_method
33
+ :original_return_value
34
+ end
35
+ public :my_module_method
36
+ end
37
+ end
27
38
  run_as_test do
28
39
  mod.stubs(:my_module_method).returns(:new_return_value)
29
40
  end
@@ -32,7 +43,17 @@ class StubModuleMethodTest < Mocha::TestCase
32
43
  end
33
44
 
34
45
  def test_should_leave_stubbed_protected_method_unchanged_after_test
35
- mod = Module.new { class << self; def my_module_method; :original_return_value; end; protected :my_module_method; def my_unprotected_module_method; my_module_method; end; end }
46
+ mod = Module.new do
47
+ class << self
48
+ def my_module_method
49
+ :original_return_value
50
+ end
51
+ protected :my_module_method
52
+ def my_unprotected_module_method
53
+ my_module_method
54
+ end
55
+ end
56
+ end
36
57
  run_as_test do
37
58
  mod.stubs(:my_module_method).returns(:new_return_value)
38
59
  end
@@ -41,7 +62,14 @@ class StubModuleMethodTest < Mocha::TestCase
41
62
  end
42
63
 
43
64
  def test_should_leave_stubbed_private_method_unchanged_after_test
44
- mod = Module.new { class << self; def my_module_method; :original_return_value; end; private :my_module_method; end }
65
+ mod = Module.new do
66
+ class << self
67
+ def my_module_method
68
+ :original_return_value
69
+ end
70
+ private :my_module_method
71
+ end
72
+ end
45
73
  run_as_test do
46
74
  mod.stubs(:my_module_method).returns(:new_return_value)
47
75
  end
@@ -50,7 +78,11 @@ class StubModuleMethodTest < Mocha::TestCase
50
78
  end
51
79
 
52
80
  def test_should_reset_expectations_after_test
53
- mod = Module.new { def self.my_module_method; :original_return_value; end }
81
+ mod = Module.new do
82
+ def self.my_module_method
83
+ :original_return_value
84
+ end
85
+ end
54
86
  run_as_test do
55
87
  mod.stubs(:my_module_method)
56
88
  end
@@ -58,8 +90,14 @@ class StubModuleMethodTest < Mocha::TestCase
58
90
  end
59
91
 
60
92
  def test_should_be_able_to_stub_a_superclass_method
61
- supermod = Module.new { def self.my_superclass_method; :original_return_value; end }
62
- mod = Module.new { include supermod }
93
+ supermod = Module.new do
94
+ def self.my_superclass_method
95
+ :original_return_value
96
+ end
97
+ end
98
+ mod = Module.new do
99
+ include supermod
100
+ end
63
101
  test_result = run_as_test do
64
102
  mod.stubs(:my_superclass_method).returns(:new_return_value)
65
103
  assert_equal :new_return_value, mod.my_superclass_method
@@ -16,7 +16,10 @@ class StubbaTestResultTest < Mocha::TestCase
16
16
 
17
17
  def test_should_include_expectation_verification_in_assertion_count
18
18
  test_result = run_as_test do
19
- object = Class.new { def message; end }.new
19
+ object = Class.new do
20
+ def message
21
+ end
22
+ end.new
20
23
  object.expects(:message)
21
24
  object.message
22
25
  end
@@ -32,7 +35,10 @@ class StubbaTestResultTest < Mocha::TestCase
32
35
 
33
36
  def test_should_not_include_stubbing_expectation_verification_in_assertion_count
34
37
  test_result = run_as_test do
35
- object = Class.new { def message; end }.new
38
+ object = Class.new do
39
+ def message
40
+ end
41
+ end.new
36
42
  object.stubs(:message)
37
43
  object.message
38
44
  end
@@ -41,7 +47,10 @@ class StubbaTestResultTest < Mocha::TestCase
41
47
 
42
48
  def test_should_include_expectation_verification_failure_in_failure_count
43
49
  test_result = run_as_test do
44
- object = Class.new { def message; end }.new
50
+ object = Class.new do
51
+ def message
52
+ end
53
+ end.new
45
54
  object.expects(:message)
46
55
  end
47
56
  assert_equal 1, test_result.failure_count
@@ -15,7 +15,10 @@ class StubbingOnNonMockObjectTest < Mocha::TestCase
15
15
 
16
16
  def test_should_allow_stubbing_method_on_non_mock_object
17
17
  Mocha::Configuration.allow(:stubbing_method_on_non_mock_object)
18
- non_mock_object = Class.new { def existing_method; end }
18
+ non_mock_object = Class.new do
19
+ def existing_method
20
+ end
21
+ end
19
22
  test_result = run_as_test do
20
23
  non_mock_object.stubs(:existing_method)
21
24
  end
@@ -25,7 +28,10 @@ class StubbingOnNonMockObjectTest < Mocha::TestCase
25
28
 
26
29
  def test_should_warn_on_stubbing_method_on_non_mock_object
27
30
  Mocha::Configuration.warn_when(:stubbing_method_on_non_mock_object)
28
- non_mock_object = Class.new { def existing_method; end }
31
+ non_mock_object = Class.new do
32
+ def existing_method
33
+ end
34
+ end
29
35
  test_result = run_as_test do
30
36
  non_mock_object.stubs(:existing_method)
31
37
  end
@@ -35,7 +41,10 @@ class StubbingOnNonMockObjectTest < Mocha::TestCase
35
41
 
36
42
  def test_should_prevent_stubbing_method_on_non_mock_object
37
43
  Mocha::Configuration.prevent(:stubbing_method_on_non_mock_object)
38
- non_mock_object = Class.new { def existing_method; end }
44
+ non_mock_object = Class.new do
45
+ def existing_method
46
+ end
47
+ end
39
48
  test_result = run_as_test do
40
49
  non_mock_object.stubs(:existing_method)
41
50
  end
@@ -44,7 +53,10 @@ class StubbingOnNonMockObjectTest < Mocha::TestCase
44
53
  end
45
54
 
46
55
  def test_should_default_to_allow_stubbing_method_on_non_mock_object
47
- non_mock_object = Class.new { def existing_method; end }
56
+ non_mock_object = Class.new do
57
+ def existing_method
58
+ end
59
+ end
48
60
  test_result = run_as_test do
49
61
  non_mock_object.stubs(:existing_method)
50
62
  end
@@ -12,4 +12,5 @@ module DeprecationDisabler
12
12
  end
13
13
  end
14
14
 
15
+ module_function :disable_deprecations
15
16
  end
@@ -10,14 +10,16 @@ class ExecutionPoint
10
10
  @backtrace = backtrace
11
11
  end
12
12
 
13
+ def first_relevant_line_of_backtrace
14
+ @backtrace && (@backtrace.reject { |l| /\Aorg\/jruby\//.match(l) }.first || 'unknown:0')
15
+ end
16
+
13
17
  def file_name
14
- return "unknown" unless @backtrace && @backtrace.first
15
- /\A(.*?):\d+/.match(@backtrace.first)[1]
18
+ /\A(.*?):\d+/.match(first_relevant_line_of_backtrace)[1]
16
19
  end
17
20
 
18
21
  def line_number
19
- return "unknown" unless @backtrace && @backtrace.first
20
- Integer(/\A.*?:(\d+)/.match(@backtrace.first)[1])
22
+ Integer(/\A.*?:(\d+)/.match(first_relevant_line_of_backtrace)[1])
21
23
  end
22
24
 
23
25
  def ==(other)
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
- require "mocha/mini_test"
3
+ require "mocha/minitest"
4
4
  require "integration/shared_tests"
5
5
 
6
6
  class MiniTestTest < Mocha::TestCase
@@ -76,6 +76,7 @@ end
76
76
  klass.define_instance_method(:any_instance) { any_instance }
77
77
  method = AnyInstanceMethod.new(klass, :method_x)
78
78
  method.replace_instance_method(:restore_original_method) { }
79
+ method.replace_instance_method(:reset_mocha) { }
79
80
  method.define_instance_accessor(:remove_called)
80
81
  method.replace_instance_method(:remove_new_method) { self.remove_called = true }
81
82
 
@@ -92,6 +93,7 @@ end
92
93
  klass.define_instance_method(:any_instance) { any_instance }
93
94
  method = AnyInstanceMethod.new(klass, :method_x)
94
95
  method.replace_instance_method(:remove_new_method) { }
96
+ method.replace_instance_method(:reset_mocha) { }
95
97
  method.define_instance_accessor(:restore_called)
96
98
  method.replace_instance_method(:restore_original_method) { self.restore_called = true }
97
99
 
@@ -10,7 +10,7 @@ class ArrayInspectTest < Mocha::TestCase
10
10
 
11
11
  def test_should_use_mocha_inspect_on_each_item
12
12
  array = [1, 2, "chris"]
13
- assert_equal "[1, 2, 'chris']", array.mocha_inspect
13
+ assert_equal %{[1, 2, "chris"]}, array.mocha_inspect
14
14
  end
15
15
 
16
16
  end
@@ -11,6 +11,7 @@ class ClassMethodTest < Mocha::TestCase
11
11
  unless RUBY_V2_PLUS
12
12
  def test_should_hide_original_method
13
13
  klass = Class.new { def self.method_x; end }
14
+ klass.__metaclass__.send(:alias_method, :_method, :method)
14
15
  method = ClassMethod.new(klass, :method_x)
15
16
 
16
17
  method.hide_original_method
@@ -59,6 +60,7 @@ end
59
60
 
60
61
  def test_should_restore_original_method
61
62
  klass = Class.new { def self.method_x; :original_result; end }
63
+ klass.__metaclass__.send(:alias_method, :_method, :method)
62
64
  method = ClassMethod.new(klass, :method_x)
63
65
 
64
66
  method.hide_original_method
@@ -72,6 +74,7 @@ end
72
74
 
73
75
  def test_should_restore_original_method_accepting_a_block_parameter
74
76
  klass = Class.new { def self.method_x(&block); block.call if block_given? ; end }
77
+ klass.__metaclass__.send(:alias_method, :_method, :method)
75
78
  method = ClassMethod.new(klass, :method_x)
76
79
 
77
80
  method.hide_original_method
@@ -121,6 +124,7 @@ end
121
124
  method = ClassMethod.new(klass, :method_x)
122
125
  mocha = build_mock
123
126
  klass.define_instance_method(:mocha) { mocha }
127
+ method.replace_instance_method(:reset_mocha) { }
124
128
  method.define_instance_accessor(:remove_called)
125
129
  method.replace_instance_method(:remove_new_method) { self.remove_called = true }
126
130
 
@@ -134,6 +138,7 @@ end
134
138
  mocha = build_mock
135
139
  klass.define_instance_method(:mocha) { mocha }
136
140
  method = ClassMethod.new(klass, :method_x)
141
+ method.replace_instance_method(:reset_mocha) { }
137
142
  method.define_instance_accessor(:restore_called)
138
143
  method.replace_instance_method(:restore_original_method) { self.restore_called = true }
139
144
 
@@ -174,10 +179,9 @@ end
174
179
  def test_should_return_mock_for_stubbee
175
180
  mocha = Object.new
176
181
  stubbee = Object.new
177
- stubbee.define_instance_accessor(:mocha) { mocha }
178
- stubbee.mocha = nil
182
+ stubbee.define_instance_method(:mocha) { mocha }
179
183
  method = ClassMethod.new(stubbee, :method_name)
180
- assert_equal stubbee.mocha, method.mock
184
+ assert_equal mocha, method.mock
181
185
  end
182
186
 
183
187
  def test_should_not_match_if_other_object_has_a_different_class
@@ -343,7 +343,7 @@ class ExpectationTest < Mocha::TestCase
343
343
  sequence_two = Sequence.new('two')
344
344
  expectation = Expectation.new(mock, :expected_method).with(1, 2, {'a' => true}, {:b => false}, [1, 2, 3]).in_sequence(sequence_one, sequence_two)
345
345
  assert !expectation.verified?
346
- assert_match "mock.expected_method(1, 2, {'a' => true}, {:b => false}, [1, 2, 3]); in sequence 'one'; in sequence 'two'", expectation.mocha_inspect
346
+ assert_match %{mock.expected_method(1, 2, {"a" => true}, {:b => false}, [1, 2, 3]); in sequence "one"; in sequence "two"}, expectation.mocha_inspect
347
347
  end
348
348
 
349
349
  class FakeConstraint
@@ -10,7 +10,7 @@ class HashInspectTest < Mocha::TestCase
10
10
 
11
11
  def test_should_use_mocha_inspect_on_each_item
12
12
  hash = {:a => 'mocha'}
13
- assert_equal "{:a => 'mocha'}", hash.mocha_inspect
13
+ assert_equal %{{:a => "mocha"}}, hash.mocha_inspect
14
14
  end
15
15
 
16
16
  end
@@ -334,6 +334,14 @@ class MockTest < Mocha::TestCase
334
334
  assert_match(/unexpected invocation/, e.message)
335
335
  end
336
336
 
337
+ unless PRE_RUBY_V19
338
+ def test_expectation_is_defined_on_mock
339
+ mock = build_mock
340
+ mock.expects(:method1)
341
+ assert defined? mock.method1
342
+ end
343
+ end
344
+
337
345
  private
338
346
 
339
347
  def build_mock
@@ -2,10 +2,12 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
  require 'mocha/mockery'
3
3
  require 'mocha/state_machine'
4
4
  require 'mocha/expectation_error_factory'
5
+ require 'deprecation_disabler'
5
6
 
6
7
  class MockeryTest < Mocha::TestCase
7
8
 
8
9
  include Mocha
10
+ include DeprecationDisabler
9
11
 
10
12
  def test_should_build_instance_of_mockery
11
13
  mockery = Mockery.instance
@@ -28,16 +30,20 @@ class MockeryTest < Mocha::TestCase
28
30
 
29
31
  def test_should_raise_expectation_error_because_not_all_expectations_are_satisfied
30
32
  mockery = Mockery.new
31
- mock_1 = mockery.named_mock('mock-1') { expects(:method_1) }
32
- mock_2 = mockery.named_mock('mock-2') { expects(:method_2) }
33
- 1.times { mock_1.method_1 }
34
- 0.times { mock_2.method_2 }
33
+ disable_deprecations do
34
+ mock_1 = mockery.named_mock('mock-1') { expects(:method_1) }
35
+ mock_2 = mockery.named_mock('mock-2') { expects(:method_2) }
36
+ 1.times { mock_1.method_1 }
37
+ 0.times { mock_2.method_2 }
38
+ end
35
39
  assert_raises(ExpectationErrorFactory.exception_class) { mockery.verify }
36
40
  end
37
41
 
38
42
  def test_should_reset_list_of_mocks_on_teardown
39
43
  mockery = Mockery.new
40
- mockery.unnamed_mock { expects(:my_method) }
44
+ disable_deprecations do
45
+ mockery.unnamed_mock { expects(:my_method) }
46
+ end
41
47
  mockery.teardown
42
48
  assert_nothing_raised(ExpectationErrorFactory.exception_class) { mockery.verify }
43
49
  end
@@ -19,7 +19,7 @@ class EqualsTest < Mocha::TestCase
19
19
 
20
20
  def test_should_describe_matcher
21
21
  matcher = equals('x')
22
- assert_equal "'x'", matcher.mocha_inspect
22
+ assert_equal %{"x"}, matcher.mocha_inspect
23
23
  end
24
24
 
25
25
  end
@@ -0,0 +1,51 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+ require 'deprecation_disabler'
3
+ require 'mocha/parameter_matchers/equivalent_uri'
4
+
5
+ class EquivalentUriMatchesTest < Mocha::TestCase
6
+
7
+ include Mocha::ParameterMatchers
8
+ include DeprecationDisabler
9
+
10
+ def test_should_match_identical_uri
11
+ matcher = equivalent_uri('http://example.com/foo?a=1&b=2')
12
+ assert matcher.matches?(['http://example.com/foo?a=1&b=2'])
13
+ end
14
+
15
+ def test_should_support_legacy_matcher_method
16
+ disable_deprecations do
17
+ matcher = has_equivalent_query_string('http://example.com/foo?a=1&b=2')
18
+ assert matcher.matches?(['http://example.com/foo?a=1&b=2'])
19
+ end
20
+ end
21
+
22
+ def test_should_match_uri_with_rearranged_query_string
23
+ matcher = equivalent_uri('http://example.com/foo?b=2&a=1')
24
+ assert matcher.matches?(['http://example.com/foo?a=1&b=2'])
25
+ end
26
+
27
+ def test_should_not_match_uri_with_different_query_string
28
+ matcher = equivalent_uri('http://example.com/foo?a=1')
29
+ assert !matcher.matches?(['http://example.com/foo?a=1&b=2'])
30
+ end
31
+
32
+ def test_should_not_match_uri_when_no_query_string_expected
33
+ matcher = equivalent_uri('http://example.com/foo')
34
+ assert !matcher.matches?(['http://example.com/foo?a=1&b=2'])
35
+ end
36
+
37
+ def test_should_not_match_uri_with_different_domain
38
+ matcher = equivalent_uri('http://a.example.com/foo?a=1&b=2')
39
+ assert !matcher.matches?(['http://b.example.com/foo?a=1&b=2'])
40
+ end
41
+
42
+ def test_should_match_uri_without_scheme_and_domain
43
+ matcher = equivalent_uri('/foo?a=1&b=2')
44
+ assert matcher.matches?(['/foo?a=1&b=2'])
45
+ end
46
+
47
+ def test_should_match_uri_with_query_string_containing_blank_value
48
+ matcher = equivalent_uri('http://example.com/foo?a=&b=2')
49
+ assert matcher.matches?(['http://example.com/foo?a=&b=2'])
50
+ end
51
+ end
@@ -31,12 +31,12 @@ class HasEntryTest < Mocha::TestCase
31
31
 
32
32
  def test_should_describe_matcher_with_key_value_pair
33
33
  matcher = has_entry(:key_1, 'value_1')
34
- assert_equal "has_entry(:key_1 => 'value_1')", matcher.mocha_inspect
34
+ assert_equal %{has_entry(:key_1 => "value_1")}, matcher.mocha_inspect
35
35
  end
36
36
 
37
37
  def test_should_describe_matcher_with_entry
38
38
  matcher = has_entry(:key_1 => 'value_1')
39
- assert_equal "has_entry(:key_1 => 'value_1')", matcher.mocha_inspect
39
+ assert_equal %{has_entry(:key_1 => "value_1")}, matcher.mocha_inspect
40
40
  end
41
41
 
42
42
  def test_should_match_hash_including_specified_entry_with_nested_key_matcher
@@ -21,7 +21,7 @@ class HasValueTest < Mocha::TestCase
21
21
 
22
22
  def test_should_describe_matcher
23
23
  matcher = has_value('value_1')
24
- assert_equal "has_value('value_1')", matcher.mocha_inspect
24
+ assert_equal %{has_value("value_1")}, matcher.mocha_inspect
25
25
  end
26
26
 
27
27
  def test_should_match_hash_including_specified_value_with_nested_value_matcher
@@ -15,6 +15,11 @@ class IncludesTest < Mocha::TestCase
15
15
  assert matcher.matches?([[:x, :y, :z]])
16
16
  end
17
17
 
18
+ def test_should_match_object_including_array_value
19
+ matcher = includes([:x])
20
+ assert matcher.matches?([[[:x], [:y], [:z]]])
21
+ end
22
+
18
23
  def test_should_match_object_including_all_values
19
24
  matcher = includes(:x, :y, :z)
20
25
  assert matcher.matches?([[:x, :y, :z]])
@@ -98,7 +98,7 @@ class SequenceTest < Mocha::TestCase
98
98
  sequence = Sequence.new('wibble')
99
99
  expectation = FakeExpectation.new
100
100
  sequence.constrain_as_next_in_sequence(expectation)
101
- assert_equal "in sequence 'wibble'", expectation.ordering_constraints[0].mocha_inspect
101
+ assert_equal %{in sequence "wibble"}, expectation.ordering_constraints[0].mocha_inspect
102
102
  end
103
103
 
104
104
  end
@@ -3,9 +3,9 @@ require 'mocha/inspect'
3
3
 
4
4
  class StringInspectTest < Mocha::TestCase
5
5
 
6
- def test_should_replace_escaped_quotes_with_single_quote
6
+ def test_should_use_default_inspect_method
7
7
  string = "my_string"
8
- assert_equal "'my_string'", string.mocha_inspect
8
+ assert_equal %{"my_string"}, string.mocha_inspect
9
9
  end
10
10
 
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocha
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mead
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-15 00:00:00.000000000 Z
11
+ date: 2018-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metaclass
@@ -179,6 +179,7 @@ files:
179
179
  - lib/mocha/logger.rb
180
180
  - lib/mocha/method_matcher.rb
181
181
  - lib/mocha/mini_test.rb
182
+ - lib/mocha/minitest.rb
182
183
  - lib/mocha/mock.rb
183
184
  - lib/mocha/mockery.rb
184
185
  - lib/mocha/module_method.rb
@@ -194,6 +195,7 @@ files:
194
195
  - lib/mocha/parameter_matchers/anything.rb
195
196
  - lib/mocha/parameter_matchers/base.rb
196
197
  - lib/mocha/parameter_matchers/equals.rb
198
+ - lib/mocha/parameter_matchers/equivalent_uri.rb
197
199
  - lib/mocha/parameter_matchers/has_entries.rb
198
200
  - lib/mocha/parameter_matchers/has_entry.rb
199
201
  - lib/mocha/parameter_matchers/has_key.rb
@@ -205,7 +207,6 @@ files:
205
207
  - lib/mocha/parameter_matchers/not.rb
206
208
  - lib/mocha/parameter_matchers/object.rb
207
209
  - lib/mocha/parameter_matchers/optionally.rb
208
- - lib/mocha/parameter_matchers/query_string.rb
209
210
  - lib/mocha/parameter_matchers/regexp_matches.rb
210
211
  - lib/mocha/parameter_matchers/responds_with.rb
211
212
  - lib/mocha/parameter_matchers/yaml_equivalent.rb
@@ -330,6 +331,7 @@ files:
330
331
  - test/unit/parameter_matchers/any_of_test.rb
331
332
  - test/unit/parameter_matchers/anything_test.rb
332
333
  - test/unit/parameter_matchers/equals_test.rb
334
+ - test/unit/parameter_matchers/equivalent_uri_test.rb
333
335
  - test/unit/parameter_matchers/has_entries_test.rb
334
336
  - test/unit/parameter_matchers/has_entry_test.rb
335
337
  - test/unit/parameter_matchers/has_key_test.rb
@@ -368,7 +370,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
368
370
  requirements:
369
371
  - - ">="
370
372
  - !ruby/object:Gem::Version
371
- version: '0'
373
+ version: 1.8.7
372
374
  required_rubygems_version: !ruby/object:Gem::Requirement
373
375
  requirements:
374
376
  - - ">="
@@ -376,7 +378,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
376
378
  version: '0'
377
379
  requirements: []
378
380
  rubyforge_project: mocha
379
- rubygems_version: 2.5.1
381
+ rubygems_version: 2.6.11
380
382
  signing_key:
381
383
  specification_version: 3
382
384
  summary: Mocking and stubbing library