mocha 2.0.0.alpha → 2.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69781697a086ec84aecb54fa1f63dff7842796caa275af3f01e82695e7187b0d
4
- data.tar.gz: f0aa6493ffccdeeb7f48b0aa8a329ba57612c4c01470642b0df8f23392857534
3
+ metadata.gz: 4f52376e6c8b1042085cca75e7d22e0241452dca80e73de22510f39a83041030
4
+ data.tar.gz: aa4584255d27f58ee1e9c18935921e352044ac8c2cc91d97221d280e21c54b29
5
5
  SHA512:
6
- metadata.gz: ddc7f9eab0a9506cc0e5a69ffc0bbc359d68c4e19f2c2cd207554d2b264854f77a38bed9fa7df6f0ac110b25cf26aaa9315ec092d709a0d2cdc8ec610c3cc2fc
7
- data.tar.gz: 7b20ce12545006706f32ff11863802dd31fe4c766925e7ca2bd63828f8dc78e98cb692d9bf5558e6ea6f401929be236c52183bc42ecfff05a752c002d9414c2c
6
+ metadata.gz: d23cc4f2cb0ffcf1464103c1bca607d8a2fac7fef3592dc4637d25ed72dbfd91f5d7234c9f4df23f1c27248829b6638013396e780212f41d9a44236b7a95bd16
7
+ data.tar.gz: efbcf261aab3292625c56f9f8cab796a19b4dc1ac474a64041ee1a6a92e72c4941b1ce0a0299322e682607d8e8c92598da7ffe853de1257cd92f49027b0891d4
data/.rubocop.yml CHANGED
@@ -48,6 +48,10 @@ Style/WhileUntilModifier:
48
48
  Style/AccessModifierDeclarations:
49
49
  Enabled: false
50
50
 
51
+ # This is useful when using `ExecutionPoint.current` to make tests more robust
52
+ Style/Semicolon:
53
+ Enabled: false
54
+
51
55
  # Enabling this cop results in an "Infinite loop detected" exception
52
56
  Layout/AccessModifierIndentation:
53
57
  Enabled: false
data/README.md CHANGED
@@ -302,6 +302,12 @@ See the [documentation](https://mocha.jamesmead.org/Mocha/Configuration.html) fo
302
302
  Only the following values are currently recognized and have an effect:
303
303
  * `debug`: Enables a debug mode which will output backtraces for each deprecation warning. This is useful for finding where in the test suite the deprecated calls are.
304
304
 
305
+ ### Semantic versioning
306
+
307
+ * Every effort is made to comply with [semantic versioning](https://semver.org/).
308
+ * However, this only applies to the behaviour documented in the public API.
309
+ * The documented public API does *not* include the content or format of messsages displayed to the user, e.g. assertion failure messages.
310
+
305
311
  ### Useful Links
306
312
 
307
313
  * [Official Documentation](https://mocha.jamesmead.org)
data/RELEASE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Release Notes
2
2
 
3
- ## 2.0.0.alpha
3
+ ## 2.0.0
4
4
 
5
5
  ### External changes
6
6
 
@@ -19,6 +19,8 @@ from the Ruby v1.8 standard library are no longer supported (#540,969f4845)
19
19
  * Expand `Expectation#with` docs re keyword arguments (fed6808d)
20
20
  * Improve docs for `strict_keyword_argument_matching` (8d8f881d)
21
21
  * Remove deprecated Rails plugin `init.rb` file (1c617175)
22
+ * Improve strict keyword argument matching deprecation warning by including the source location of the stub definition (77c0d4cc)
23
+ * Add README section re semantic versioning (00758246)
22
24
 
23
25
  ### Internal changes
24
26
 
@@ -31,6 +33,18 @@ from the Ruby v1.8 standard library are no longer supported (#540,969f4845)
31
33
  * More consistent Test::Unit & Minitest integration (27dd3817)
32
34
  * Remove redundant `require` statements (d82218a8,fa17b114)
33
35
  * Add missing `require` statement (73493761)
36
+ * Disable Style/Semicolon cop globally (8cd0b705)
37
+
38
+ ## 1.16.0
39
+
40
+ ### External changes
41
+
42
+ * Default `Configuration#reinstate_undocumented_behaviour_from_v1_9=` to `false` (6fcaf947)
43
+ * Deprecate `Configuration#reinstate_undocumented_behaviour_from_v1_9=` (a797c5fd)
44
+
45
+ ### Internal changes
46
+
47
+ * Remove redundant deprecation disabling in MockTest (dc8ca969)
34
48
 
35
49
  ## 1.15.0
36
50
 
@@ -252,11 +252,11 @@ module Mocha
252
252
 
253
253
  # Perform strict keyword argument comparison. Only supported in Ruby >= v2.7.
254
254
  #
255
- # When this option is set to +false+ a positional +Hash+ and a set of keyword arguments are treated the same during comparison, which can lead to false negatives in Ruby >= v3.0 (see examples below). However, a deprecation warning will be displayed if a positional +Hash+ matches a set of keyword arguments or vice versa. This is because {#strict_keyword_argument_matching=} will default to +true+ in the future.
255
+ # When this option is set to +false+ a positional +Hash+ and a set of keyword arguments are treated the same during comparison, which can lead to misleading passing tests in Ruby >= v3.0 (see examples below). However, a deprecation warning will be displayed if a positional +Hash+ matches a set of keyword arguments or vice versa. This is because {#strict_keyword_argument_matching=} will default to +true+ in the future.
256
256
  #
257
257
  # For more details on keyword arguments in Ruby v3, refer to {https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0 this article}.
258
258
  #
259
- # Note that +Hash+-related matchers such as {ParameterMatchers#has_value} or {ParameterMatchers#has_key} will still treat a positional +Hash+ and a set of keyword arguments the same, so false negatives are still possible when they are used.
259
+ # Note that +Hash+-related matchers such as {ParameterMatchers#has_value} or {ParameterMatchers#has_key} will still treat a positional +Hash+ and a set of keyword arguments the same, so misleading passing tests are still possible when they are used.
260
260
  #
261
261
  # This configuration option is +false+ by default to enable gradual adoption, but will be +true+ by default in the future.
262
262
  #
@@ -12,6 +12,7 @@ require 'mocha/change_state_side_effect'
12
12
  require 'mocha/cardinality'
13
13
  require 'mocha/configuration'
14
14
  require 'mocha/block_matcher'
15
+ require 'mocha/backtrace_filter'
15
16
 
16
17
  module Mocha
17
18
  # Methods on expectations returned from {Mock#expects}, {Mock#stubs}, {ObjectMethods#expects} and {ObjectMethods#stubs}.
@@ -266,7 +267,7 @@ module Mocha
266
267
  # object.expected_method(17)
267
268
  # # => verify fails
268
269
  def with(*expected_parameters_or_matchers, &matching_block)
269
- @parameters_matcher = ParametersMatcher.new(expected_parameters_or_matchers, &matching_block)
270
+ @parameters_matcher = ParametersMatcher.new(expected_parameters_or_matchers, self, &matching_block)
270
271
  self
271
272
  end
272
273
  ruby2_keywords(:with)
@@ -692,5 +693,11 @@ module Mocha
692
693
  signature << " #{@block_matcher.mocha_inspect}" if @block_matcher.mocha_inspect
693
694
  signature
694
695
  end
696
+
697
+ # @private
698
+ def definition_location
699
+ filter = BacktraceFilter.new
700
+ filter.filtered(backtrace)[0]
701
+ end
695
702
  end
696
703
  end
@@ -3,7 +3,7 @@ module Mocha
3
3
  # @abstract Subclass and implement +#matches?+ and +#mocha_inspect+ to define a custom matcher. Also add a suitably named instance method to {ParameterMatchers} to build an instance of the new matcher c.f. {#equals}.
4
4
  class Base
5
5
  # @private
6
- def to_matcher
6
+ def to_matcher(_expectation = nil)
7
7
  self
8
8
  end
9
9
 
@@ -6,7 +6,7 @@ module Mocha
6
6
  # @private
7
7
  module InstanceMethods
8
8
  # @private
9
- def to_matcher
9
+ def to_matcher(_expectation = nil)
10
10
  Mocha::ParameterMatchers::Equals.new(self)
11
11
  end
12
12
  end
@@ -21,7 +21,7 @@ end
21
21
  # @private
22
22
  class Hash
23
23
  # @private
24
- def to_matcher
25
- Mocha::ParameterMatchers::PositionalOrKeywordHash.new(self)
24
+ def to_matcher(expectation = nil)
25
+ Mocha::ParameterMatchers::PositionalOrKeywordHash.new(self, expectation)
26
26
  end
27
27
  end
@@ -6,8 +6,9 @@ module Mocha
6
6
  module ParameterMatchers
7
7
  # @private
8
8
  class PositionalOrKeywordHash < Base
9
- def initialize(value)
9
+ def initialize(value, expectation)
10
10
  @value = value
11
+ @expectation = expectation
11
12
  end
12
13
 
13
14
  def matches?(available_parameters)
@@ -38,10 +39,11 @@ module Mocha
38
39
  end
39
40
 
40
41
  def deprecation_warning(actual, expected)
41
- details = "Expected #{hash_type(expected)} (#{expected.mocha_inspect}), but received #{hash_type(actual)} (#{actual.mocha_inspect})."
42
+ details1 = "Expectation #{expectation_definition} expected #{hash_type(expected)} (#{expected.mocha_inspect}),".squeeze(' ')
43
+ details2 = "but received #{hash_type(actual)} (#{actual.mocha_inspect})."
42
44
  sentence1 = 'These will stop matching when strict keyword argument matching is enabled.'
43
45
  sentence2 = 'See the documentation for Mocha::Configuration#strict_keyword_argument_matching=.'
44
- Deprecation.warning([details, sentence1, sentence2].join(' '))
46
+ Deprecation.warning([details1, details2, sentence1, sentence2].join(' '))
45
47
  end
46
48
 
47
49
  def hash_type(hash)
@@ -51,6 +53,12 @@ module Mocha
51
53
  def ruby2_keywords_hash?(hash)
52
54
  hash.is_a?(Hash) && ::Hash.ruby2_keywords_hash?(hash)
53
55
  end
56
+
57
+ def expectation_definition
58
+ return nil unless @expectation
59
+
60
+ "defined at #{@expectation.definition_location}"
61
+ end
54
62
  end
55
63
  end
56
64
  end
@@ -3,8 +3,9 @@ require 'mocha/parameter_matchers'
3
3
 
4
4
  module Mocha
5
5
  class ParametersMatcher
6
- def initialize(expected_parameters = [ParameterMatchers::AnyParameters.new], &matching_block)
6
+ def initialize(expected_parameters = [ParameterMatchers::AnyParameters.new], expectation = nil, &matching_block)
7
7
  @expected_parameters = expected_parameters
8
+ @expectation = expectation
8
9
  @matching_block = matching_block
9
10
  end
10
11
 
@@ -27,7 +28,7 @@ module Mocha
27
28
  end
28
29
 
29
30
  def matchers
30
- @expected_parameters.map(&:to_matcher)
31
+ @expected_parameters.map { |p| p.to_matcher(@expectation) }
31
32
  end
32
33
  end
33
34
  end
data/lib/mocha/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mocha
2
- VERSION = '2.0.0.alpha'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  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: 2.0.0.alpha
4
+ version: 2.0.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: 2022-10-17 00:00:00.000000000 Z
11
+ date: 2022-11-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Mocking and stubbing library with JMock/SchMock syntax, which allows
14
14
  mocking and stubbing of methods on real (non-mock) classes.
@@ -132,9 +132,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
132
  version: '2.0'
133
133
  required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  requirements:
135
- - - ">"
135
+ - - ">="
136
136
  - !ruby/object:Gem::Version
137
- version: 1.3.1
137
+ version: '0'
138
138
  requirements: []
139
139
  rubygems_version: 3.3.3
140
140
  signing_key: