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 CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- metadata.gz: e5d7e06636c2654760be8dee2fbe8c80d9b86ef4
4
- data.tar.gz: ebca2dede9dd9f9305548d3d8eb9db88a4ec1bae
5
- SHA512:
6
- metadata.gz: 6e4b733a9dccaa7babf00419d86f7e6d112d1a84cfe306c854509e9109bedbaae1c22f2ed4d83edd95f05c571c9ce804251bd0ca75a790478703bf4a703497d8
7
- data.tar.gz: b41abee2b1ed680b2df84d1eb08c5854beb98001a5b774c4ef2311e583200b96cbdb2ccf1872068c98d050107a1e3fc23eecc02e283fe01cb8e211ce2365b875
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
- MuchStub.stub(myobj, :mymeth)
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.stub(myobj, :mymeth){ 'stub-meth' }
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.stub(myobj, :mymeth).with(123){ 'stub-meth' }
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
- MuchStub.stub(myobj, :myval){ 'stub-meth' }
47
+ # Create a new stub for the :myval method
48
+
49
+ MuchStub.(myobj, :myval){ 'stub-meth' }
44
50
  # => StubError: arity mismatch
45
- MuchStub.stub(myobj, :myval).with(123){ |val| val.to_s }
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
- MuchStub.stub_send(myobj, :myval, 123) # call to the original method post-stub
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)
@@ -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
- (self.stubs[MuchStub::Stub.key(obj, meth)] ||= begin
11
- MuchStub::Stub.new(obj, meth, caller_locations)
12
- end).tap{ |s| s.do = block }
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
- (self.stubs.delete(MuchStub::Stub.key(obj, meth)) || MuchStub::NullStub.new).teardown
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 => exception
79
+ rescue NotStubbedError
71
80
  @lookup.rehash
72
81
  lookup(args, orig_caller).call(*args, &block)
73
82
  end
@@ -1,3 +1,3 @@
1
1
  module MuchStub
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -18,6 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_development_dependency("assert", ["~> 2.16.3"])
21
+ gem.add_development_dependency("assert", ["~> 2.17.0"])
22
22
 
23
23
  end
@@ -23,20 +23,23 @@ module MuchStub
23
23
  end
24
24
 
25
25
  should "build a stub" do
26
- stub1 = MuchStub.stub(@myobj, :mymeth)
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.stub(@myobj, :mymeth)
32
- stub2 = MuchStub.stub(@myobj, :mymeth)
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.stub(@myobj, :mymeth)
40
+ MuchStub.(@myobj, :mymeth)
38
41
  assert_raises(MuchStub::NotStubbedError){ @myobj.mymeth }
39
- MuchStub.stub(@myobj, :mymeth){ @stub_value }
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.stub(@myobj, :mymeth){ @stub_value }
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.stub(@myobj, :mymeth){ @stub_value }
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.stub(@myobj, :mymeth){ @stub_value }
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.0
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
- date: 2018-06-05 00:00:00 Z
14
- dependencies:
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
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- requirements:
20
- - - ~>
21
- - !ruby/object:Gem::Version
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
- version_requirements: *id001
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
- files:
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
- - &id002
62
- - ">="
63
- - !ruby/object:Gem::Version
64
- version: "0"
65
- required_rubygems_version: !ruby/object:Gem::Requirement
66
- requirements:
67
- - *id002
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.6.6
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