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 +4 -4
- data/README.md +59 -31
- data/assert.gemspec +1 -1
- data/lib/assert/stub.rb +4 -0
- data/lib/assert/version.rb +1 -1
- data/test/unit/assert_tests.rb +10 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea0650f5a320e5717749a864de46a1864eb5ba3bb0e308d5a1566734f390360c
|
4
|
+
data.tar.gz: 4745c715d058de3dfd306dd920de2c8a59653564349d71e9a712bd2f9e0d5291
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
79
|
-
|
78
|
+
def my_method
|
79
|
+
"my_method"
|
80
|
+
end
|
81
|
+
|
82
|
+
def my_value(value)
|
83
|
+
value
|
84
|
+
end
|
80
85
|
end
|
81
|
-
|
86
|
+
my_object = myclass.new
|
82
87
|
|
83
|
-
|
84
|
-
# => "
|
85
|
-
|
88
|
+
my_object.my_method
|
89
|
+
# => "my_method"
|
90
|
+
my_object.my_value(123)
|
86
91
|
# => 123
|
87
|
-
|
92
|
+
my_object.my_value(456)
|
88
93
|
# => 456
|
89
94
|
|
90
|
-
Assert.stub(
|
91
|
-
|
92
|
-
# => StubError: `
|
93
|
-
Assert.stub(
|
94
|
-
|
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
|
-
|
101
|
+
my_object.my_method(123)
|
97
102
|
# => StubError: arity mismatch
|
98
|
-
Assert.stub(
|
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
|
-
|
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(
|
106
|
-
|
112
|
+
Assert.stub(my_object, :my_value).with(123){ |val| val.to_s }
|
113
|
+
my_object.my_value
|
107
114
|
# => StubError: arity mismatch
|
108
|
-
|
115
|
+
my_object.my_value(123)
|
109
116
|
# => "123"
|
110
|
-
|
111
|
-
# => StubError: `
|
112
|
-
|
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(
|
123
|
+
Assert.stub_send(my_object, :my_value, 456)
|
115
124
|
# => 456
|
116
125
|
|
117
|
-
|
118
|
-
|
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
|
-
|
121
|
-
# => "
|
122
|
-
|
146
|
+
my_object.my_method
|
147
|
+
# => "my_method"
|
148
|
+
my_object.my_value(123)
|
123
149
|
# => 123
|
124
|
-
|
150
|
+
value = my_object.my_value(456)
|
125
151
|
# => 456
|
152
|
+
value.to_s
|
153
|
+
# => "456"
|
126
154
|
```
|
127
155
|
|
128
156
|
## Factory
|
data/assert.gemspec
CHANGED
data/lib/assert/stub.rb
CHANGED
data/lib/assert/version.rb
CHANGED
data/test/unit/assert_tests.rb
CHANGED
@@ -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.
|
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:
|
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.
|
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.
|
41
|
+
version: 0.1.2
|
42
42
|
description: Assertion style testing framework.
|
43
43
|
email:
|
44
44
|
- kelly@kellyredding.com
|