minitest-stub_any_instance 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/minitest/stub_any_instance.rb +9 -6
- data/test/stub_any_instance_test.rb +26 -0
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d419f072287bcd82581e413aad81d8bd2fce844
|
4
|
+
data.tar.gz: cbc5e034772668f9e8d300177ed77cc13da81241
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8919405ef56b01544131016a2ea10dccf4eb788265405851e7df1870dfb7096493060d54ca74644bd1580c589e907b82fb285307642475e0d89ad6010a62c5b
|
7
|
+
data.tar.gz: af7336b7d9c596af39bc2a22f8c80cd323a7e05fbd6c5165e023c7bfba89e3588af54753061ed8c47eb96451aa77cd4062bff0f2ab7afbd350a3842789e6174b
|
@@ -1,9 +1,10 @@
|
|
1
|
-
class
|
1
|
+
class BasicObject
|
2
2
|
def self.stub_any_instance name, val_or_callable, &block
|
3
3
|
new_name = "__minitest_any_instance_stub__#{name}"
|
4
4
|
|
5
|
+
owns_method = instance_method(name).owner == self
|
5
6
|
class_eval do
|
6
|
-
alias_method new_name, name
|
7
|
+
alias_method new_name, name if owns_method
|
7
8
|
|
8
9
|
define_method(name) do |*args|
|
9
10
|
if val_or_callable.respond_to? :call then
|
@@ -17,9 +18,11 @@ class Object
|
|
17
18
|
yield
|
18
19
|
ensure
|
19
20
|
class_eval do
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
remove_method name
|
22
|
+
if owns_method
|
23
|
+
alias_method name, new_name
|
24
|
+
remove_method new_name
|
25
|
+
end
|
23
26
|
end
|
24
27
|
end
|
25
|
-
end
|
28
|
+
end
|
@@ -2,6 +2,23 @@ require 'minitest/autorun'
|
|
2
2
|
require 'stringio'
|
3
3
|
require File.expand_path("../../lib/minitest/stub_any_instance", __FILE__)
|
4
4
|
|
5
|
+
module StubAnyInstanceTest
|
6
|
+
class GrandparentClass < BasicObject
|
7
|
+
def foo(_a)
|
8
|
+
'bar'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ParentClass < GrandparentClass
|
13
|
+
def foo
|
14
|
+
super(:a)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class ChildClass < ParentClass
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
5
22
|
class TestStubAnyInstance < MiniTest::Unit::TestCase
|
6
23
|
def setup
|
7
24
|
$stderr = StringIO.new
|
@@ -41,4 +58,13 @@ class TestStubAnyInstance < MiniTest::Unit::TestCase
|
|
41
58
|
end
|
42
59
|
end
|
43
60
|
|
61
|
+
def test_stub_method_not_implemented_in_grandchild_class
|
62
|
+
::StubAnyInstanceTest::ChildClass.stub_any_instance(:foo, :result) do
|
63
|
+
assert_equal :result, ::StubAnyInstanceTest::ChildClass.new.foo
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_stubbed_method_does_not_get_restored_to_non_owning_class
|
68
|
+
assert_equal 'bar', ::StubAnyInstanceTest::ChildClass.new.foo
|
69
|
+
end
|
44
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-stub_any_instance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sammy Larbi
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-01-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 1.11.2
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 1.11.2
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
42
56
|
description: Adds a method to MiniTest that stubs any instance of a class.
|
43
57
|
email:
|
44
58
|
- sam@codeodor.com
|
@@ -68,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
82
|
version: '0'
|
69
83
|
requirements: []
|
70
84
|
rubyforge_project:
|
71
|
-
rubygems_version: 2.
|
85
|
+
rubygems_version: 2.6.14
|
72
86
|
signing_key:
|
73
87
|
specification_version: 4
|
74
88
|
summary: ''
|