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.
Files changed (120) hide show
  1. data/History.txt +17 -0
  2. data/Manifest.txt +53 -74
  3. data/Rakefile +0 -1
  4. data/examples/{pure → passing}/autogenerated_docstrings_example.rb +6 -0
  5. data/examples/{pure → passing}/before_and_after_example.rb +0 -0
  6. data/examples/{pure → passing}/behave_as_example.rb +0 -0
  7. data/examples/{pure → passing}/custom_expectation_matchers.rb +0 -0
  8. data/examples/{pure → passing}/custom_formatter.rb +1 -1
  9. data/examples/{pure → passing}/dynamic_spec.rb +2 -2
  10. data/examples/{pure → passing}/file_accessor.rb +0 -0
  11. data/examples/{pure → passing}/file_accessor_spec.rb +0 -0
  12. data/examples/{pure → passing}/greeter_spec.rb +0 -0
  13. data/examples/{pure → passing}/helper_method_example.rb +0 -0
  14. data/examples/{pure → passing}/io_processor.rb +0 -0
  15. data/examples/{pure → passing}/io_processor_spec.rb +0 -0
  16. data/examples/{pure → passing}/legacy_spec.rb +0 -0
  17. data/examples/{pure → passing}/mocking_example.rb +0 -0
  18. data/examples/{pure → passing}/multi_threaded_behaviour_runner.rb +0 -0
  19. data/examples/{pure → passing}/nested_classes_example.rb +0 -0
  20. data/examples/{pure → passing}/partial_mock_example.rb +0 -0
  21. data/examples/{pure → passing}/pending_example.rb +0 -0
  22. data/examples/{pure → passing}/predicate_example.rb +0 -0
  23. data/examples/{pure → passing}/priority.txt +0 -0
  24. data/examples/{pure → passing}/shared_example_group_example.rb +0 -0
  25. data/examples/{pure → passing}/shared_stack_examples.rb +1 -3
  26. data/examples/{pure → passing}/spec_helper.rb +0 -0
  27. data/examples/{pure → passing}/stack.rb +0 -0
  28. data/examples/{pure → passing}/stack_spec.rb +3 -2
  29. data/examples/{pure → passing}/stack_spec_with_nested_example_groups.rb +0 -0
  30. data/examples/{pure → passing}/stubbing_example.rb +0 -0
  31. data/examples/{pure → passing}/yielding_example.rb +0 -0
  32. data/lib/spec/example/before_and_after_hooks.rb +8 -21
  33. data/lib/spec/example/configuration.rb +45 -45
  34. data/lib/spec/example/example_group_factory.rb +10 -9
  35. data/lib/spec/example/example_group_methods.rb +31 -15
  36. data/lib/spec/example/example_methods.rb +74 -22
  37. data/lib/spec/example/shared_example_group.rb +27 -16
  38. data/lib/spec/example.rb +28 -0
  39. data/lib/spec/expectations.rb +1 -0
  40. data/lib/spec/extensions.rb +0 -2
  41. data/lib/spec/matchers/be.rb +96 -114
  42. data/lib/spec/matchers/operator_matcher.rb +2 -9
  43. data/lib/spec/matchers/throw_symbol.rb +41 -15
  44. data/lib/spec/matchers.rb +4 -27
  45. data/lib/spec/runner/formatter/base_text_formatter.rb +1 -1
  46. data/lib/spec/runner/option_parser.rb +2 -2
  47. data/lib/spec/runner/reporter.rb +1 -1
  48. data/lib/spec/runner.rb +1 -1
  49. data/lib/spec/version.rb +1 -1
  50. data/lib/spec.rb +1 -0
  51. data/rspec.gemspec +4 -24
  52. data/spec/spec/example/example_group_factory_spec.rb +29 -9
  53. data/spec/spec/example/example_group_methods_spec.rb +4 -6
  54. data/spec/spec/example/example_group_spec.rb +0 -6
  55. data/spec/spec/example/example_matcher_spec.rb +6 -23
  56. data/spec/spec/example/example_methods_spec.rb +117 -2
  57. data/spec/spec/example/shared_example_group_spec.rb +51 -75
  58. data/spec/spec/matchers/be_spec.rb +40 -7
  59. data/spec/spec/matchers/description_generation_spec.rb +14 -0
  60. data/spec/spec/matchers/throw_symbol_spec.rb +83 -41
  61. data/spec/spec/runner/command_line_spec.rb +4 -4
  62. data/spec/spec/runner/formatter/html_formatted-1.8.4.html +6 -6
  63. data/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html +9 -9
  64. data/spec/spec/runner/formatter/html_formatted-1.8.5.html +6 -6
  65. data/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html +10 -10
  66. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +6 -6
  67. data/spec/spec/runner/formatter/html_formatter_spec.rb +1 -1
  68. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +5 -5
  69. data/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html +6 -6
  70. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +6 -6
  71. data/spec/spec/runner/reporter_spec.rb +1 -1
  72. data/stories/example_groups/autogenerated_docstrings +4 -4
  73. data/stories/example_groups/nested_groups +2 -2
  74. metadata +33 -59
  75. data/examples/stories/adder.rb +0 -13
  76. data/examples/stories/addition +0 -34
  77. data/examples/stories/addition.rb +0 -9
  78. data/examples/stories/calculator.rb +0 -65
  79. data/examples/stories/game-of-life/.loadpath +0 -5
  80. data/examples/stories/game-of-life/README.txt +0 -21
  81. data/examples/stories/game-of-life/behaviour/everything.rb +0 -6
  82. data/examples/stories/game-of-life/behaviour/examples/examples.rb +0 -3
  83. data/examples/stories/game-of-life/behaviour/examples/game_behaviour.rb +0 -35
  84. data/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb +0 -66
  85. data/examples/stories/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story +0 -21
  86. data/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +0 -21
  87. data/examples/stories/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story +0 -42
  88. data/examples/stories/game-of-life/behaviour/stories/ICanCreateACell.story +0 -42
  89. data/examples/stories/game-of-life/behaviour/stories/ICanKillACell.story +0 -17
  90. data/examples/stories/game-of-life/behaviour/stories/TheGridWraps.story +0 -53
  91. data/examples/stories/game-of-life/behaviour/stories/create_a_cell.rb +0 -52
  92. data/examples/stories/game-of-life/behaviour/stories/helper.rb +0 -6
  93. data/examples/stories/game-of-life/behaviour/stories/kill_a_cell.rb +0 -26
  94. data/examples/stories/game-of-life/behaviour/stories/steps.rb +0 -5
  95. data/examples/stories/game-of-life/behaviour/stories/stories.rb +0 -3
  96. data/examples/stories/game-of-life/behaviour/stories/stories.txt +0 -22
  97. data/examples/stories/game-of-life/life/game.rb +0 -23
  98. data/examples/stories/game-of-life/life/grid.rb +0 -43
  99. data/examples/stories/game-of-life/life.rb +0 -3
  100. data/examples/stories/helper.rb +0 -9
  101. data/examples/stories/steps/addition_steps.rb +0 -18
  102. data/failing_examples/README.txt +0 -7
  103. data/failing_examples/diffing_spec.rb +0 -36
  104. data/failing_examples/failing_autogenerated_docstrings_example.rb +0 -19
  105. data/failing_examples/failure_in_setup.rb +0 -10
  106. data/failing_examples/failure_in_teardown.rb +0 -10
  107. data/failing_examples/mocking_example.rb +0 -40
  108. data/failing_examples/mocking_with_flexmock.rb +0 -26
  109. data/failing_examples/mocking_with_mocha.rb +0 -25
  110. data/failing_examples/mocking_with_rr.rb +0 -27
  111. data/failing_examples/partial_mock_example.rb +0 -20
  112. data/failing_examples/predicate_example.rb +0 -29
  113. data/failing_examples/raising_example.rb +0 -47
  114. data/failing_examples/spec_helper.rb +0 -3
  115. data/failing_examples/syntax_error_example.rb +0 -7
  116. data/failing_examples/team_spec.rb +0 -44
  117. data/failing_examples/timeout_behaviour.rb +0 -7
  118. data/lib/spec/extensions/main.rb +0 -87
  119. data/lib/spec/extensions/object.rb +0 -6
  120. 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 "#__full_description" do
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.__full_description.should == "An ExampleGroup should do something"
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.shared_example_groups.clear
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
- it "should not be shared when not configured as shared" do
55
- example_group = non_shared_example_group
56
- SharedExampleGroup.shared_example_groups.should_not include(example_group)
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 "should complain when adding a second shared example_group with the same description" do
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 "should NOT complain when adding the same shared example_group instance again" do
69
- shared_example_group = Class.new(ExampleGroup).describe("shared example_group", :shared => true)
70
- SharedExampleGroup.add_shared_example_group(shared_example_group)
71
- SharedExampleGroup.add_shared_example_group(shared_example_group)
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 "should NOT complain when adding the same shared example_group again (i.e. file gets reloaded)" do
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 "should NOT complain when adding the same shared example_group in same file with different absolute path" do
84
- shared_example_group_1 = Class.new(ExampleGroup).describe(
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
- shared_example_group_2 = Class.new(ExampleGroup).describe(
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 "should complain when adding a different shared example_group with the same name in a different file with the same basename" do
100
- shared_example_group_1 = Class.new(ExampleGroup).describe(
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.add_shared_example_group(shared_example_group_2)
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 "should add examples to current example_group using it_should_behave_like" do
118
- shared_example_group = make_shared_example_group("shared example_group") do
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 "should add examples to from two shared groups" do
130
- shared_example_group_1 = make_shared_example_group("shared example_group 1") do
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 = make_shared_example_group("shared example_group 2") do
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 "should add examples to current example_group using include" do
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 "should add examples to current example_group using it_should_behave_like with a module" do
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 "should run shared examples" do
144
+ it "runs shared examples" do
169
145
  shared_example_ran = false
170
- shared_example_group = make_shared_example_group("shared example_group") do
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 "should run setup and teardown from shared example_group" do
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 = make_shared_example_group("shared example_group") do
187
- before { shared_setup_ran = true }
188
- after { shared_teardown_ran = true }
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 = make_shared_example_group("shared example_group") do
181
+ shared_example_group = SharedExampleGroup.register("shared example_group") do
206
182
  before(:all) { shared_before_all_run_count += 1}
207
- after(:all) { shared_after_all_run_count += 1}
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 = make_shared_example_group("shared example_group") do
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 = make_shared_example_group("shared example_group xyz") do
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 :not_nil")
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 not nil, got nil")
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 === "not a hash", got Hash])
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 if to be satisfied, got false")
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 if to be satisfied, got nil")
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, "(constructed with no Symbol)" do
6
- before(:each) { @matcher = ThrowSymbol.new }
5
+ describe ThrowSymbol do
6
+ describe "with no args" do
7
+ before(:each) { @matcher = ThrowSymbol.new }
7
8
 
8
- it "should match if any Symbol is thrown" do
9
- @matcher.matches?(lambda{ throw :sym }).should be_true
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
- describe ThrowSymbol, "(constructed with a Symbol)" do
25
- before(:each) { @matcher = ThrowSymbol.new(:sym) }
28
+ describe "with a symbol" do
29
+ before(:each) { @matcher = ThrowSymbol.new(:sym) }
26
30
 
27
- it "should match if correct Symbol is thrown" do
28
- @matcher.matches?(lambda{ throw :sym }).should be_true
29
- end
30
- it "should not match if no Symbol is thrown" do
31
- @matcher.matches?(lambda{ }).should be_false
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
- it "should not match if correct Symbol is thrown" do
34
- @matcher.matches?(lambda{ throw :other_sym }).should be_false
35
- @matcher.failure_message.should == "expected :sym, got :other_sym"
36
- end
37
- it "should provide a failure message when no Symbol is thrown" do
38
- @matcher.matches?(lambda{})
39
- @matcher.failure_message.should == "expected :sym but nothing was thrown"
40
- end
41
- it "should provide a failure message when wrong Symbol is thrown" do
42
- @matcher.matches?(lambda{ throw :other_sym })
43
- @matcher.failure_message.should == "expected :sym, got :other_sym"
44
- end
45
- it "should provide a negative failure message" do
46
- @matcher.matches?(lambda{ throw :sym })
47
- @matcher.negative_failure_message.should == "expected :sym not to be thrown"
48
- end
49
- it "should only match NameErrors raised by uncaught throws" do
50
- @matcher.matches?(lambda{ sym }).should be_false
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/pure'
15
- run_with(OptionParser.parse([file,"-p","**/*.rb"], @err, @out))
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__) + '/../../../failing_examples/predicate_example.rb'
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 =~ /2 examples, 1 failure/n
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