ddt 0.1.2 → 1.0.0
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 +8 -8
- data/README.md +37 -0
- data/lib/truth_test/truth_test.rb +25 -0
- data/lib/version/version.rb +3 -3
- data/spec/truth_test/module_truth_test_spec.rb +13 -0
- data/spec/truth_test/truth_test_spec.rb +13 -0
- data/truths/cat/pick_up_truths.yaml +9 -0
- data/truths/upcaseify/raises_truths.yaml +9 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWI2ZWRmNjkyODY5NWNlMzc4NWJhNGE2OTEyMjViYTU3YzFlMzk0Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjVlOTRiNjUzNDA3NzE5YTA0Y2MxMzdhZjczYzU1NmEwYTYyYmYyNA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmFjYjZmOTlhODJlNzRlMWNmYzU2NTI1OWU2ZjFmZTUwMWU3MDg0NDE3OTMz
|
10
|
+
NTgxNmVkM2ZhODQ1ZThhYTMzOTc0YWM2OTI5Mjc5OGFiNzY4MGRjZjQ3MGZm
|
11
|
+
OTE3N2ZhNjI5Y2M2MDQ4NDY0MjAxNDQxNTYxZmU5YWU5YmJiYmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODg5ZjZiYTJkMTYyMzIxNTc5OGRlNGNjMGNhNWVmOWQyYmQyYzU4NGIxMGM3
|
14
|
+
NzhiNjMxOTc5Zjc4M2JlZmM1YmFlOTZlYzkzZWQ3NDI4MjE5NGQ5ZjEzZWM5
|
15
|
+
YTVlYjlkNDU3MGI1MjE0NTMwZTU5NGNhN2Y3OWU4YTIzMGMwZGU=
|
data/README.md
CHANGED
@@ -194,6 +194,43 @@ It's also possible to use RSpec's stubbing to do this:
|
|
194
194
|
|
195
195
|
Wolf::Truth.should_receive(:tester).and_return(Wolf.new "draw blood")
|
196
196
|
|
197
|
+
## Testing for exceptions
|
198
|
+
|
199
|
+
The key `'!raises'` in your truth file for a given input specifies that
|
200
|
+
that input should raise an exception. The value specifies the type of
|
201
|
+
exception. If the value is 'true', then any type of exception is acceptable.
|
202
|
+
|
203
|
+
Example:
|
204
|
+
|
205
|
+
```
|
206
|
+
class Cat
|
207
|
+
# my cat does NOT like to be picked up
|
208
|
+
def pick_up str
|
209
|
+
if str == 'just kidding'
|
210
|
+
'a-ok'
|
211
|
+
elsif str == 'by the tail'
|
212
|
+
# raise a ZeroDivisionError because this is a bad idea
|
213
|
+
1/0
|
214
|
+
else
|
215
|
+
raise ArgumentError, 'DO NOT PICK ME UP'
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
```
|
220
|
+
|
221
|
+
Corresponding truth file:
|
222
|
+
```
|
223
|
+
---
|
224
|
+
input: 'just kidding'
|
225
|
+
output: 'a-ok'
|
226
|
+
---
|
227
|
+
input: 'by the tail'
|
228
|
+
'!raises': ZeroDivisionError
|
229
|
+
---
|
230
|
+
input: 'in any way at all'
|
231
|
+
'!raises': true
|
232
|
+
```
|
233
|
+
|
197
234
|
## Contributing
|
198
235
|
|
199
236
|
The usual github process applies here:
|
@@ -39,6 +39,7 @@ module DDT
|
|
39
39
|
# :define_method and also allow access to the_klass
|
40
40
|
klass.send(:define_method, :initialize) do |data={}|
|
41
41
|
data.each_pair do |attr, value|
|
42
|
+
next if attr == '!raises'
|
42
43
|
instance_variable_set "@#{attr}", value
|
43
44
|
self.class.send(:attr_accessor, attr.to_sym)
|
44
45
|
end
|
@@ -79,12 +80,18 @@ module DDT
|
|
79
80
|
# ---
|
80
81
|
# input: bam
|
81
82
|
# bar: baz bam
|
83
|
+
# ---
|
84
|
+
# input: uh-oh
|
85
|
+
# '!raises': true
|
82
86
|
#
|
83
87
|
# # foo.rb
|
84
88
|
# class Foo
|
85
89
|
# attr_accessor :bar
|
86
90
|
#
|
87
91
|
# def do_stuff input
|
92
|
+
# if input == 'uh-oh'
|
93
|
+
# raise ArgumentError, 'This input raises an error'
|
94
|
+
# end
|
88
95
|
# @bar = "baz #{input}"
|
89
96
|
# end
|
90
97
|
# end
|
@@ -136,6 +143,24 @@ module DDT
|
|
136
143
|
next
|
137
144
|
end
|
138
145
|
|
146
|
+
# test for an exception to be raised if the datum has a '!raise'
|
147
|
+
# key that is set to true
|
148
|
+
if datum.has_key?('!raises')
|
149
|
+
if datum['!raises'] == true
|
150
|
+
# true -> raise any kind of error
|
151
|
+
it "should raise an error when called as '#{method}(#{truth.input})'" do
|
152
|
+
expect{ truth.tester.send(method, truth.input) }.to raise_error
|
153
|
+
end
|
154
|
+
next
|
155
|
+
else
|
156
|
+
# specific value -> interpret that as an error class
|
157
|
+
it "should raise an error of type #{datum['!raises']} when called as '#{method}(#{truth.input})'" do
|
158
|
+
expect{ truth.tester.send(method, truth.input) }.to raise_error(Kernel.const_get(datum['!raises']))
|
159
|
+
end
|
160
|
+
next
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
139
164
|
if datum.has_key?("output")
|
140
165
|
it "should respond to '#{method}(#{truth.input})' with '#{truth.output}'" do
|
141
166
|
truth.tester.send(method, truth.input).should == truth.output
|
data/lib/version/version.rb
CHANGED
@@ -6,6 +6,18 @@ module Upcaseify
|
|
6
6
|
def do str
|
7
7
|
str.upcase
|
8
8
|
end
|
9
|
+
|
10
|
+
# to test '!raises'
|
11
|
+
def raises str
|
12
|
+
if str == 'only this input does not produce an error'
|
13
|
+
'a-ok'
|
14
|
+
elsif str == 'zero-division'
|
15
|
+
# raise a ZeroDivisionError
|
16
|
+
1/0
|
17
|
+
else
|
18
|
+
raise ArgumentError, 'This method is supposed to raise an error'
|
19
|
+
end
|
20
|
+
end
|
9
21
|
end
|
10
22
|
|
11
23
|
Upcaseify::define_truth
|
@@ -39,4 +51,5 @@ end
|
|
39
51
|
|
40
52
|
describe Upcaseify do
|
41
53
|
truth_test :do
|
54
|
+
truth_test :raises
|
42
55
|
end
|
@@ -41,6 +41,18 @@ class Cat
|
|
41
41
|
end
|
42
42
|
predisposition
|
43
43
|
end
|
44
|
+
|
45
|
+
# for testing '!raises'
|
46
|
+
def pick_up str
|
47
|
+
if str == 'just kidding'
|
48
|
+
'a-ok'
|
49
|
+
elsif str == 'by the tail'
|
50
|
+
# raise a ZeroDivisionError
|
51
|
+
1/0
|
52
|
+
else
|
53
|
+
raise ArgumentError, 'DO NOT PICK ME UP'
|
54
|
+
end
|
55
|
+
end
|
44
56
|
end
|
45
57
|
|
46
58
|
# a class that we'll define a specific tester for
|
@@ -93,6 +105,7 @@ end
|
|
93
105
|
# this way we know that a truth was automatically defined
|
94
106
|
describe Cat do
|
95
107
|
truth_test :pet
|
108
|
+
truth_test :pick_up
|
96
109
|
end
|
97
110
|
|
98
111
|
# tests for truth_test
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Swain
|
@@ -24,8 +24,10 @@ files:
|
|
24
24
|
- spec/truth_test/module_truth_test_spec.rb
|
25
25
|
- spec/truth_test/truth_test_spec.rb
|
26
26
|
- truths/cat/pet_truths.yaml
|
27
|
+
- truths/cat/pick_up_truths.yaml
|
27
28
|
- truths/dog/parse!_truths.yaml
|
28
29
|
- truths/upcaseify/do_truths.yaml
|
30
|
+
- truths/upcaseify/raises_truths.yaml
|
29
31
|
- LICENSE
|
30
32
|
- Rakefile
|
31
33
|
- README.md
|
@@ -58,5 +60,7 @@ test_files:
|
|
58
60
|
- spec/truth_test/module_truth_test_spec.rb
|
59
61
|
- spec/truth_test/truth_test_spec.rb
|
60
62
|
- truths/cat/pet_truths.yaml
|
63
|
+
- truths/cat/pick_up_truths.yaml
|
61
64
|
- truths/dog/parse!_truths.yaml
|
62
65
|
- truths/upcaseify/do_truths.yaml
|
66
|
+
- truths/upcaseify/raises_truths.yaml
|