much-stub 0.1.0 → 0.1.1
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 +7 -7
- data/README.md +23 -6
- data/lib/much-stub.rb +14 -5
- data/lib/much-stub/version.rb +1 -1
- data/much-stub.gemspec +1 -1
- data/test/unit/much-stub_tests.rb +11 -8
- metadata +35 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 405abaae599baf274c0eea900413f3c534c3acf1a19b4a83a356f5c61640025b
|
4
|
+
data.tar.gz: e68b22427ea8c78b87023576611a94c750a9d4ed75989cc72b7cdc96a56ebf2d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d1cafda498eceb26c4d41a4b4867c0376dc36d34149454350e3ac4ef8a04623ee747a6d28639e417cac93eeb1f4950c1fda696153be860c61e9fef8be8f36a3e
|
7
|
+
data.tar.gz: 416559df2f95b8faa18fac713e924e5af8ac128b2b385a91623f32939396488f9f2a0ecef01649c3099b076e385270cbae2f5f79a84e0e26d54c689c193e7e7e
|
data/README.md
CHANGED
@@ -14,6 +14,8 @@ Note: this was originally implemented in and extracted from [Assert](https://git
|
|
14
14
|
## Usage
|
15
15
|
|
16
16
|
```ruby
|
17
|
+
# Given this object/API
|
18
|
+
|
17
19
|
myclass = Class.new do
|
18
20
|
def mymeth; 'meth'; end
|
19
21
|
def myval(val); val; end
|
@@ -27,36 +29,51 @@ myobj.myval(123)
|
|
27
29
|
myobj.myval(456)
|
28
30
|
# => 456
|
29
31
|
|
30
|
-
|
32
|
+
# Create a new stub for the :mymeth method
|
33
|
+
|
34
|
+
MuchStub.(myobj, :mymeth)
|
31
35
|
myobj.mymeth
|
32
36
|
# => StubError: `mymeth` not stubbed.
|
33
|
-
MuchStub.
|
37
|
+
MuchStub.(myobj, :mymeth){ 'stub-meth' }
|
34
38
|
myobj.mymeth
|
35
39
|
# => 'stub-meth'
|
36
40
|
myobj.mymeth(123)
|
37
41
|
# => StubError: arity mismatch
|
38
|
-
MuchStub.
|
42
|
+
MuchStub.(myobj, :mymeth).with(123){ 'stub-meth' }
|
39
43
|
# => StubError: arity mismatch
|
40
44
|
MuchStub.stub_send(myobj, :mymeth) # call to the original method post-stub
|
41
45
|
# => 'meth'
|
42
46
|
|
43
|
-
|
47
|
+
# Create a new stub for the :myval method
|
48
|
+
|
49
|
+
MuchStub.(myobj, :myval){ 'stub-meth' }
|
44
50
|
# => StubError: arity mismatch
|
45
|
-
MuchStub.
|
51
|
+
MuchStub.(myobj, :myval).with(123){ |val| val.to_s }
|
46
52
|
myobj.myval
|
47
53
|
# => StubError: arity mismatch
|
48
54
|
myobj.myval(123)
|
49
55
|
# => '123'
|
50
56
|
myobj.myval(456)
|
51
57
|
# => StubError: `myval(456)` not stubbed.
|
52
|
-
|
58
|
+
|
59
|
+
# Call to the original method post-stub
|
60
|
+
|
61
|
+
MuchStub.stub_send(myobj, :myval, 123)
|
53
62
|
# => 123
|
54
63
|
MuchStub.stub_send(myobj, :myval, 456)
|
55
64
|
# => 456
|
56
65
|
|
66
|
+
# Unstub individual stubs
|
67
|
+
|
57
68
|
MuchStub.unstub(myobj, :mymeth)
|
58
69
|
MuchStub.unstub(myobj, :myval)
|
59
70
|
|
71
|
+
# OR blanket unstub all stubs
|
72
|
+
|
73
|
+
MuchStub.unstub!
|
74
|
+
|
75
|
+
# Original API is preserved after unstubbing
|
76
|
+
|
60
77
|
myobj.mymeth
|
61
78
|
# => 'meth'
|
62
79
|
myobj.myval(123)
|
data/lib/much-stub.rb
CHANGED
@@ -6,14 +6,23 @@ module MuchStub
|
|
6
6
|
@stubs ||= {}
|
7
7
|
end
|
8
8
|
|
9
|
+
def self.stub_key(obj, meth)
|
10
|
+
MuchStub::Stub.key(obj, meth)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.call(*args, &block)
|
14
|
+
self.stub(*args, &block)
|
15
|
+
end
|
16
|
+
|
9
17
|
def self.stub(obj, meth, &block)
|
10
|
-
|
11
|
-
|
12
|
-
|
18
|
+
key = self.stub_key(obj, meth)
|
19
|
+
self.stubs[key] ||= MuchStub::Stub.new(obj, meth, caller_locations)
|
20
|
+
self.stubs[key].tap{ |s| s.do = block }
|
13
21
|
end
|
14
22
|
|
15
23
|
def self.unstub(obj, meth)
|
16
|
-
|
24
|
+
key = self.stub_key(obj, meth)
|
25
|
+
(self.stubs.delete(key) || MuchStub::NullStub.new).teardown
|
17
26
|
end
|
18
27
|
|
19
28
|
def self.unstub!
|
@@ -67,7 +76,7 @@ module MuchStub
|
|
67
76
|
raise StubArityError, msg, orig_caller.map(&:to_s)
|
68
77
|
end
|
69
78
|
lookup(args, orig_caller).call(*args, &block)
|
70
|
-
rescue NotStubbedError
|
79
|
+
rescue NotStubbedError
|
71
80
|
@lookup.rehash
|
72
81
|
lookup(args, orig_caller).call(*args, &block)
|
73
82
|
end
|
data/lib/much-stub/version.rb
CHANGED
data/much-stub.gemspec
CHANGED
@@ -23,20 +23,23 @@ module MuchStub
|
|
23
23
|
end
|
24
24
|
|
25
25
|
should "build a stub" do
|
26
|
-
stub1 = MuchStub.
|
26
|
+
stub1 = MuchStub.(@myobj, :mymeth)
|
27
27
|
assert_kind_of MuchStub::Stub, stub1
|
28
|
+
|
29
|
+
stub2 = MuchStub.call(@myobj, :mymeth)
|
30
|
+
assert_kind_of MuchStub::Stub, stub2
|
28
31
|
end
|
29
32
|
|
30
33
|
should "lookup stubs that have been called before" do
|
31
|
-
stub1 = MuchStub.
|
32
|
-
stub2 = MuchStub.
|
34
|
+
stub1 = MuchStub.(@myobj, :mymeth)
|
35
|
+
stub2 = MuchStub.(@myobj, :mymeth)
|
33
36
|
assert_same stub1, stub2
|
34
37
|
end
|
35
38
|
|
36
39
|
should "set the stub's do block if given a block" do
|
37
|
-
MuchStub.
|
40
|
+
MuchStub.(@myobj, :mymeth)
|
38
41
|
assert_raises(MuchStub::NotStubbedError){ @myobj.mymeth }
|
39
|
-
MuchStub.
|
42
|
+
MuchStub.(@myobj, :mymeth){ @stub_value }
|
40
43
|
assert_equal @stub_value, @myobj.mymeth
|
41
44
|
end
|
42
45
|
|
@@ -46,7 +49,7 @@ module MuchStub
|
|
46
49
|
assert_equal @orig_value, @myobj.mymeth
|
47
50
|
|
48
51
|
assert_equal @orig_value, @myobj.mymeth
|
49
|
-
MuchStub.
|
52
|
+
MuchStub.(@myobj, :mymeth){ @stub_value }
|
50
53
|
assert_equal @stub_value, @myobj.mymeth
|
51
54
|
MuchStub.unstub(@myobj, :mymeth)
|
52
55
|
assert_equal @orig_value, @myobj.mymeth
|
@@ -55,7 +58,7 @@ module MuchStub
|
|
55
58
|
should "know and teardown all stubs" do
|
56
59
|
assert_equal @orig_value, @myobj.mymeth
|
57
60
|
|
58
|
-
MuchStub.
|
61
|
+
MuchStub.(@myobj, :mymeth){ @stub_value }
|
59
62
|
assert_equal @stub_value, @myobj.mymeth
|
60
63
|
assert_equal 1, MuchStub.stubs.size
|
61
64
|
|
@@ -69,7 +72,7 @@ module MuchStub
|
|
69
72
|
assert_includes 'not stubbed.', err.message
|
70
73
|
assert_includes 'test/unit/much-stub_tests.rb', err.backtrace.first
|
71
74
|
|
72
|
-
MuchStub.
|
75
|
+
MuchStub.(@myobj, :mymeth){ @stub_value }
|
73
76
|
|
74
77
|
assert_equal @stub_value, @myobj.mymeth
|
75
78
|
assert_equal @orig_value, MuchStub.stub_send(@myobj, :mymeth)
|
metadata
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: much-stub
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Kelly Redding
|
8
8
|
- Collin Redding
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2019-05-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: assert
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
version: 2.16.3
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.17.0
|
23
21
|
type: :development
|
24
|
-
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.17.0
|
25
28
|
description: Stubbing API for replacing method calls on objects in test runs.
|
26
|
-
email:
|
29
|
+
email:
|
27
30
|
- kelly@kellyredding.com
|
28
31
|
- collin.redding@me.com
|
29
32
|
executables: []
|
30
|
-
|
31
33
|
extensions: []
|
32
|
-
|
33
34
|
extra_rdoc_files: []
|
34
|
-
|
35
|
-
|
36
|
-
- .gitignore
|
35
|
+
files:
|
36
|
+
- ".gitignore"
|
37
37
|
- Gemfile
|
38
38
|
- LICENSE
|
39
39
|
- README.md
|
@@ -47,32 +47,30 @@ files:
|
|
47
47
|
- test/unit/much-stub_tests.rb
|
48
48
|
- tmp/.gitkeep
|
49
49
|
homepage: https://github.com/redding/much-stub
|
50
|
-
licenses:
|
50
|
+
licenses:
|
51
51
|
- MIT
|
52
52
|
metadata: {}
|
53
|
-
|
54
53
|
post_install_message:
|
55
54
|
rdoc_options: []
|
56
|
-
|
57
|
-
require_paths:
|
55
|
+
require_paths:
|
58
56
|
- lib
|
59
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
-
requirements:
|
61
|
-
-
|
62
|
-
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
68
67
|
requirements: []
|
69
|
-
|
70
68
|
rubyforge_project:
|
71
|
-
rubygems_version: 2.
|
69
|
+
rubygems_version: 2.7.7
|
72
70
|
signing_key:
|
73
71
|
specification_version: 4
|
74
72
|
summary: Stubbing API for replacing method calls on objects in test runs.
|
75
|
-
test_files:
|
73
|
+
test_files:
|
76
74
|
- test/helper.rb
|
77
75
|
- test/support/factory.rb
|
78
76
|
- test/system/much-stub_tests.rb
|