mocha 2.0.0.alpha → 2.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69781697a086ec84aecb54fa1f63dff7842796caa275af3f01e82695e7187b0d
4
- data.tar.gz: f0aa6493ffccdeeb7f48b0aa8a329ba57612c4c01470642b0df8f23392857534
3
+ metadata.gz: 97e7753fb6b5d10c44315d7b40ab4004dd1ee6224af909d983e2553d6541701b
4
+ data.tar.gz: 917eff26dfcbdfa01dc4c1befcb43556075d87b0b9929ac055498e2a9ec4e622
5
5
  SHA512:
6
- metadata.gz: ddc7f9eab0a9506cc0e5a69ffc0bbc359d68c4e19f2c2cd207554d2b264854f77a38bed9fa7df6f0ac110b25cf26aaa9315ec092d709a0d2cdc8ec610c3cc2fc
7
- data.tar.gz: 7b20ce12545006706f32ff11863802dd31fe4c766925e7ca2bd63828f8dc78e98cb692d9bf5558e6ea6f401929be236c52183bc42ecfff05a752c002d9414c2c
6
+ metadata.gz: 9421147bdeb37a99308e577e284248f0c2ddad246772d4822a0d97c11ed4e393e12f5157be6832d0bf7ab58b60227910282b5ec315615476b27ecc7ff67523fc
7
+ data.tar.gz: 1a63c4651b41de00f65ed771f1b22d0e6b63c1d795b9c36b195889fac3bd55168399d0b3a7cc6dfae77fcfdbfffce8098e8f5b6a8cef4fc49f481a533d844c6d
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/RELEASE.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Release Notes
2
2
 
3
+ ## 2.0.0.alpha.1
4
+
5
+ ### External changes
6
+
7
+ * Improve strict keyword argument matching deprecation warning by including the source location of the stub definition (77c0d4cc)
8
+
9
+ ### Internal changes
10
+
11
+ * Disable Style/Semicolon cop globally (8cd0b705)
12
+
3
13
  ## 2.0.0.alpha
4
14
 
5
15
  ### External changes
@@ -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.alpha.1'.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.alpha.1
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-10-18 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.