mocha 2.4.0 → 2.4.5

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: bc6cb720040e8f8e9b422f5c96529de7d3d0a6d26d5b627cbce4edc070de0b84
4
- data.tar.gz: 466f0bc9a7f8422150eaff6cfbff9bd6582c2ce71dbf72be894f6bcfc7c6fe33
3
+ metadata.gz: ecd327fa9f38f70ce2c055060703fe7e946da3a435d858e3f7a4dfc84cf1869b
4
+ data.tar.gz: aa3f71bdd6b8934e9a6f02361daad1b304f88b33362c77511c1f2810becf255e
5
5
  SHA512:
6
- metadata.gz: aacaeecf4b7e8eea1b2e4ae31bb19759a0c2045befc8cbe80ae9a9b32fb5af4dbaffc0bbefa228b33232b5cbd92c92c2e9aa61ca9660e0aa3f1500ac881606a1
7
- data.tar.gz: 2c9b80dc28bd3a397e70fe93c4c383c4faac9429e028197396b0c192bda9445a14629e694f74b86d180bdbe54af6c80ad152491806f4226d237da137e7020722
6
+ metadata.gz: ed7c31bf9f39294a89338718f7139c4ce23883b18b628aa02c8e1ea585a244ed77e6e322db1352431f6d3fd29b01de0f1e39acf2164209633ad62fd18f8d919c
7
+ data.tar.gz: e1380ad00c76d152ca14865f02a9019f4c83e36ff8433182b164ae308b46319859e80a7583b7dd7f8c0269b4da4a36b5f5bd1af6a8404e8870df010bf0ea917a
data/.rubocop.yml CHANGED
@@ -36,6 +36,11 @@ Style/WhileUntilModifier:
36
36
  Style/AccessModifierDeclarations:
37
37
  Enabled: false
38
38
 
39
+ # `Module#===` is useful in presence of objects such as mocks
40
+ # that may have a `is_a?` implementation that lies.
41
+ Style/CaseEquality:
42
+ Enabled: false
43
+
39
44
  # This is useful when using `ExecutionPoint.current` to make tests more robust
40
45
  Style/Semicolon:
41
46
  Enabled: false
data/RELEASE.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # Release Notes
2
2
 
3
+ ## 2.4.5
4
+
5
+ ### External changes
6
+
7
+ * Fix regression when stubbed method expects `Hash` but receives `ActionController::Parameters` object (#662, #664) - thanks to @evgeni for reporting and testing
8
+
9
+ ## 2.4.4
10
+
11
+ ### External changes
12
+
13
+ * Fix regression when method expecting `Hash` parameter or keyword arguments is invoked with no arguments (#662, #663) - thanks to @vlad-pisanov for reporting
14
+
15
+ ## 2.4.3
16
+
17
+ ### External changes
18
+
19
+ * Fix regression when matching `Hash` parameter or keyword arguments (#657, #660) - thanks to @josesei for reporting and testing
20
+
21
+ ## 2.4.2
22
+
23
+ ### External changes
24
+
25
+ * Don't trust `Object#is_a?` in presence of mock objects (#656) - thanks to @casperisfine
26
+
27
+ ## 2.4.1
28
+
29
+ ### External changes
30
+
31
+ * Fix regression in matchers when used with keyword arguments (#654 & #655) - thanks to @ElvinEfendi for reporting
32
+
33
+ ### Internal changes
34
+
35
+ * Reduce duplication & consolidate `#to_matcher` method definitions (600ee2aa, e9de64e4, #655)
36
+ * Change `#to_matcher` method to use keyword arguments (3b60b7df, #655)
37
+
3
38
  ## 2.4.0
4
39
 
5
40
  ### External changes
@@ -2,11 +2,6 @@ module Mocha
2
2
  module ParameterMatchers
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
- # @private
6
- def to_matcher(_expectation = nil)
7
- self
8
- end
9
-
10
5
  # A shorthand way of combining two matchers when both must match.
11
6
  #
12
7
  # Returns a new {AllOf} parameter matcher combining two matchers using a logical AND.
@@ -30,20 +30,25 @@ module Mocha
30
30
  # Parameter matcher which matches when actual parameter contains all expected +Hash+ entries.
31
31
  class HasEntries < Base
32
32
  # @private
33
- def initialize(entries)
33
+ def initialize(entries, exact: false)
34
34
  @entries = entries
35
+ @exact = exact
35
36
  end
36
37
 
37
38
  # @private
38
39
  def matches?(available_parameters)
39
40
  parameter = available_parameters.shift
41
+ return false unless parameter
42
+ return false unless parameter.respond_to?(:keys)
43
+ return false if @exact && @entries.length != parameter.keys.length
44
+
40
45
  has_entry_matchers = @entries.map { |key, value| HasEntry.new(key, value) }
41
46
  AllOf.new(*has_entry_matchers).matches?([parameter])
42
47
  end
43
48
 
44
49
  # @private
45
50
  def mocha_inspect
46
- "has_entries(#{@entries.mocha_inspect})"
51
+ @exact ? @entries.mocha_inspect : "has_entries(#{@entries.mocha_inspect})"
47
52
  end
48
53
  end
49
54
  end
@@ -1,3 +1,4 @@
1
+ require 'mocha/parameter_matchers/base'
1
2
  require 'mocha/parameter_matchers/equals'
2
3
  require 'mocha/parameter_matchers/positional_or_keyword_hash'
3
4
 
@@ -6,8 +7,14 @@ module Mocha
6
7
  # @private
7
8
  module InstanceMethods
8
9
  # @private
9
- def to_matcher(_expectation = nil)
10
- Mocha::ParameterMatchers::Equals.new(self)
10
+ def to_matcher(expectation: nil, top_level: false)
11
+ if Base === self
12
+ self
13
+ elsif Hash === self && top_level
14
+ Mocha::ParameterMatchers::PositionalOrKeywordHash.new(self, expectation)
15
+ else
16
+ Mocha::ParameterMatchers::Equals.new(self)
17
+ end
11
18
  end
12
19
  end
13
20
  end
@@ -17,11 +24,3 @@ end
17
24
  class Object
18
25
  include Mocha::ParameterMatchers::InstanceMethods
19
26
  end
20
-
21
- # @private
22
- class Hash
23
- # @private
24
- def to_matcher(expectation = nil)
25
- Mocha::ParameterMatchers::PositionalOrKeywordHash.new(self, expectation)
26
- end
27
- end
@@ -1,6 +1,7 @@
1
1
  require 'mocha/configuration'
2
2
  require 'mocha/deprecation'
3
3
  require 'mocha/parameter_matchers/base'
4
+ require 'mocha/parameter_matchers/has_entries'
4
5
 
5
6
  module Mocha
6
7
  module ParameterMatchers
@@ -14,7 +15,7 @@ module Mocha
14
15
  def matches?(available_parameters)
15
16
  parameter, is_last_parameter = extract_parameter(available_parameters)
16
17
 
17
- return false unless HasEntries.new(@value).matches?([parameter])
18
+ return false unless HasEntries.new(@value, exact: true).matches?([parameter])
18
19
 
19
20
  if is_last_parameter && !same_type_of_hash?(parameter, @value)
20
21
  return false if Mocha.configuration.strict_keyword_argument_matching?
@@ -28,7 +28,7 @@ module Mocha
28
28
  end
29
29
 
30
30
  def matchers
31
- @expected_parameters.map { |p| p.to_matcher(@expectation) }
31
+ @expected_parameters.map { |p| p.to_matcher(expectation: @expectation, top_level: true) }
32
32
  end
33
33
  end
34
34
  end
data/lib/mocha/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mocha
2
- VERSION = '2.4.0'.freeze
2
+ VERSION = '2.4.5'.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.4.0
4
+ version: 2.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mead
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-16 00:00:00.000000000 Z
11
+ date: 2024-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby2_keywords