assert 2.18.0 → 2.18.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20bea593cdc98d699ba8e3cc3a946d178800c3e08afce5ccc19bc844851c8a1c
4
- data.tar.gz: 3eb6857857d305066936768ff680d30449bb6ee2e5730805227ab0f8120465e9
3
+ metadata.gz: ea0650f5a320e5717749a864de46a1864eb5ba3bb0e308d5a1566734f390360c
4
+ data.tar.gz: 4745c715d058de3dfd306dd920de2c8a59653564349d71e9a712bd2f9e0d5291
5
5
  SHA512:
6
- metadata.gz: 67b54d007f1a3da01a789d9b5bf77fd8850fb21cb2997b41719c9ec88ad93ebe7a94a4b1874f85c81adc31c09818f5cdc44e20d39ea7488710a8bb09dba7562a
7
- data.tar.gz: 17ce1c4d21f34fcb1b229c28fa5ff9685df1ab0a498116edcd5b8a637ba3cdb4e18e36813e957aa05dd113a22c96eca60ca9a9c5ecffc2484fd590b1bec5f56a
6
+ metadata.gz: 90c18d256c11014101dc39559572369b34973c362412313a25b3efff62c8b389382477e5c62b12bbe46343c8f8e45f9e1f2ff59394eb3cd53aad5caedb9d8fbc
7
+ data.tar.gz: 83c5e113ecc103bba694edf878ebf077ce7fc00566b3128a970300be1407f539e61d4c2cccff8911ddefc7567a88c9cb2fb17b33761750e525f6cff1b36c9c34
data/README.md CHANGED
@@ -71,58 +71,86 @@ Assert comes with a stubbing API - all it does is replace method calls. In gene
71
71
  * no methods are added to `Object` to support stubbing
72
72
  * stubs are auto-unstubbed on test teardown
73
73
 
74
- **Note**: Assert's stubbing logic has been extracted into a separate gem: [MuchStub](https://github.com/redding/much-stub/#muchstub). However, the main `Assert.{stub|unstub|stub_send|etc}` api is still available (it just proxies MuchStub now).
74
+ **Note**: Assert's stubbing logic has been extracted into a separate gem: [MuchStub](https://github.com/redding/much-stub/#muchstub). However, the main `Assert.{stub|unstub|stub_send|stub_tap|etc}` api is still available (it just proxies to MuchStub now).
75
75
 
76
76
  ```ruby
77
77
  myclass = Class.new do
78
- def mymeth; "meth"; end
79
- def myval(val); val; end
78
+ def my_method
79
+ "my_method"
80
+ end
81
+
82
+ def my_value(value)
83
+ value
84
+ end
80
85
  end
81
- myobj = myclass.new
86
+ my_object = myclass.new
82
87
 
83
- myobj.mymeth
84
- # => "meth"
85
- myobj.myval(123)
88
+ my_object.my_method
89
+ # => "my_method"
90
+ my_object.my_value(123)
86
91
  # => 123
87
- myobj.myval(456)
92
+ my_object.my_value(456)
88
93
  # => 456
89
94
 
90
- Assert.stub(myobj, :mymeth)
91
- myobj.mymeth
92
- # => StubError: `mymeth` not stubbed.
93
- Assert.stub(myobj, :mymeth){ "stub-meth" }
94
- myobj.mymeth
95
+ Assert.stub(my_object, :my_method)
96
+ my_object.my_method
97
+ # => StubError: `my_method` not stubbed.
98
+ Assert.stub(my_object, :my_method){ "stub-meth" }
99
+ my_object.my_method
95
100
  # => "stub-meth"
96
- myobj.mymeth(123)
101
+ my_object.my_method(123)
97
102
  # => StubError: arity mismatch
98
- Assert.stub(myobj, :mymeth).with(123){ "stub-meth" }
103
+ Assert.stub(my_object, :my_method).with(123){ "stub-meth" }
99
104
  # => StubError: arity mismatch
100
- Assert.stub_send(myobj, :mymeth) # call to the original method post-stub
101
- # => "meth"
102
105
 
103
- Assert.stub(myobj, :myval){ "stub-meth" }
106
+ # Call the original method after it has been stubbed.
107
+ Assert.stub_send(my_object, :my_method)
108
+ # => "my_method"
109
+
110
+ Assert.stub(my_object, :my_value){ "stub-meth" }
104
111
  # => StubError: arity mismatch
105
- Assert.stub(myobj, :myval).with(123){ |val| val.to_s }
106
- myobj.myval
112
+ Assert.stub(my_object, :my_value).with(123){ |val| val.to_s }
113
+ my_object.my_value
107
114
  # => StubError: arity mismatch
108
- myobj.myval(123)
115
+ my_object.my_value(123)
109
116
  # => "123"
110
- myobj.myval(456)
111
- # => StubError: `myval(456)` not stubbed.
112
- Assert.stub_send(myobj, :myval, 123) # call to the original method post-stub
117
+ my_object.my_value(456)
118
+ # => StubError: `my_value(456)` not stubbed.
119
+
120
+ # Call the original method after it has been stubbed.
121
+ Assert.stub_send(my_object, :my_value, 123)
113
122
  # => 123
114
- Assert.stub_send(myobj, :myval, 456)
123
+ Assert.stub_send(my_object, :my_value, 456)
115
124
  # => 456
116
125
 
117
- Assert.unstub(myobj, :mymeth)
118
- Assert.unstub(myobj, :myval)
126
+ # Stub a method while preserving its behavior and return value.
127
+ my_value_called_with = nil
128
+ Assert.stub_tap(my_object, :my_value) { |value, *args|
129
+ my_value_called_with = args
130
+ Assert.stub(value, :to_s) { "FIREWORKS!" }
131
+ }
132
+ value = my_object.my_value(123)
133
+ # => 123
134
+ my_value_called_with
135
+ # => [123]
136
+ value.to_s
137
+ # =>"FIREWORKS!"
138
+
139
+ # Unstub individual stubs
140
+ Assert.unstub(my_object, :my_method)
141
+ Assert.unstub(my_object, :my_value)
142
+
143
+ # OR blanket unstub all stubs
144
+ Assert.unstub!
119
145
 
120
- myobj.mymeth
121
- # => "meth"
122
- myobj.myval(123)
146
+ my_object.my_method
147
+ # => "my_method"
148
+ my_object.my_value(123)
123
149
  # => 123
124
- myobj.myval(456)
150
+ value = my_object.my_value(456)
125
151
  # => 456
152
+ value.to_s
153
+ # => "456"
126
154
  ```
127
155
 
128
156
  ## Factory
@@ -21,5 +21,5 @@ Gem::Specification.new do |gem|
21
21
  gem.required_ruby_version = "~> 2.4"
22
22
 
23
23
  gem.add_dependency("much-factory", ["~> 0.1.0"])
24
- gem.add_dependency("much-stub", ["~> 0.1.1"])
24
+ gem.add_dependency("much-stub", ["~> 0.1.2"])
25
25
  end
@@ -26,4 +26,8 @@ module Assert
26
26
  raise err
27
27
  end
28
28
  end
29
+
30
+ def self.stub_tap(*args, &block)
31
+ MuchStub.tap(*args, &block)
32
+ end
29
33
  end
@@ -1,3 +1,3 @@
1
1
  module Assert
2
- VERSION = "2.18.0"
2
+ VERSION = "2.18.1"
3
3
  end
@@ -104,5 +104,15 @@ module Assert
104
104
  assert_equal @stub_value, @myobj.mymeth
105
105
  assert_equal @orig_value, Assert.stub_send(@myobj, :mymeth)
106
106
  end
107
+
108
+ should "be able to add a stub tap" do
109
+ my_meth_called_with = nil
110
+ Assert.stub_tap(@myobj, :mymeth){ |value, *args, &block|
111
+ my_meth_called_with = args
112
+ }
113
+
114
+ assert_equal @orig_value, @myobj.mymeth
115
+ assert_equal [], my_meth_called_with
116
+ end
107
117
  end
108
118
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assert
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.18.0
4
+ version: 2.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-12-22 00:00:00.000000000 Z
12
+ date: 2020-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: much-factory
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: 0.1.1
34
+ version: 0.1.2
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: 0.1.1
41
+ version: 0.1.2
42
42
  description: Assertion style testing framework.
43
43
  email:
44
44
  - kelly@kellyredding.com