grift 1.0.1 → 1.0.2

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: dfb5ff564a491305f0eccd4e3098fb3c132fca4b70fef6f07ff05fd5a087fe12
4
- data.tar.gz: bf327e20c122bc67ac490cce8409f80fb7e03fbeb81aca5e7443a2bad9b61c93
3
+ metadata.gz: 98c5113978ecfca383496652f50e2fee8b820bdf0f9dfd94e01649b567c44ee8
4
+ data.tar.gz: 16d205bacdddd4018ef18654b09c7f9b7d283956a382875f6f4dbae58f1244dd
5
5
  SHA512:
6
- metadata.gz: ebe31625bd0ecf33c2d5e0cfbadba80ac634cfaee932d0e54cb915c94720b538ab6748c56f311ece69177c078a8ce4394c39ae1b4c431bc78293d0c34b2e95d6
7
- data.tar.gz: 4779c67321958fe366269a293308c145e2402cb6a169a651a94e6ebdccd678b1b96154edd1170c5c5eeae84ddbe57f5ce769b41280dd9158a51f37beff679d0c
6
+ metadata.gz: 75ca213c47eabb2e1cf4ee8790949e041ff383193a844f34f1ab794486cd3afdf633e0206f367e7b74d358276bb43f48b7b0dcf8ae8fbb124977d42c34df1bb7
7
+ data.tar.gz: 91e88879f44d036403d94808ab853007a66f10e60dad5569e38ace29f1969abc2abc24fdb87b6f9f5db61c98a8efdd34c6d4cfcb4f063fc147e9a1bc80ece52c
data/CHANGELOG.md CHANGED
@@ -8,6 +8,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
8
8
 
9
9
  N/A
10
10
 
11
+ ## [1.0.2](https://github.com/clarkedb/grift/releases/tag/v1.0.2) - 2021-11-11
12
+
13
+ This version fixes a bug that prevented the mocking of methods defined by a class's super class.
14
+
15
+ ### Fixed
16
+
17
+ * Allow mocks of inherited methods
18
+
11
19
  ## [1.0.1](https://github.com/clarkedb/grift/releases/tag/v1.0.1) - 2021-11-10
12
20
 
13
21
  This version fixes a bug that prevented most mocking features in Grift from functioning as expected.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grift (1.0.1)
4
+ grift (1.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -36,6 +36,14 @@ class Minitest::Test
36
36
  end
37
37
  ```
38
38
 
39
+ Or for Ruby on Rails:
40
+
41
+ ```ruby
42
+ class ActiveSupport::TestCase
43
+ include Grift::MinitestPlugin
44
+ end
45
+ ```
46
+
39
47
  ## Usage
40
48
 
41
49
  For complete usage guide, see the [docs](https://clarkedb.github.io/grift/).
@@ -29,7 +29,7 @@ module Grift
29
29
  #
30
30
  def initialize(klass, method_name, watch: true)
31
31
  if Grift.restricted_method?(klass, method_name)
32
- raise(Grift::Error, "Cannont mock restricted method #{method_name} for class #{klass}")
32
+ raise(Grift::Error, "Cannot mock restricted method #{method_name} for class #{klass}")
33
33
  end
34
34
 
35
35
  @klass = klass
@@ -41,8 +41,8 @@ module Grift
41
41
  # class methods are really instance methods of the singleton class
42
42
  @class_method = klass.singleton_class.instance_methods(true).include?(method_name)
43
43
 
44
- unless class_instance.instance_methods(true).include?(method_name)
45
- raise(Grift::Error, "Cannont mock unknown method #{method_name} for class #{klass}")
44
+ unless @class_method || class_instance.instance_methods(true).include?(method_name)
45
+ raise(Grift::Error, "Cannot mock unknown method #{method_name} for class #{klass}")
46
46
  end
47
47
 
48
48
  if class_instance.instance_methods.include?(@cache_method_name)
@@ -137,7 +137,7 @@ module Grift
137
137
  premock_setup
138
138
  mock_executions = @mock_executions # required to access inside class instance block
139
139
 
140
- class_instance.remove_method(@method_name)
140
+ class_instance.remove_method(@method_name) if class_instance.instance_methods(false).include?(@method_name)
141
141
  class_instance.define_method @method_name do |*args|
142
142
  return_value = block.call(*args)
143
143
 
@@ -168,7 +168,7 @@ module Grift
168
168
  premock_setup
169
169
  mock_executions = @mock_executions # required to access inside class instance block
170
170
 
171
- class_instance.remove_method(@method_name)
171
+ class_instance.remove_method(@method_name) if method_defined?
172
172
  class_instance.define_method @method_name do |*args|
173
173
  # record the args passed in the call to the method and the result
174
174
  mock_executions.store(args, return_value)
@@ -217,7 +217,7 @@ module Grift
217
217
  mock_executions = @mock_executions # required to access inside class instance block
218
218
  cache_method_name = @cache_method_name
219
219
 
220
- class_instance.remove_method(@method_name)
220
+ class_instance.remove_method(@method_name) if method_defined?
221
221
  class_instance.define_method @method_name do |*args|
222
222
  return_value = send(cache_method_name, *args)
223
223
 
@@ -237,7 +237,7 @@ module Grift
237
237
  def unmock_method
238
238
  raise(Grift::Error, 'Method is not cached') unless @true_method_cached
239
239
 
240
- class_instance.remove_method(@method_name)
240
+ class_instance.remove_method(@method_name) if method_defined?
241
241
  class_instance.alias_method(@method_name, @cache_method_name)
242
242
  class_instance.remove_method(@cache_method_name)
243
243
 
@@ -280,5 +280,16 @@ module Grift
280
280
  def class_instance
281
281
  @class_method ? @klass.singleton_class : @klass
282
282
  end
283
+
284
+ ##
285
+ # Checks if the method is defined on the class instance. If the method is
286
+ # inherited from the super class and has not been mocked yet, this will
287
+ # return false because the super class defined the method.
288
+ #
289
+ # @return [Boolean]
290
+ #
291
+ def method_defined?
292
+ class_instance.instance_methods(false).include?(@method_name)
293
+ end
283
294
  end
284
295
  end
data/lib/grift/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Grift
4
4
  # gem version
5
- VERSION = '1.0.1'
5
+ VERSION = '1.0.2'
6
6
  public_constant :VERSION
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grift
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clark Brown