mocha 1.11.1 → 1.11.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/RELEASE.md +14 -0
  3. data/docs/Mocha.html +2 -2
  4. data/docs/Mocha/API.html +16 -18
  5. data/docs/Mocha/ClassMethods.html +2 -2
  6. data/docs/Mocha/Configuration.html +2 -2
  7. data/docs/Mocha/Expectation.html +2 -2
  8. data/docs/Mocha/ExpectationError.html +2 -2
  9. data/docs/Mocha/ExpectationErrorFactory.html +2 -2
  10. data/docs/Mocha/Hooks.html +2 -2
  11. data/docs/Mocha/Integration.html +2 -2
  12. data/docs/Mocha/Integration/MiniTest.html +2 -2
  13. data/docs/Mocha/Integration/MiniTest/Adapter.html +2 -2
  14. data/docs/Mocha/Integration/TestUnit.html +2 -2
  15. data/docs/Mocha/Integration/TestUnit/Adapter.html +2 -2
  16. data/docs/Mocha/Mock.html +12 -39
  17. data/docs/Mocha/ObjectMethods.html +2 -2
  18. data/docs/Mocha/ParameterMatchers.html +14 -26
  19. data/docs/Mocha/ParameterMatchers/AllOf.html +2 -2
  20. data/docs/Mocha/ParameterMatchers/AnyOf.html +2 -2
  21. data/docs/Mocha/ParameterMatchers/AnyParameters.html +2 -2
  22. data/docs/Mocha/ParameterMatchers/Anything.html +2 -2
  23. data/docs/Mocha/ParameterMatchers/Base.html +2 -2
  24. data/docs/Mocha/ParameterMatchers/Equals.html +2 -2
  25. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +2 -2
  26. data/docs/Mocha/ParameterMatchers/HasEntries.html +2 -2
  27. data/docs/Mocha/ParameterMatchers/HasEntry.html +2 -2
  28. data/docs/Mocha/ParameterMatchers/HasKey.html +2 -2
  29. data/docs/Mocha/ParameterMatchers/HasValue.html +2 -2
  30. data/docs/Mocha/ParameterMatchers/Includes.html +2 -2
  31. data/docs/Mocha/ParameterMatchers/InstanceOf.html +2 -2
  32. data/docs/Mocha/ParameterMatchers/IsA.html +2 -2
  33. data/docs/Mocha/ParameterMatchers/KindOf.html +2 -2
  34. data/docs/Mocha/ParameterMatchers/Not.html +2 -2
  35. data/docs/Mocha/ParameterMatchers/Optionally.html +2 -2
  36. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +2 -2
  37. data/docs/Mocha/ParameterMatchers/RespondsWith.html +2 -2
  38. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +2 -2
  39. data/docs/Mocha/Sequence.html +2 -2
  40. data/docs/Mocha/StateMachine.html +5 -5
  41. data/docs/Mocha/StateMachine/State.html +2 -2
  42. data/docs/Mocha/StateMachine/StatePredicate.html +2 -2
  43. data/docs/Mocha/StubbingError.html +2 -2
  44. data/docs/_index.html +3 -3
  45. data/docs/file.COPYING.html +2 -2
  46. data/docs/file.MIT-LICENSE.html +2 -2
  47. data/docs/file.README.html +2 -2
  48. data/docs/file.RELEASE.html +20 -2
  49. data/docs/frames.html +1 -1
  50. data/docs/index.html +2 -2
  51. data/docs/top-level-namespace.html +2 -2
  52. data/lib/mocha/api.rb +2 -3
  53. data/lib/mocha/mock.rb +40 -14
  54. data/lib/mocha/mockery.rb +10 -7
  55. data/lib/mocha/parameter_matchers/has_entries.rb +2 -3
  56. data/lib/mocha/parameter_matchers/has_entry.rb +2 -3
  57. data/lib/mocha/parameter_matchers/has_key.rb +2 -3
  58. data/lib/mocha/parameter_matchers/has_value.rb +2 -3
  59. data/lib/mocha/parameter_matchers/is_a.rb +2 -3
  60. data/lib/mocha/parameter_matchers/not.rb +2 -3
  61. data/lib/mocha/state_machine.rb +2 -3
  62. data/lib/mocha/stubbed_method.rb +4 -6
  63. data/lib/mocha/version.rb +1 -1
  64. data/test/acceptance/issue_457_test.rb +31 -0
  65. data/test/acceptance/mocha_example_test.rb +11 -1
  66. data/test/acceptance/mock_test.rb +36 -0
  67. data/test/acceptance/stubba_example_test.rb +11 -1
  68. metadata +3 -3
  69. data/lib/mocha/pretty_parameters.rb +0 -24
@@ -22,11 +22,10 @@ module Mocha
22
22
  # object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2))
23
23
  # object.method_1('key_1' => 1, 'key_2' => 99)
24
24
  # # error raised, because method_1 was not called with Hash containing entries: 'key_1' => 1, 'key_2' => 2
25
- # rubocop:disable Naming/PredicateName
26
- def has_entries(entries)
25
+ #
26
+ def has_entries(entries) # rubocop:disable Naming/PredicateName
27
27
  HasEntries.new(entries)
28
28
  end
29
- # rubocop:enable Naming/PredicateName
30
29
 
31
30
  # Parameter matcher which matches when actual parameter contains all expected +Hash+ entries.
32
31
  class HasEntries < Base
@@ -39,8 +39,8 @@ module Mocha
39
39
  # object.expects(:method_1).with(has_entry('key_1' => 1))
40
40
  # object.method_1('key_1' => 2, 'key_2' => 1)
41
41
  # # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1
42
- # rubocop:disable Naming/PredicateName
43
- def has_entry(*options)
42
+ #
43
+ def has_entry(*options) # rubocop:disable Naming/PredicateName
44
44
  case options.length
45
45
  when 1
46
46
  case options[0]
@@ -63,7 +63,6 @@ module Mocha
63
63
  end
64
64
  HasEntry.new(key, value)
65
65
  end
66
- # rubocop:enable Naming/PredicateName
67
66
 
68
67
  # Parameter matcher which matches when actual parameter contains expected +Hash+ entry.
69
68
  class HasEntry < Base
@@ -20,11 +20,10 @@ module Mocha
20
20
  # object.expects(:method_1).with(has_key('key_1'))
21
21
  # object.method_1('key_2' => 2)
22
22
  # # error raised, because method_1 was not called with Hash containing key: 'key_1'
23
- # rubocop:disable Naming/PredicateName
24
- def has_key(key)
23
+ #
24
+ def has_key(key) # rubocop:disable Naming/PredicateName
25
25
  HasKey.new(key)
26
26
  end
27
- # rubocop:enable Naming/PredicateName
28
27
 
29
28
  # Parameter matcher which matches when actual parameter contains +Hash+ entry with expected key.
30
29
  class HasKey < Base
@@ -20,11 +20,10 @@ module Mocha
20
20
  # object.expects(:method_1).with(has_value(1))
21
21
  # object.method_1('key_2' => 2)
22
22
  # # error raised, because method_1 was not called with Hash containing value: 1
23
- # rubocop:disable Naming/PredicateName
24
- def has_value(value)
23
+ #
24
+ def has_value(value) # rubocop:disable Naming/PredicateName
25
25
  HasValue.new(value)
26
26
  end
27
- # rubocop:enable Naming/PredicateName
28
27
 
29
28
  # Parameter matcher which matches when actual parameter contains +Hash+ entry with expected value.
30
29
  class HasValue < Base
@@ -21,11 +21,10 @@ module Mocha
21
21
  # object.expects(:method_1).with(is_a(Integer))
22
22
  # object.method_1('string')
23
23
  # # error raised, because method_1 was not called with an Integer
24
- # rubocop:disable Naming/PredicateName
25
- def is_a(klass)
24
+ #
25
+ def is_a(klass) # rubocop:disable Naming/PredicateName
26
26
  IsA.new(klass)
27
27
  end
28
- # rubocop:enable Naming/PredicateName
29
28
 
30
29
  # Parameter matcher which matches when actual parameter is a specific class.
31
30
  class IsA < Base
@@ -20,11 +20,10 @@ module Mocha
20
20
  # object.expects(:method_1).with(Not(includes(1)))
21
21
  # object.method_1([0, 1, 2, 3])
22
22
  # # error raised, because method_1 was not called with object not including 1
23
- # rubocop:disable Naming/MethodName
24
- def Not(matcher)
23
+ #
24
+ def Not(matcher) # rubocop:disable Naming/MethodName
25
25
  Not.new(matcher)
26
26
  end
27
- # rubocop:enable Naming/MethodName
28
27
 
29
28
  # Parameter matcher which inverts the logic of the specified matcher using a logical NOT operation.
30
29
  class Not < Base
@@ -84,11 +84,10 @@ module Mocha
84
84
  end
85
85
 
86
86
  # Provides a mechanism to determine whether the {StateMachine} is not in the state specified by +state_name+ at some point in the future.
87
- # rubocop:disable Naming/PredicateName
88
- def is_not(state_name)
87
+ #
88
+ def is_not(state_name) # rubocop:disable Naming/PredicateName
89
89
  StatePredicate.new(self, state_name)
90
90
  end
91
- # rubocop:enable Naming/PredicateName
92
91
 
93
92
  # @private
94
93
  def mocha_inspect
@@ -74,7 +74,7 @@ module Mocha
74
74
  def restore_original_method
75
75
  return if use_prepended_module_for_stub_method?
76
76
  if stub_method_overwrites_original_method?
77
- original_method_owner.send(:define_method, method_name, method_body(original_method))
77
+ original_method_owner.send(:define_method, method_name, method_body(@original_method))
78
78
  end
79
79
  retain_original_visibility(original_method_owner)
80
80
  end
@@ -93,18 +93,16 @@ module Mocha
93
93
  private
94
94
 
95
95
  def retain_original_visibility(method_owner)
96
- return unless original_visibility
97
- Module.instance_method(original_visibility).bind(method_owner).call(method_name)
96
+ return unless @original_visibility
97
+ Module.instance_method(@original_visibility).bind(method_owner).call(method_name)
98
98
  end
99
99
 
100
- attr_reader :original_method, :original_visibility
101
-
102
100
  def store_original_method_visibility
103
101
  @original_visibility = original_method_owner.__method_visibility__(method_name)
104
102
  end
105
103
 
106
104
  def stub_method_overwrites_original_method?
107
- original_method && original_method.owner == original_method_owner
105
+ @original_method && @original_method.owner == original_method_owner
108
106
  end
109
107
 
110
108
  def remove_original_method_from_stubbee
@@ -1,3 +1,3 @@
1
1
  module Mocha
2
- VERSION = '1.11.1'.freeze
2
+ VERSION = '1.11.2'.freeze
3
3
  end
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
+
3
+ class Issue457Test < Mocha::TestCase
4
+ include AcceptanceTest
5
+
6
+ def setup
7
+ setup_acceptance_test
8
+ end
9
+
10
+ def teardown
11
+ teardown_acceptance_test
12
+ end
13
+
14
+ def test_only_inspect_objects_when_necessary
15
+ test_result = run_as_test do
16
+ klass = Class.new do
17
+ def message
18
+ raise 'Not inspectable in this state!'
19
+ end
20
+
21
+ def inspect
22
+ message
23
+ end
24
+ end
25
+ instance = klass.new
26
+ instance.stubs(:message).returns('message')
27
+ assert_equal 'message', instance.inspect
28
+ end
29
+ assert_passed(test_result)
30
+ end
31
+ end
@@ -1,6 +1,16 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
 
3
3
  class MochaExampleTest < Mocha::TestCase
4
+ include AcceptanceTest
5
+
6
+ def setup
7
+ setup_acceptance_test
8
+ end
9
+
10
+ def teardown
11
+ teardown_acceptance_test
12
+ end
13
+
4
14
  class Rover
5
15
  def initialize(left_track, right_track, steps_per_metre, steps_per_degree)
6
16
  @left_track = left_track
@@ -1,9 +1,11 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha/configuration'
3
+ require 'mocha/deprecation'
3
4
  require 'deprecation_disabler'
4
5
 
5
6
  class MockTest < Mocha::TestCase
6
7
  include AcceptanceTest
8
+ include Mocha
7
9
 
8
10
  def setup
9
11
  setup_acceptance_test
@@ -152,4 +154,38 @@ class MockTest < Mocha::TestCase
152
154
  end
153
155
  assert_failed(test_result)
154
156
  end
157
+
158
+ class Foo
159
+ class << self
160
+ attr_accessor :logger
161
+ end
162
+
163
+ def use_the_mock
164
+ self.class.logger.log('Foo was here')
165
+ end
166
+ end
167
+
168
+ # rubocop:disable Metrics/AbcSize
169
+ def test_should_display_deprecation_warning_if_mock_receives_invocations_in_another_test
170
+ use_mock_test_result = run_as_test do
171
+ Foo.logger = mock('Logger')
172
+ Foo.logger.expects(:log).with('Foo was here')
173
+ Foo.new.use_the_mock
174
+ end
175
+ assert_passed(use_mock_test_result)
176
+
177
+ reuse_mock_test_result = run_as_test do
178
+ DeprecationDisabler.disable_deprecations do
179
+ Foo.logger.expects(:log).with('Foo was here')
180
+ Foo.new.use_the_mock
181
+ end
182
+ end
183
+ assert_passed(reuse_mock_test_result)
184
+ assert message = Deprecation.messages.last
185
+ assert message.include?('#<Mock:Logger> was instantiated in one test but it is receiving invocations within another test.')
186
+ assert message.include?('This can lead to unintended interactions between tests and hence unexpected test failures.')
187
+ assert message.include?('Ensure that every test correctly cleans up any state that it introduces.')
188
+ assert message.include?('A Mocha::StubbingError will be raised in this scenario in the future.')
189
+ end
190
+ # rubocop:enable Metrics/AbcSize
155
191
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
 
3
3
  class Widget
4
4
  def model
@@ -23,6 +23,16 @@ module Thingy
23
23
  end
24
24
 
25
25
  class StubbaExampleTest < Mocha::TestCase
26
+ include AcceptanceTest
27
+
28
+ def setup
29
+ setup_acceptance_test
30
+ end
31
+
32
+ def teardown
33
+ teardown_acceptance_test
34
+ end
35
+
26
36
  def test_should_stub_instance_method
27
37
  widget = Widget.new
28
38
  widget.expects(:model).returns('different_model')
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.11.1
4
+ version: 1.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mead
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-17 00:00:00.000000000 Z
11
+ date: 2020-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -245,7 +245,6 @@ files:
245
245
  - lib/mocha/parameter_matchers/responds_with.rb
246
246
  - lib/mocha/parameter_matchers/yaml_equivalent.rb
247
247
  - lib/mocha/parameters_matcher.rb
248
- - lib/mocha/pretty_parameters.rb
249
248
  - lib/mocha/raised_exception.rb
250
249
  - lib/mocha/receivers.rb
251
250
  - lib/mocha/return_values.rb
@@ -273,6 +272,7 @@ files:
273
272
  - test/acceptance/expected_invocation_count_test.rb
274
273
  - test/acceptance/failure_messages_test.rb
275
274
  - test/acceptance/issue_272_test.rb
275
+ - test/acceptance/issue_457_test.rb
276
276
  - test/acceptance/issue_65_test.rb
277
277
  - test/acceptance/issue_70_test.rb
278
278
  - test/acceptance/mocha_example_test.rb
@@ -1,24 +0,0 @@
1
- require 'mocha/inspect'
2
-
3
- module Mocha
4
- class PrettyParameters
5
- def initialize(params)
6
- @params = params
7
- @params_string = params.mocha_inspect
8
- end
9
-
10
- def pretty
11
- remove_outer_array_braces!
12
- remove_outer_hash_braces!
13
- @params_string
14
- end
15
-
16
- def remove_outer_array_braces!
17
- @params_string = @params_string.gsub(/^\[|\]$/, '')
18
- end
19
-
20
- def remove_outer_hash_braces!
21
- @params_string = @params_string.gsub(/^\{|\}$/, '') if @params.length == 1
22
- end
23
- end
24
- end