minitest-moar 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/lib/minitest/moar/stubbing.rb +29 -19
- data/lib/minitest/moar/version.rb +1 -1
- data/minitest-moar.gemspec +1 -0
- data/test/stubbing_test.rb +22 -0
- data/test/test_helper.rb +12 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bd36ad22b5cbc2fe05af43cbda9cd06e93b390f
|
4
|
+
data.tar.gz: e9a7a1629f9a259d9dca78543087057ea61eba9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 617a0b96ae8bc72f5ca2ba858a72c8cd53e16b247aba124a60083df40b5b1d3441d740cc41d00fb5637bcbaa4527f5cae3761445d5f787bda15ace6429e41050
|
7
|
+
data.tar.gz: e31b2670df6dc3356bcdb57a758538d528418211b834b852a76c07618901f7a14be4d3412fd68a6fd14b721140df2d0908b17d553ba6ac80d964ab3b696253c0
|
data/Gemfile
CHANGED
@@ -2,32 +2,42 @@ module Minitest::Moar::Stubbing
|
|
2
2
|
def stub klass, name, val_or_callable = nil, *block_args, &block
|
3
3
|
@invocations ||= Hash.new { |h, k| h[k] = Hash.new { |_h, _k| _h[_k] = 0 } }
|
4
4
|
|
5
|
-
new_name = "__minitest_stub__#{name}"
|
6
|
-
|
7
5
|
metaclass = class << klass; self; end
|
8
|
-
|
6
|
+
|
7
|
+
if metaclass.respond_to? name and not metaclass.instance_methods.map(&:to_s).include? name.to_s then
|
8
|
+
metaclass.send :define_method, name do |*args|
|
9
|
+
super(*args)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
__stub__ metaclass, name, val_or_callable, block_args, &block
|
9
13
|
end
|
10
14
|
|
11
|
-
def instance_stub
|
12
|
-
|
15
|
+
def instance_stub obj, name, val_or_callable = nil, *block_args, &block
|
16
|
+
if obj.respond_to? name and not obj.methods.map(&:to_s).include? name.to_s then
|
17
|
+
obj.send :define_method, name do |*args|
|
18
|
+
super(*args)
|
19
|
+
end
|
20
|
+
end
|
13
21
|
|
14
|
-
|
22
|
+
__stub__ obj, name, val_or_callable, block_args, &block
|
23
|
+
end
|
15
24
|
|
25
|
+
def __stub__ obj, name, val_or_callable = nil, *block_args, &block
|
16
26
|
new_name = "__minitest_stub__#{name}"
|
17
27
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
28
|
+
@invocations ||= Hash.new { |h, k| h[k] = Hash.new { |_h, _k| _h[_k] = 0 } }
|
29
|
+
|
30
|
+
invoker = Proc.new { |klass, name| @invocations[klass][name] += 1 }
|
23
31
|
|
24
|
-
|
32
|
+
obj.send :alias_method, new_name, name
|
25
33
|
|
26
|
-
|
27
|
-
|
34
|
+
# Module.method(:define_method).bind(klass).call(name) do |*args, &blk|
|
35
|
+
obj.send :define_method, name do |*args, &blk|
|
36
|
+
if ::Class === self
|
28
37
|
invoker.call(self, name)
|
29
38
|
else
|
30
|
-
|
39
|
+
klass = Kernel.instance_method(:class).bind(self).call
|
40
|
+
invoker.call("Instance of #{klass}", name)
|
31
41
|
end
|
32
42
|
|
33
43
|
ret = if val_or_callable.respond_to? :call then
|
@@ -41,11 +51,11 @@ module Minitest::Moar::Stubbing
|
|
41
51
|
ret
|
42
52
|
end
|
43
53
|
|
44
|
-
yield
|
54
|
+
yield obj
|
45
55
|
ensure
|
46
|
-
|
47
|
-
|
48
|
-
|
56
|
+
obj.send :undef_method, name
|
57
|
+
obj.send :alias_method, name, new_name
|
58
|
+
obj.send :undef_method, new_name
|
49
59
|
end
|
50
60
|
end
|
51
61
|
|
data/minitest-moar.gemspec
CHANGED
data/test/stubbing_test.rb
CHANGED
@@ -39,4 +39,26 @@ class StubbingTest < Minitest::Test
|
|
39
39
|
|
40
40
|
assert_equal 1, @called
|
41
41
|
end
|
42
|
+
|
43
|
+
def test_basic_object_stubbing
|
44
|
+
dog = Dog.new
|
45
|
+
|
46
|
+
@called = 0
|
47
|
+
caller = Proc.new { @called += 1 }
|
48
|
+
stub dog, :name, caller do
|
49
|
+
dog.name
|
50
|
+
end
|
51
|
+
|
52
|
+
assert_equal 1, @called
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_module_stubbing
|
56
|
+
@called = 0
|
57
|
+
caller = Proc.new { @called += 1 }
|
58
|
+
stub Project, :name, caller do
|
59
|
+
Project.name
|
60
|
+
end
|
61
|
+
|
62
|
+
assert_equal 1, @called
|
63
|
+
end
|
42
64
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-moar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Cardarella
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.1'
|
41
55
|
description: Moar Minitest Please!
|
42
56
|
email:
|
43
57
|
- bcardarella@gmail.com
|