dchelimsky-rspec 1.1.10 → 1.1.11
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.
- data/History.txt +17 -0
- data/Manifest.txt +53 -74
- data/Rakefile +0 -1
- data/examples/{pure → passing}/autogenerated_docstrings_example.rb +6 -0
- data/examples/{pure → passing}/before_and_after_example.rb +0 -0
- data/examples/{pure → passing}/behave_as_example.rb +0 -0
- data/examples/{pure → passing}/custom_expectation_matchers.rb +0 -0
- data/examples/{pure → passing}/custom_formatter.rb +1 -1
- data/examples/{pure → passing}/dynamic_spec.rb +2 -2
- data/examples/{pure → passing}/file_accessor.rb +0 -0
- data/examples/{pure → passing}/file_accessor_spec.rb +0 -0
- data/examples/{pure → passing}/greeter_spec.rb +0 -0
- data/examples/{pure → passing}/helper_method_example.rb +0 -0
- data/examples/{pure → passing}/io_processor.rb +0 -0
- data/examples/{pure → passing}/io_processor_spec.rb +0 -0
- data/examples/{pure → passing}/legacy_spec.rb +0 -0
- data/examples/{pure → passing}/mocking_example.rb +0 -0
- data/examples/{pure → passing}/multi_threaded_behaviour_runner.rb +0 -0
- data/examples/{pure → passing}/nested_classes_example.rb +0 -0
- data/examples/{pure → passing}/partial_mock_example.rb +0 -0
- data/examples/{pure → passing}/pending_example.rb +0 -0
- data/examples/{pure → passing}/predicate_example.rb +0 -0
- data/examples/{pure → passing}/priority.txt +0 -0
- data/examples/{pure → passing}/shared_example_group_example.rb +0 -0
- data/examples/{pure → passing}/shared_stack_examples.rb +1 -3
- data/examples/{pure → passing}/spec_helper.rb +0 -0
- data/examples/{pure → passing}/stack.rb +0 -0
- data/examples/{pure → passing}/stack_spec.rb +3 -2
- data/examples/{pure → passing}/stack_spec_with_nested_example_groups.rb +0 -0
- data/examples/{pure → passing}/stubbing_example.rb +0 -0
- data/examples/{pure → passing}/yielding_example.rb +0 -0
- data/lib/spec/example/before_and_after_hooks.rb +8 -21
- data/lib/spec/example/configuration.rb +45 -45
- data/lib/spec/example/example_group_factory.rb +10 -9
- data/lib/spec/example/example_group_methods.rb +31 -15
- data/lib/spec/example/example_methods.rb +74 -22
- data/lib/spec/example/shared_example_group.rb +27 -16
- data/lib/spec/example.rb +28 -0
- data/lib/spec/expectations.rb +1 -0
- data/lib/spec/extensions.rb +0 -2
- data/lib/spec/matchers/be.rb +96 -114
- data/lib/spec/matchers/operator_matcher.rb +2 -9
- data/lib/spec/matchers/throw_symbol.rb +41 -15
- data/lib/spec/matchers.rb +4 -27
- data/lib/spec/runner/formatter/base_text_formatter.rb +1 -1
- data/lib/spec/runner/option_parser.rb +2 -2
- data/lib/spec/runner/reporter.rb +1 -1
- data/lib/spec/runner.rb +1 -1
- data/lib/spec/version.rb +1 -1
- data/lib/spec.rb +1 -0
- data/rspec.gemspec +4 -24
- data/spec/spec/example/example_group_factory_spec.rb +29 -9
- data/spec/spec/example/example_group_methods_spec.rb +4 -6
- data/spec/spec/example/example_group_spec.rb +0 -6
- data/spec/spec/example/example_matcher_spec.rb +6 -23
- data/spec/spec/example/example_methods_spec.rb +117 -2
- data/spec/spec/example/shared_example_group_spec.rb +51 -75
- data/spec/spec/matchers/be_spec.rb +40 -7
- data/spec/spec/matchers/description_generation_spec.rb +14 -0
- data/spec/spec/matchers/throw_symbol_spec.rb +83 -41
- data/spec/spec/runner/command_line_spec.rb +4 -4
- data/spec/spec/runner/formatter/html_formatted-1.8.4.html +6 -6
- data/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html +9 -9
- data/spec/spec/runner/formatter/html_formatted-1.8.5.html +6 -6
- data/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html +10 -10
- data/spec/spec/runner/formatter/html_formatted-1.8.6.html +6 -6
- data/spec/spec/runner/formatter/html_formatter_spec.rb +1 -1
- data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +5 -5
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html +6 -6
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +6 -6
- data/spec/spec/runner/reporter_spec.rb +1 -1
- data/stories/example_groups/autogenerated_docstrings +4 -4
- data/stories/example_groups/nested_groups +2 -2
- metadata +33 -59
- data/examples/stories/adder.rb +0 -13
- data/examples/stories/addition +0 -34
- data/examples/stories/addition.rb +0 -9
- data/examples/stories/calculator.rb +0 -65
- data/examples/stories/game-of-life/.loadpath +0 -5
- data/examples/stories/game-of-life/README.txt +0 -21
- data/examples/stories/game-of-life/behaviour/everything.rb +0 -6
- data/examples/stories/game-of-life/behaviour/examples/examples.rb +0 -3
- data/examples/stories/game-of-life/behaviour/examples/game_behaviour.rb +0 -35
- data/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb +0 -66
- data/examples/stories/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story +0 -21
- data/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +0 -21
- data/examples/stories/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story +0 -42
- data/examples/stories/game-of-life/behaviour/stories/ICanCreateACell.story +0 -42
- data/examples/stories/game-of-life/behaviour/stories/ICanKillACell.story +0 -17
- data/examples/stories/game-of-life/behaviour/stories/TheGridWraps.story +0 -53
- data/examples/stories/game-of-life/behaviour/stories/create_a_cell.rb +0 -52
- data/examples/stories/game-of-life/behaviour/stories/helper.rb +0 -6
- data/examples/stories/game-of-life/behaviour/stories/kill_a_cell.rb +0 -26
- data/examples/stories/game-of-life/behaviour/stories/steps.rb +0 -5
- data/examples/stories/game-of-life/behaviour/stories/stories.rb +0 -3
- data/examples/stories/game-of-life/behaviour/stories/stories.txt +0 -22
- data/examples/stories/game-of-life/life/game.rb +0 -23
- data/examples/stories/game-of-life/life/grid.rb +0 -43
- data/examples/stories/game-of-life/life.rb +0 -3
- data/examples/stories/helper.rb +0 -9
- data/examples/stories/steps/addition_steps.rb +0 -18
- data/failing_examples/README.txt +0 -7
- data/failing_examples/diffing_spec.rb +0 -36
- data/failing_examples/failing_autogenerated_docstrings_example.rb +0 -19
- data/failing_examples/failure_in_setup.rb +0 -10
- data/failing_examples/failure_in_teardown.rb +0 -10
- data/failing_examples/mocking_example.rb +0 -40
- data/failing_examples/mocking_with_flexmock.rb +0 -26
- data/failing_examples/mocking_with_mocha.rb +0 -25
- data/failing_examples/mocking_with_rr.rb +0 -27
- data/failing_examples/partial_mock_example.rb +0 -20
- data/failing_examples/predicate_example.rb +0 -29
- data/failing_examples/raising_example.rb +0 -47
- data/failing_examples/spec_helper.rb +0 -3
- data/failing_examples/syntax_error_example.rb +0 -7
- data/failing_examples/team_spec.rb +0 -44
- data/failing_examples/timeout_behaviour.rb +0 -7
- data/lib/spec/extensions/main.rb +0 -87
- data/lib/spec/extensions/object.rb +0 -6
- data/spec/spec/extensions/main_spec.rb +0 -71
@@ -145,14 +145,129 @@ module Spec
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
describe "#
|
148
|
+
describe "#full_description" do
|
149
149
|
it "should return the full description of the ExampleGroup and Example" do
|
150
150
|
example_group = Class.new(ExampleGroup).describe("An ExampleGroup") do
|
151
151
|
it "should do something" do
|
152
152
|
end
|
153
153
|
end
|
154
154
|
example = example_group.examples.first
|
155
|
-
example.
|
155
|
+
example.full_description.should == "An ExampleGroup should do something"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "#subject" do
|
160
|
+
it "should return an instance variable named after the described type" do
|
161
|
+
example_group = describe(Array) do
|
162
|
+
example {}
|
163
|
+
end
|
164
|
+
example = example_group.examples.first
|
165
|
+
example.subject.should == []
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should not barf on a module (as opposed to a class)" do
|
169
|
+
example_group = Class.new(ExampleGroup).describe(ObjectSpace) do
|
170
|
+
example {}
|
171
|
+
end
|
172
|
+
example_group.examples.first.subject.should be_nil
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should not barf on a string" do
|
176
|
+
example_group = describe('foo') do
|
177
|
+
example {}
|
178
|
+
end
|
179
|
+
example_group.examples.first.subject.should be_nil
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "#should" do
|
184
|
+
with_sandboxed_options do
|
185
|
+
class Thing
|
186
|
+
def ==(other)
|
187
|
+
true
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "in an ExampleGroup with the ivar defined in before" do
|
192
|
+
attr_reader :example, :success
|
193
|
+
|
194
|
+
before(:each) do
|
195
|
+
example_group = describe(Thing, "1") do
|
196
|
+
before(:each) { @spec_example_thing = 'expected' }
|
197
|
+
it { should eql('expected') }
|
198
|
+
end
|
199
|
+
@example = example_group.examples.first
|
200
|
+
@success = example_group.run
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should create an example using the description from the matcher" do
|
204
|
+
example.description.should == 'should eql "expected"'
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should test the matcher returned from the block" do
|
208
|
+
success.should be_true
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "in an ExampleGroup with the subject defined using #subject" do
|
213
|
+
it "should create an example using the description from the matcher" do
|
214
|
+
example_group = describe(Thing, "2") do
|
215
|
+
subject {'this is the subject'}
|
216
|
+
it { should eql('this is the subject') }
|
217
|
+
end
|
218
|
+
example = example_group.examples.first
|
219
|
+
example_group.run
|
220
|
+
example.description.should =~ /should eql "this is the subject"/
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe "in an ExampleGroup using an implicit ivar" do
|
225
|
+
it "should create an example using the description from the matcher" do
|
226
|
+
example_group = describe(Thing, "3") do
|
227
|
+
it { should == Thing.new }
|
228
|
+
end
|
229
|
+
example = example_group.examples.first
|
230
|
+
success = example_group.run
|
231
|
+
example.description.should =~ /should == #<Spec::Example::Thing/
|
232
|
+
success.should be_true
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
after(:each) do
|
237
|
+
ExampleGroup.reset
|
238
|
+
end
|
239
|
+
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe "#should_not" do
|
244
|
+
with_sandboxed_options do
|
245
|
+
|
246
|
+
attr_reader :example_group, :example, :success
|
247
|
+
|
248
|
+
before do
|
249
|
+
@example_group = Class.new(ExampleGroup) do
|
250
|
+
def subject; @actual; end
|
251
|
+
before(:each) { @actual = 'expected' }
|
252
|
+
it { should_not eql('unexpected') }
|
253
|
+
end
|
254
|
+
@example = @example_group.examples.first
|
255
|
+
|
256
|
+
@success = example_group.run
|
257
|
+
end
|
258
|
+
|
259
|
+
it "should create an example using the description from the matcher" do
|
260
|
+
example.description.should == 'should not eql "unexpected"'
|
261
|
+
end
|
262
|
+
|
263
|
+
it "should test the matcher returned from the block" do
|
264
|
+
success.should be_true
|
265
|
+
end
|
266
|
+
|
267
|
+
after do
|
268
|
+
ExampleGroup.reset
|
269
|
+
end
|
270
|
+
|
156
271
|
end
|
157
272
|
end
|
158
273
|
end
|
@@ -17,46 +17,25 @@ module Spec
|
|
17
17
|
after(:each) do
|
18
18
|
@formatter.rspec_verify
|
19
19
|
@example_group = nil
|
20
|
-
Spec::Example::SharedExampleGroup.
|
21
|
-
end
|
22
|
-
|
23
|
-
def make_shared_example_group(name, opts=nil, &block)
|
24
|
-
example_group = SharedExampleGroup.new(name, :shared => true, &block)
|
25
|
-
SharedExampleGroup.add_shared_example_group(example_group)
|
26
|
-
example_group
|
27
|
-
end
|
28
|
-
|
29
|
-
def non_shared_example_group()
|
30
|
-
@non_shared_example_group ||= Class.new(ExampleGroup).describe("example_group")
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should accept an optional options hash" do
|
34
|
-
lambda { Class.new(ExampleGroup).describe("context") }.should_not raise_error(Exception)
|
35
|
-
lambda { Class.new(ExampleGroup).describe("context", :shared => true) }.should_not raise_error(Exception)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should return all shared example_groups" do
|
39
|
-
b1 = make_shared_example_group("b1", :shared => true) {}
|
40
|
-
b2 = make_shared_example_group("b2", :shared => true) {}
|
41
|
-
|
42
|
-
b1.should_not be(nil)
|
43
|
-
b2.should_not be(nil)
|
44
|
-
|
45
|
-
SharedExampleGroup.find_shared_example_group("b1").should equal(b1)
|
46
|
-
SharedExampleGroup.find_shared_example_group("b2").should equal(b2)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should register as shared example_group" do
|
50
|
-
example_group = make_shared_example_group("example_group") {}
|
51
|
-
SharedExampleGroup.shared_example_groups.should include(example_group)
|
20
|
+
Spec::Example::SharedExampleGroup.clear
|
52
21
|
end
|
22
|
+
|
23
|
+
describe "#register" do
|
24
|
+
it "creates a new shared example group with the submitted args" do
|
25
|
+
block = lambda {}
|
26
|
+
group = SharedExampleGroup.new("shared group") do end
|
27
|
+
Spec::Example::SharedExampleGroup.should_receive(:new).with("share me", &block).and_return(group)
|
28
|
+
Spec::Example::SharedExampleGroup.register("share me", &block)
|
29
|
+
end
|
53
30
|
|
54
|
-
|
55
|
-
|
56
|
-
|
31
|
+
it "registers the shared example group" do
|
32
|
+
lambda do
|
33
|
+
Spec::Example::SharedExampleGroup.register "share me" do end
|
34
|
+
end.should change {Spec::Example::SharedExampleGroup.count}.by(1)
|
35
|
+
end
|
57
36
|
end
|
58
37
|
|
59
|
-
it "
|
38
|
+
it "complains when adding a second shared example_group with the same description" do
|
60
39
|
describe "shared example_group", :shared => true do
|
61
40
|
end
|
62
41
|
lambda do
|
@@ -64,14 +43,17 @@ module Spec
|
|
64
43
|
end
|
65
44
|
end.should raise_error(ArgumentError)
|
66
45
|
end
|
67
|
-
|
68
|
-
it "
|
69
|
-
|
70
|
-
|
71
|
-
|
46
|
+
|
47
|
+
it "does NOT add the same group twice" do
|
48
|
+
lambda do
|
49
|
+
2.times do
|
50
|
+
describe "shared example_group which gets loaded twice", :shared => true do
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end.should change {Spec::Example::SharedExampleGroup.count}.by(1)
|
72
54
|
end
|
73
55
|
|
74
|
-
it "
|
56
|
+
it "does NOT complain when adding the same shared example_group again (i.e. file gets reloaded)" do
|
75
57
|
lambda do
|
76
58
|
2.times do
|
77
59
|
describe "shared example_group which gets loaded twice", :shared => true do
|
@@ -80,42 +62,36 @@ module Spec
|
|
80
62
|
end.should_not raise_error(ArgumentError)
|
81
63
|
end
|
82
64
|
|
83
|
-
it "
|
84
|
-
|
65
|
+
it "does NOT complain when adding the same shared example_group in same file with different absolute path" do
|
66
|
+
SharedExampleGroup.register(
|
85
67
|
"shared example_group",
|
86
68
|
:shared => true,
|
87
69
|
:spec_path => "/my/spec/a/../shared.rb"
|
88
70
|
)
|
89
|
-
|
71
|
+
SharedExampleGroup.register(
|
90
72
|
"shared example_group",
|
91
73
|
:shared => true,
|
92
74
|
:spec_path => "/my/spec/b/../shared.rb"
|
93
75
|
)
|
94
|
-
|
95
|
-
SharedExampleGroup.add_shared_example_group(shared_example_group_1)
|
96
|
-
SharedExampleGroup.add_shared_example_group(shared_example_group_2)
|
97
76
|
end
|
98
77
|
|
99
|
-
it "
|
100
|
-
|
78
|
+
it "complains when adding a different shared example_group with the same name in a different file with the same basename" do
|
79
|
+
SharedExampleGroup.register(
|
101
80
|
"shared example_group",
|
102
81
|
:shared => true,
|
103
82
|
:spec_path => "/my/spec/a/shared.rb"
|
104
83
|
)
|
105
|
-
shared_example_group_2 = Class.new(ExampleGroup).describe(
|
106
|
-
"shared example_group",
|
107
|
-
:shared => true,
|
108
|
-
:spec_path => "/my/spec/b/shared.rb"
|
109
|
-
)
|
110
|
-
|
111
|
-
SharedExampleGroup.add_shared_example_group(shared_example_group_1)
|
112
84
|
lambda do
|
113
|
-
SharedExampleGroup.
|
85
|
+
SharedExampleGroup.register(
|
86
|
+
"shared example_group",
|
87
|
+
:shared => true,
|
88
|
+
:spec_path => "/my/spec/b/shared.rb"
|
89
|
+
)
|
114
90
|
end.should raise_error(ArgumentError, /already exists/)
|
115
91
|
end
|
116
92
|
|
117
|
-
it "
|
118
|
-
shared_example_group =
|
93
|
+
it "adds examples to current example_group using it_should_behave_like" do
|
94
|
+
shared_example_group = SharedExampleGroup.register("shared example_group") do
|
119
95
|
it("shared example") {}
|
120
96
|
it("shared example 2") {}
|
121
97
|
end
|
@@ -126,12 +102,12 @@ module Spec
|
|
126
102
|
example_group.number_of_examples.should == 3
|
127
103
|
end
|
128
104
|
|
129
|
-
it "
|
130
|
-
shared_example_group_1 =
|
105
|
+
it "adds examples to from two shared groups" do
|
106
|
+
shared_example_group_1 = SharedExampleGroup.register("shared example_group 1") do
|
131
107
|
it("shared example 1") {}
|
132
108
|
end
|
133
109
|
|
134
|
-
shared_example_group_1 =
|
110
|
+
shared_example_group_1 = SharedExampleGroup.register("shared example_group 2") do
|
135
111
|
it("shared example 2") {}
|
136
112
|
end
|
137
113
|
|
@@ -141,7 +117,7 @@ module Spec
|
|
141
117
|
example_group.number_of_examples.should == 3
|
142
118
|
end
|
143
119
|
|
144
|
-
it "
|
120
|
+
it "adds examples to current example_group using include" do
|
145
121
|
shared_example_group = describe "all things", :shared => true do
|
146
122
|
it "should do stuff" do end
|
147
123
|
end
|
@@ -153,7 +129,7 @@ module Spec
|
|
153
129
|
example_group.number_of_examples.should == 1
|
154
130
|
end
|
155
131
|
|
156
|
-
it "
|
132
|
+
it "adds examples to current example_group using it_should_behave_like with a module" do
|
157
133
|
AllThings = describe "all things", :shared => true do
|
158
134
|
it "should do stuff" do end
|
159
135
|
end
|
@@ -165,9 +141,9 @@ module Spec
|
|
165
141
|
example_group.number_of_examples.should == 1
|
166
142
|
end
|
167
143
|
|
168
|
-
it "
|
144
|
+
it "runs shared examples" do
|
169
145
|
shared_example_ran = false
|
170
|
-
shared_example_group =
|
146
|
+
shared_example_group = SharedExampleGroup.register("shared example_group") do
|
171
147
|
it("shared example") { shared_example_ran = true }
|
172
148
|
end
|
173
149
|
|
@@ -180,12 +156,12 @@ module Spec
|
|
180
156
|
shared_example_ran.should be_true
|
181
157
|
end
|
182
158
|
|
183
|
-
it "
|
159
|
+
it "runs before(:each) and after(:each) from shared example_group" do
|
184
160
|
shared_setup_ran = false
|
185
161
|
shared_teardown_ran = false
|
186
|
-
shared_example_group =
|
187
|
-
before { shared_setup_ran = true }
|
188
|
-
after
|
162
|
+
shared_example_group = SharedExampleGroup.register("shared example_group") do
|
163
|
+
before(:each) { shared_setup_ran = true }
|
164
|
+
after(:each) { shared_teardown_ran = true }
|
189
165
|
it("shared example") { shared_example_ran = true }
|
190
166
|
end
|
191
167
|
|
@@ -202,9 +178,9 @@ module Spec
|
|
202
178
|
it "should run before(:all) and after(:all) only once from shared example_group" do
|
203
179
|
shared_before_all_run_count = 0
|
204
180
|
shared_after_all_run_count = 0
|
205
|
-
shared_example_group =
|
181
|
+
shared_example_group = SharedExampleGroup.register("shared example_group") do
|
206
182
|
before(:all) { shared_before_all_run_count += 1}
|
207
|
-
after(:all)
|
183
|
+
after(:all) { shared_after_all_run_count += 1}
|
208
184
|
it("shared example") { shared_example_ran = true }
|
209
185
|
end
|
210
186
|
|
@@ -221,7 +197,7 @@ module Spec
|
|
221
197
|
it "should include modules, included into shared example_group, into current example_group" do
|
222
198
|
@formatter.should_receive(:add_example_group).with(any_args)
|
223
199
|
|
224
|
-
shared_example_group =
|
200
|
+
shared_example_group = SharedExampleGroup.register("shared example_group") do
|
225
201
|
it("shared example") { shared_example_ran = true }
|
226
202
|
end
|
227
203
|
|
@@ -254,7 +230,7 @@ module Spec
|
|
254
230
|
end
|
255
231
|
|
256
232
|
it "should make methods defined in the shared example_group available in consuming example_group" do
|
257
|
-
shared_example_group =
|
233
|
+
shared_example_group = SharedExampleGroup.register("shared example_group xyz") do
|
258
234
|
def a_shared_helper_method
|
259
235
|
"this got defined in a shared example_group"
|
260
236
|
end
|
@@ -7,7 +7,7 @@ describe "should be_predicate" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should pass when actual returns true for :predicates? (present tense)" do
|
10
|
-
actual = stub("actual", :exists? => true)
|
10
|
+
actual = stub("actual", :exists? => true, :exist? => true)
|
11
11
|
actual.should be_exist
|
12
12
|
end
|
13
13
|
|
@@ -21,7 +21,23 @@ describe "should be_predicate" do
|
|
21
21
|
it "should fail when actual does not respond to :predicate?" do
|
22
22
|
lambda {
|
23
23
|
Object.new.should be_happy
|
24
|
-
}.should raise_error(NameError)
|
24
|
+
}.should raise_error(NameError, /happy\?/)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should fail on error other than NameError" do
|
28
|
+
actual = stub("actual")
|
29
|
+
actual.should_receive(:foo?).and_raise("aaaah")
|
30
|
+
lambda {
|
31
|
+
actual.should be_foo
|
32
|
+
}.should raise_error(/aaaah/)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should fail on error other than NameError (with the present tense predicate)" do
|
36
|
+
actual = Object.new
|
37
|
+
actual.should_receive(:foos?).and_raise("aaaah")
|
38
|
+
lambda {
|
39
|
+
actual.should be_foo
|
40
|
+
}.should raise_error(/aaaah/)
|
25
41
|
end
|
26
42
|
end
|
27
43
|
|
@@ -121,7 +137,7 @@ describe "should be_nil" do
|
|
121
137
|
it "should fail when actual is not nil" do
|
122
138
|
lambda {
|
123
139
|
:not_nil.should be_nil
|
124
|
-
}.should fail_with("expected nil, got
|
140
|
+
}.should fail_with("expected nil? to return true, got false")
|
125
141
|
end
|
126
142
|
end
|
127
143
|
|
@@ -133,7 +149,7 @@ describe "should_not be_nil" do
|
|
133
149
|
it "should fail when actual is nil" do
|
134
150
|
lambda {
|
135
151
|
nil.should_not be_nil
|
136
|
-
}.should fail_with("expected
|
152
|
+
}.should fail_with("expected nil? to return false, got true")
|
137
153
|
end
|
138
154
|
end
|
139
155
|
|
@@ -195,7 +211,15 @@ describe "should be ===" do
|
|
195
211
|
end
|
196
212
|
|
197
213
|
it "should fail when === operator returns false" do
|
198
|
-
lambda { Hash.should be === "not a hash" }.should fail_with(%[expected ===
|
214
|
+
lambda { Hash.should be === "not a hash" }.should fail_with(%[expected === not a hash, got Hash])
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
describe "should_not with operators" do
|
219
|
+
it "should coach user to stop using operators with should_not" do
|
220
|
+
lambda {
|
221
|
+
5.should_not be < 6
|
222
|
+
}.should raise_error(/not only FAILED,\nit reads really poorly./m)
|
199
223
|
end
|
200
224
|
end
|
201
225
|
|
@@ -206,11 +230,11 @@ describe "should be" do
|
|
206
230
|
end
|
207
231
|
|
208
232
|
it "should fail if actual is false" do
|
209
|
-
lambda {false.should be}.should fail_with("expected
|
233
|
+
lambda {false.should be}.should fail_with("expected true, got false")
|
210
234
|
end
|
211
235
|
|
212
236
|
it "should fail if actual is nil" do
|
213
|
-
lambda {nil.should be}.should fail_with("expected
|
237
|
+
lambda {nil.should be}.should fail_with("expected true, got nil")
|
214
238
|
end
|
215
239
|
end
|
216
240
|
|
@@ -223,6 +247,15 @@ describe "should be(value)" do
|
|
223
247
|
end
|
224
248
|
end
|
225
249
|
|
250
|
+
describe "'should be' with operator" do
|
251
|
+
it "should include 'be' in the description" do
|
252
|
+
(be > 6).description.should =~ /be > 6/
|
253
|
+
(be >= 6).description.should =~ /be >= 6/
|
254
|
+
(be <= 6).description.should =~ /be <= 6/
|
255
|
+
(be < 6).description.should =~ /be < 6/
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
226
259
|
|
227
260
|
describe "arbitrary predicate with DelegateClass" do
|
228
261
|
it "should access methods defined in the delegating class (LH[#48])" do
|
@@ -151,3 +151,17 @@ describe "Matchers should be able to generate their own descriptions" do
|
|
151
151
|
end.new
|
152
152
|
end
|
153
153
|
end
|
154
|
+
|
155
|
+
describe "a Matcher with no description" do
|
156
|
+
def matcher
|
157
|
+
Class.new do
|
158
|
+
def matches?(ignore); true; end
|
159
|
+
def failure_message; ""; end
|
160
|
+
end.new
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should provide a helpful message when used in a string-less example block" do
|
164
|
+
5.should matcher
|
165
|
+
Spec::Matchers.generated_description.should =~ /When you call.*description method/m
|
166
|
+
end
|
167
|
+
end
|
@@ -2,52 +2,94 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|
2
2
|
|
3
3
|
module Spec
|
4
4
|
module Matchers
|
5
|
-
describe ThrowSymbol
|
6
|
-
|
5
|
+
describe ThrowSymbol do
|
6
|
+
describe "with no args" do
|
7
|
+
before(:each) { @matcher = ThrowSymbol.new }
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
it "should match if any Symbol is thrown" do
|
10
|
+
@matcher.matches?(lambda{ throw :sym }).should be_true
|
11
|
+
end
|
12
|
+
it "should match if any Symbol is thrown with an arg" do
|
13
|
+
@matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
|
14
|
+
end
|
15
|
+
it "should not match if no Symbol is thrown" do
|
16
|
+
@matcher.matches?(lambda{ }).should be_false
|
17
|
+
end
|
18
|
+
it "should provide a failure message" do
|
19
|
+
@matcher.matches?(lambda{})
|
20
|
+
@matcher.failure_message.should == "expected a Symbol but nothing was thrown"
|
21
|
+
end
|
22
|
+
it "should provide a negative failure message" do
|
23
|
+
@matcher.matches?(lambda{ throw :sym})
|
24
|
+
@matcher.negative_failure_message.should == "expected no Symbol, got :sym"
|
25
|
+
end
|
10
26
|
end
|
11
|
-
it "should not match if no Symbol is thrown" do
|
12
|
-
@matcher.matches?(lambda{ }).should be_false
|
13
|
-
end
|
14
|
-
it "should provide a failure message" do
|
15
|
-
@matcher.matches?(lambda{})
|
16
|
-
@matcher.failure_message.should == "expected a Symbol but nothing was thrown"
|
17
|
-
end
|
18
|
-
it "should provide a negative failure message" do
|
19
|
-
@matcher.matches?(lambda{ throw :sym})
|
20
|
-
@matcher.negative_failure_message.should == "expected no Symbol, got :sym"
|
21
|
-
end
|
22
|
-
end
|
23
27
|
|
24
|
-
|
25
|
-
|
28
|
+
describe "with a symbol" do
|
29
|
+
before(:each) { @matcher = ThrowSymbol.new(:sym) }
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
it "should match if correct Symbol is thrown" do
|
32
|
+
@matcher.matches?(lambda{ throw :sym }).should be_true
|
33
|
+
end
|
34
|
+
it "should match if correct Symbol is thrown with an arg" do
|
35
|
+
@matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
|
36
|
+
end
|
37
|
+
it "should not match if no Symbol is thrown" do
|
38
|
+
@matcher.matches?(lambda{ }).should be_false
|
39
|
+
end
|
40
|
+
it "should not match if correct Symbol is thrown" do
|
41
|
+
@matcher.matches?(lambda{ throw :other_sym }).should be_false
|
42
|
+
end
|
43
|
+
it "should provide a failure message when no Symbol is thrown" do
|
44
|
+
@matcher.matches?(lambda{})
|
45
|
+
@matcher.failure_message.should == "expected :sym but nothing was thrown"
|
46
|
+
end
|
47
|
+
it "should provide a failure message when wrong Symbol is thrown" do
|
48
|
+
@matcher.matches?(lambda{ throw :other_sym })
|
49
|
+
@matcher.failure_message.should == "expected :sym, got :other_sym"
|
50
|
+
end
|
51
|
+
it "should provide a negative failure message" do
|
52
|
+
@matcher.matches?(lambda{ throw :sym })
|
53
|
+
@matcher.negative_failure_message.should == "expected :sym not to be thrown"
|
54
|
+
end
|
55
|
+
it "should only match NameErrors raised by uncaught throws" do
|
56
|
+
@matcher.matches?(lambda{ sym }).should be_false
|
57
|
+
end
|
32
58
|
end
|
33
|
-
|
34
|
-
|
35
|
-
@matcher
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
59
|
+
|
60
|
+
describe "with a symbol and an arg" do
|
61
|
+
before(:each) { @matcher = ThrowSymbol.new(:sym, "a") }
|
62
|
+
|
63
|
+
it "should match if correct Symbol and args are thrown" do
|
64
|
+
@matcher.matches?(lambda{ throw :sym, "a" }).should be_true
|
65
|
+
end
|
66
|
+
it "should not match if nothing is thrown" do
|
67
|
+
@matcher.matches?(lambda{ }).should be_false
|
68
|
+
end
|
69
|
+
it "should not match if other Symbol is thrown" do
|
70
|
+
@matcher.matches?(lambda{ throw :other_sym, "a" }).should be_false
|
71
|
+
end
|
72
|
+
it "should not match if no arg is thrown" do
|
73
|
+
@matcher.matches?(lambda{ throw :sym }).should be_false
|
74
|
+
end
|
75
|
+
it "should not match if wrong arg is thrown" do
|
76
|
+
@matcher.matches?(lambda{ throw :sym, "b" }).should be_false
|
77
|
+
end
|
78
|
+
it "should provide a failure message when no Symbol is thrown" do
|
79
|
+
@matcher.matches?(lambda{})
|
80
|
+
@matcher.failure_message.should == %q[expected :sym with "a" but nothing was thrown]
|
81
|
+
end
|
82
|
+
it "should provide a failure message when wrong Symbol is thrown" do
|
83
|
+
@matcher.matches?(lambda{ throw :other_sym })
|
84
|
+
@matcher.failure_message.should == %q[expected :sym with "a", got :other_sym]
|
85
|
+
end
|
86
|
+
it "should provide a negative failure message" do
|
87
|
+
@matcher.matches?(lambda{ throw :sym })
|
88
|
+
@matcher.negative_failure_message.should == %q[expected :sym with "a" not to be thrown]
|
89
|
+
end
|
90
|
+
it "should only match NameErrors raised by uncaught throws" do
|
91
|
+
@matcher.matches?(lambda{ sym }).should be_false
|
92
|
+
end
|
51
93
|
end
|
52
94
|
end
|
53
95
|
end
|
@@ -11,19 +11,19 @@ module Spec
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should run directory" do
|
14
|
-
file = File.dirname(__FILE__) + '/../../../examples/
|
15
|
-
run_with(OptionParser.parse([file,"-p","
|
14
|
+
file = File.dirname(__FILE__) + '/../../../examples/passing'
|
15
|
+
run_with(OptionParser.parse([file,"-p","**/*_spec.rb,**/*_example.rb"], @err, @out))
|
16
16
|
|
17
17
|
@out.rewind
|
18
18
|
@out.read.should =~ /\d+ examples, 0 failures, 3 pending/n
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should run file" do
|
22
|
-
file = File.dirname(__FILE__) + '/../../../
|
22
|
+
file = File.dirname(__FILE__) + '/../../../examples/failing/predicate_example.rb'
|
23
23
|
run_with(OptionParser.parse([file], @err, @out))
|
24
24
|
|
25
25
|
@out.rewind
|
26
|
-
@out.read.should =~ /
|
26
|
+
@out.read.should =~ /3 examples, 2 failures/n
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should raise when file does not exist" do
|