rspec-todo 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 5dd31131ee403a76e605cecfedcc10fabc021471
4
- data.tar.gz: fcb29ec1bf71a68d1c8fe6cec08330e62dec6bd4
3
+ metadata.gz: 6764d77a1678c01bcb539d36765616f320bc4dac
4
+ data.tar.gz: a83e031ba64123414a56157352b8f50163c96c3b
5
5
  SHA512:
6
- metadata.gz: ae826bd4f4c505688ae5e4a86749dcc62768c81ca70d1405f2b789013c7028f0b4799b31ed8eb6142740440d314363e8f79a3350819c8576891408293ce28f2f
7
- data.tar.gz: a5ecad56e6c3e04d4cc3f1390f185067b158881a8882e849a28375bf32cde62f3171b0df4c80380edccac12c568941b4ccebeb3722bfe5d90e1439b520715b1b
6
+ metadata.gz: 2d600f60892ad3aac75b23f72f2a96d9a5d817ce97230979a87cd87f1b48094ac7fec9f2d02e82ae7cc6e7cc4be223e5f9ca6992245b1a7eca15d4dfd4b7d110
7
+ data.tar.gz: d215d3693a6095caf5c7919b6d36ab9ce03642f0a00bd7b09b637614888554613a54298f4d5e65d4b8b5e6c1853a652f80fb3bcda13513611f301a78845bfb40
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # Rspec::Todo [![Build Status](https://travis-ci.org/okitan/rspec-todo.png?branch=master)](https://travis-ci.org/okitan/rspec-todo)
2
2
 
3
- todo: pending if failed
4
- not_todo: result errors if passed
3
+ * todo
4
+ * pending if failed
5
+ * not_todo
6
+ * result errors if passed
5
7
 
6
8
  ## Installation
7
9
 
@@ -40,6 +42,32 @@ describe "rspec-todo" do
40
42
  end
41
43
  ```
42
44
 
45
+ ### if: and unless:
46
+
47
+ switch use to_do and not to_do with options.
48
+
49
+
50
+ ```ruby
51
+ it "todo results pending if failed and if: is true" do
52
+ todo(if: true) {
53
+ # your code which may fail and will fix later
54
+ }
55
+ end
56
+
57
+ it "todo ignored if if: is true" do
58
+ todo(if: false) { # todo is ignored and expectation is evaled directly
59
+ }
60
+ end
61
+ ```
62
+
63
+ ## Comparison
64
+
65
+ | methods | no errors (passed) | raise error (failed) |
66
+ |----------|-------------|-------------|
67
+ | pending | failure | pending |
68
+ | todo | success | pending |
69
+ | not_todo | failure | success |
70
+
43
71
  ## Contributing
44
72
 
45
73
  1. Fork it
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -1,36 +1,58 @@
1
+ require "tapp"
2
+
1
3
  module RSpec
2
4
  module Todo
3
- def todo(reason = nil, &block)
4
- if block_given?
5
- begin
6
- yield
7
- rescue => e
8
- if reason
9
- pending(reason)
10
- else
11
- pending(e.inspect)
5
+ def rspec_todo_works_for(opts = {})
6
+ if opts[:if].nil? && opts[:unless].nil?
7
+ true
8
+ else
9
+ opts[:if] || (opts[:unless].nil? ? false : !opts[:unless])
10
+ end
11
+ end
12
+
13
+ def todo(reason = nil, opts = {}, &block)
14
+ reason, opts = nil, reason if reason.is_a?(Hash)
15
+
16
+ if rspec_todo_works_for(opts)
17
+ if block_given?
18
+ begin
19
+ yield
20
+ rescue => e
21
+ if reason
22
+ pending(reason)
23
+ else
24
+ pending(e.inspect)
25
+ end
12
26
  end
27
+ else
28
+ pending(reason)
13
29
  end
14
30
  else
15
- pending(reason)
31
+ yield
16
32
  end
17
33
  end
18
34
 
19
- def not_todo(reason = nil, *errors_expected, &block)
20
- if block_given?
21
- begin
22
- yield
23
- rescue RSpec::Expectations::ExpectationNotMetError, *errors_expected => e
24
- # do nothing
25
- else
26
- if reason
27
- raise(reason)
35
+ def not_todo(reason = nil, opts = {}, &block)
36
+ reason, opts = nil, reason if reason.is_a?(Hash)
37
+
38
+ if rspec_todo_works_for(opts)
39
+ if block_given?
40
+ begin
41
+ yield
42
+ rescue RSpec::Expectations::ExpectationNotMetError, *opts[:errors] => e
43
+ # do nothing
28
44
  else
29
- raise "not todo but passed"
45
+ if reason
46
+ raise(reason)
47
+ else
48
+ raise "not todo but passed"
49
+ end
30
50
  end
51
+ else
52
+ pending(reason)
31
53
  end
32
54
  else
33
- pending(reason)
55
+ yield
34
56
  end
35
57
  end
36
58
  end
@@ -1,45 +1,264 @@
1
1
  require "spec_helper"
2
2
 
3
+ shared_examples "pending" do |sub_description, opts = {}|
4
+ context(sub_description, opts) do
5
+ it "works" do
6
+ begin
7
+ expect { expectation }.to raise_exception(pending_exception)
8
+ ensure
9
+ # if not example comes to be pending and cannot determine green or red
10
+ example.metadata[:pending] = false
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ shared_examples "being passed" do |sub_description, opts = {}|
17
+ context(sub_description, opts) do
18
+ it "works" do
19
+ expectation
20
+ end
21
+ end
22
+ end
23
+
24
+ shared_examples "error" do |sub_description, opts = {}|
25
+ context(sub_description, opts) do
26
+ it "works" do
27
+ begin
28
+ expect { expectation }.to raise_exception {|exception|
29
+ exception.should_not be_a(pending_exception)
30
+ }
31
+ ensure
32
+ # if not example may come to be pending and cannot detect failre
33
+ example.metadata[:pending] = false
34
+ end
35
+ end
36
+ end
37
+ end
38
+
3
39
  describe "rspec-todo" do
40
+ let(:pending_exception) { ::RSpec::Core::Pending::PendingDeclaredInExample }
41
+
42
+ context "#rspec_todo_works_for" do
43
+ [ [ true, true, true ],
44
+ [ true, false, true ],
45
+ [ true, nil, true ],
46
+ [ false, true, false ],
47
+ [ false, false, true ],
48
+ [ false, nil, false ],
49
+ [ nil, true, false ],
50
+ [ nil, false, true ],
51
+ [ nil, nil, true ],
52
+ ].each do |if_value, unless_value, result|
53
+ it "returns #{result} when if is #{if_value.inspect} and unless is #{unless_value.inspect}" do
54
+ rspec_todo_works_for(if: if_value, unless: unless_value).should == result
55
+ end
56
+ end
57
+ end
58
+
4
59
  context "todo" do
5
60
  context "with description" do
6
- it "becomes pending if failed" do
7
- todo("will raise hoge") { raise "hoge" }
61
+ it_behaves_like "pending", "when expectation failed" do
62
+ let(:expectation) do
63
+ todo("with raise hoge") { raise "hoge" }
64
+ end
8
65
  end
9
66
  end
10
67
 
11
68
  context "without description" do
12
- it "passes" do
13
- todo { true }
69
+ it_behaves_like "being passed", "when expectation succeeded" do
70
+ let(:expectation) do
71
+ todo { true }
72
+ end
73
+ end
74
+
75
+ it_behaves_like "pending", "when expectation failed" do
76
+ let(:expectation) do
77
+ todo { raise "hoge" }
78
+ end
14
79
  end
80
+ end
81
+
82
+ context "with if opts" do
83
+ context "are true" do
84
+ it_behaves_like "being passed", "when expectation succeeded" do
85
+ let(:expectation) do
86
+ todo(if: true) { true }
87
+ end
88
+ end
15
89
 
16
- it "becomes pending if failed" do
17
- todo { raise "hoge" }
90
+ it_behaves_like "pending", "when expectation failed" do
91
+ let(:expectation) do
92
+ todo(if: true) { raise "hoge" }
93
+ end
94
+ end
95
+ end
96
+
97
+ context "are false" do
98
+ it_behaves_like "being passed", "when expectation succeeded" do
99
+ let(:expectation) do
100
+ todo(if: false) { true }
101
+ end
102
+ end
103
+
104
+ it_behaves_like "error", "when expectation failed" do
105
+ let(:expectation) do
106
+ todo(if: false) { raise "hoge" }
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ context "with unless opts" do
113
+ context "are false" do
114
+ it_behaves_like "being passed", "when expectation succeeded" do
115
+ let(:expectation) do
116
+ todo(unless: false) { true }
117
+ end
118
+ end
119
+
120
+ it_behaves_like "pending", "when expectation failed" do
121
+ let(:expectation) do
122
+ todo(unless: false) { raise "hoge" }
123
+ end
124
+ end
125
+ end
126
+
127
+ context "are true" do
128
+ it_behaves_like "being passed", "when expectation succeeded" do
129
+ let(:expectation) do
130
+ todo(unless: true) { true }
131
+ end
132
+ end
133
+
134
+ it_behaves_like "error", "when expectation failed" do
135
+ let(:expectation) do
136
+ todo(unless: true) { raise "hoge" }
137
+ end
138
+ end
18
139
  end
19
140
  end
20
141
  end
21
142
 
22
143
  context "not todo" do
23
- it "result error if successed" do
24
- expect {
144
+ it_behaves_like "error", "when succeeded" do
145
+ let(:expectation) do
25
146
  not_todo { true }
26
- }.to raise_exception
147
+ end
27
148
  end
28
149
 
29
- it "results nothing when expectation not matched" do
30
- not_todo { 1.should == 2 }
150
+ it_behaves_like "being passed", "when expectation not matched" do
151
+ let(:expectation) do
152
+ not_todo { 1.should == 2 }
153
+ end
31
154
  end
32
155
 
33
- it "results nothing when specified error occured" do
34
- not_todo("runtime error occured", RuntimeError) do
35
- raise
156
+ context "when expectation raise exception" do
157
+ it_behaves_like "being passed", "when error is specified" do
158
+ let(:expectation) do
159
+ not_todo("runtime error occured", errors: RuntimeError) do
160
+ raise
161
+ end
162
+ end
163
+ end
164
+
165
+ it_behaves_like "being passed", "when errors are specified" do
166
+ let(:expectation) do
167
+ not_todo("runtime error occured", errors: [ RuntimeError ]) do
168
+ raise
169
+ end
170
+ end
171
+ end
172
+
173
+ it_behaves_like "error", "when errors are not specified" do
174
+ let(:expectation) do
175
+ not_todo { raise "unexpected" }
176
+ end
36
177
  end
37
178
  end
38
179
 
39
- it "results error if runtime error occured" do
40
- expect {
41
- not_todo { raise }
42
- }.to raise_exception
180
+ context "with if opts" do
181
+ context "are true" do
182
+ it_behaves_like "error", "when expectation succeeded" do
183
+ let(:expectation) do
184
+ not_todo(if: true) { true }
185
+ end
186
+ end
187
+
188
+ it_behaves_like "being passed", "when expectation failed" do
189
+ let(:expectation) do
190
+ not_todo(if: true) { 1.should == 2 }
191
+ end
192
+ end
193
+
194
+ it_behaves_like "being passed", "when errors are specified" do
195
+ let(:expectation) do
196
+ not_todo(if: true, errors: RuntimeError) { raise }
197
+ end
198
+ end
199
+ end
200
+
201
+ context "are false" do
202
+ it_behaves_like "being passed", "when expectation succeeded" do
203
+ let(:expectation) do
204
+ not_todo(if: false) { true }
205
+ end
206
+ end
207
+
208
+ it_behaves_like "error", "when expectation failed" do
209
+ let(:expectation) do
210
+ not_todo(if: false) { 1.should == 2 }
211
+ end
212
+ end
213
+
214
+ it_behaves_like "error", "even if errors are specified" do
215
+ let(:expectation) do
216
+ not_todo(if: false, errors: RuntimeError) { raise }
217
+ end
218
+ end
219
+ end
220
+ end
221
+
222
+ context "with unless opts" do
223
+ context "are false" do
224
+ it_behaves_like "error", "when expectation succeeded" do
225
+ let(:expectation) do
226
+ not_todo(unless: false) { true }
227
+ end
228
+ end
229
+
230
+ it_behaves_like "being passed", "when expectation failed" do
231
+ let(:expectation) do
232
+ not_todo(unless: false) { 1.should == 2 }
233
+ end
234
+ end
235
+
236
+ it_behaves_like "being passed", "when errors are specified" do
237
+ let(:expectation) do
238
+ not_todo(unless: false, errors: RuntimeError) { raise }
239
+ end
240
+ end
241
+ end
242
+
243
+ context "are true" do
244
+ it_behaves_like "being passed", "when expectation succeeded" do
245
+ let(:expectation) do
246
+ not_todo(unless: true) { true }
247
+ end
248
+ end
249
+
250
+ it_behaves_like "error", "when expectation failed" do
251
+ let(:expectation) do
252
+ not_todo(unless: true) { 1.should == 2 }
253
+ end
254
+ end
255
+
256
+ it_behaves_like "error", "even if errors are specified" do
257
+ let(:expectation) do
258
+ not_todo(unless: true, errors: RuntimeError) { raise }
259
+ end
260
+ end
261
+ end
43
262
  end
44
263
  end
45
264
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-todo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - okitan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-06 00:00:00.000000000 Z
11
+ date: 2013-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec