rspec 1.1.8 → 1.1.9

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 (57) hide show
  1. data/History.txt +30 -3
  2. data/License.txt +22 -0
  3. data/Manifest.txt +3 -3
  4. data/README.txt +1 -25
  5. data/Rakefile +4 -2
  6. data/TODO.txt +5 -4
  7. data/bin/autospec +1 -1
  8. data/examples/pure/shared_example_group_example.rb +2 -2
  9. data/lib/autotest/rspec.rb +1 -1
  10. data/lib/spec.rb +5 -1
  11. data/lib/spec/example.rb +1 -1
  12. data/lib/spec/example/before_and_after_hooks.rb +93 -0
  13. data/lib/spec/example/configuration.rb +10 -1
  14. data/lib/spec/example/example_group.rb +2 -1
  15. data/lib/spec/example/example_group_factory.rb +18 -1
  16. data/lib/spec/example/example_group_methods.rb +45 -123
  17. data/lib/spec/example/example_methods.rb +9 -6
  18. data/lib/spec/example/shared_example_group.rb +6 -12
  19. data/lib/spec/extensions/main.rb +1 -1
  20. data/lib/spec/interop/test/unit/testcase.rb +1 -1
  21. data/lib/spec/mocks/error_generator.rb +1 -1
  22. data/lib/spec/mocks/message_expectation.rb +19 -4
  23. data/lib/spec/mocks/methods.rb +2 -2
  24. data/lib/spec/mocks/proxy.rb +4 -5
  25. data/lib/spec/runner.rb +3 -4
  26. data/lib/spec/runner/formatter/nested_text_formatter.rb +3 -3
  27. data/lib/spec/runner/option_parser.rb +23 -22
  28. data/lib/spec/version.rb +1 -1
  29. data/rspec.gemspec +19 -8
  30. data/spec/autotest/rspec_spec.rb +5 -1
  31. data/spec/spec/example/configuration_spec.rb +229 -215
  32. data/spec/spec/example/example_group_class_definition_spec.rb +9 -9
  33. data/spec/spec/example/example_group_factory_spec.rb +48 -27
  34. data/spec/spec/example/example_group_methods_spec.rb +436 -426
  35. data/spec/spec/example/example_group_spec.rb +459 -500
  36. data/spec/spec/example/example_methods_spec.rb +92 -86
  37. data/spec/spec/example/shared_example_group_spec.rb +219 -203
  38. data/spec/spec/extensions/main_spec.rb +23 -23
  39. data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +13 -0
  40. data/spec/spec/interop/test/unit/spec_spec.rb +15 -8
  41. data/spec/spec/mocks/mock_spec.rb +12 -2
  42. data/spec/spec/mocks/nil_expectation_warning_spec.rb +0 -1
  43. data/spec/spec/mocks/partial_mock_spec.rb +10 -5
  44. data/spec/spec/package/bin_spec_spec.rb +8 -0
  45. data/spec/spec/runner/command_line_spec.rb +101 -100
  46. data/spec/spec/runner/drb_command_line_spec.rb +0 -2
  47. data/spec/spec/runner/formatter/html_formatter_spec.rb +1 -4
  48. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +230 -245
  49. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -3
  50. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +110 -109
  51. data/spec/spec/runner/option_parser_spec.rb +18 -6
  52. data/spec/spec_helper.rb +26 -5
  53. data/stories/mock_framework_integration/use_flexmock.story +1 -1
  54. metadata +38 -7
  55. data/lib/spec/example/module_inclusion_warnings.rb +0 -38
  56. data/spec/spec/example/example_group/described_module_spec.rb +0 -20
  57. data/spec/spec/example/example_group/warning_messages_spec.rb +0 -76
@@ -3,8 +3,6 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  module Spec
4
4
  module Runner
5
5
  describe DrbCommandLine, "without running local server" do
6
- include SandboxedOptions
7
-
8
6
  unless Config::CONFIG['ruby_install_name'] == 'jruby'
9
7
  it "should print error when there is no running local server" do
10
8
  err = StringIO.new
@@ -6,7 +6,6 @@ module Spec
6
6
  module Runner
7
7
  module Formatter
8
8
  describe HtmlFormatter do
9
- include SandboxedOptions
10
9
  ['--diff', '--dry-run'].each do |opt|
11
10
  def jruby?
12
11
  PLATFORM == 'java'
@@ -23,9 +22,7 @@ module Spec
23
22
  args = ['failing_examples/mocking_example.rb', 'failing_examples/diffing_spec.rb', 'examples/pure/stubbing_example.rb', 'examples/pure/pending_example.rb', '--format', 'html', opt]
24
23
  err = StringIO.new
25
24
  out = StringIO.new
26
- run_with(
27
- OptionParser.parse(args, err, out)
28
- )
25
+ run_with OptionParser.parse(args, err, out)
29
26
 
30
27
  seconds = /\d+\.\d+ seconds/
31
28
  html = out.string.gsub seconds, 'x seconds'
@@ -5,173 +5,178 @@ module Spec
5
5
  module Runner
6
6
  module Formatter
7
7
  describe NestedTextFormatter do
8
- include SandboxedOptions
9
- attr_reader :io, :options, :formatter, :example_group
10
- before(:each) do
11
- @io = StringIO.new
12
- options.stub!(:dry_run).and_return(false)
13
- options.stub!(:colour).and_return(false)
14
- @formatter = NestedTextFormatter.new(options, io)
15
- @example_group = ::Spec::Example::ExampleGroup.describe("ExampleGroup") do
16
- specify "example" do
8
+ with_sandboxed_options do
9
+ attr_reader :io, :options, :formatter, :example_group
10
+ before(:each) do
11
+ @io = StringIO.new
12
+ options.stub!(:dry_run).and_return(false)
13
+ options.stub!(:colour).and_return(false)
14
+ @formatter = NestedTextFormatter.new(options, io)
15
+ @example_group = ::Spec::Example::ExampleGroup.describe("ExampleGroup") do
16
+ specify "example" do
17
+ end
17
18
  end
18
19
  end
19
- end
20
-
21
- describe "where ExampleGroup has no superclasss with a description" do
22
- before do
23
- add_example_group
24
- end
25
-
26
- def add_example_group
27
- formatter.add_example_group(example_group)
28
- end
29
20
 
30
- describe "#dump_summary" do
31
- it "should produce standard summary without pending when pending has a 0 count" do
32
- formatter.dump_summary(3, 2, 1, 0)
33
- expected_output = <<-OUT
34
- ExampleGroup
21
+ describe "where ExampleGroup has no superclasss with a description" do
22
+ before do
23
+ add_example_group
24
+ end
35
25
 
36
- Finished in 3 seconds
26
+ def add_example_group
27
+ formatter.add_example_group(example_group)
28
+ end
37
29
 
38
- 2 examples, 1 failure
39
- OUT
30
+ describe "#dump_summary" do
31
+ it "should produce standard summary without pending when pending has a 0 count" do
32
+ formatter.dump_summary(3, 2, 1, 0)
33
+ io.string.should == <<-OUT
34
+ ExampleGroup
40
35
 
41
- io.string.should == expected_output.gsub(/^ /, '')
42
- end
36
+ Finished in 3 seconds
43
37
 
44
- it "should produce standard summary" do
45
- formatter.dump_summary(3, 2, 1, 4)
46
- expected_output = <<-OUT
47
- ExampleGroup
38
+ 2 examples, 1 failure
39
+ OUT
40
+ end
48
41
 
49
- Finished in 3 seconds
42
+ it "should produce standard summary" do
43
+ formatter.dump_summary(3, 2, 1, 4)
44
+ io.string.should == <<-OUT
45
+ ExampleGroup
50
46
 
51
- 2 examples, 1 failure, 4 pending
52
- OUT
53
- io.string.should == expected_output.gsub(/^ /, '')
54
- end
55
- end
47
+ Finished in 3 seconds
56
48
 
57
- describe "#add_example_group" do
58
- describe "when ExampleGroup has description_args" do
59
- before do
60
- example_group.description_args.should_not be_nil
49
+ 2 examples, 1 failure, 4 pending
50
+ OUT
61
51
  end
52
+ end
62
53
 
63
- describe "when ExampleGroup has no parents with description args" do
54
+ describe "#add_example_group" do
55
+ describe "when ExampleGroup has description_args" do
64
56
  before do
65
- example_group.superclass.description_args.should be_nil
57
+ example_group.description_args.should_not be_nil
66
58
  end
67
59
 
68
- it "should push ExampleGroup name" do
69
- io.string.should eql("ExampleGroup\n")
70
- end
71
- end
60
+ describe "when ExampleGroup has no parents with description args" do
61
+ before do
62
+ example_group.superclass.description_args.should be_empty
63
+ end
72
64
 
73
- describe "when ExampleGroup has one parent with description args" do
74
- attr_reader :child_example_group
75
- def add_example_group
76
- example_group.description_args.should_not be_nil
77
- @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
65
+ it "should push ExampleGroup name" do
66
+ io.string.should eql("ExampleGroup\n")
67
+ end
78
68
  end
79
69
 
80
- describe "and parent ExampleGroups have not been printed" do
81
- before do
82
- formatter.add_example_group(child_example_group)
70
+ describe "when ExampleGroup has one parent with description args" do
71
+ attr_reader :child_example_group
72
+ def add_example_group
73
+ example_group.description_args.should_not be_nil
74
+ @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
75
+ end
76
+
77
+ describe "and parent ExampleGroups have not been printed" do
78
+ before do
79
+ formatter.add_example_group(child_example_group)
80
+ end
81
+
82
+ it "should push ExampleGroup name with two spaces of indentation" do
83
+ io.string.should == <<-OUT
84
+ ExampleGroup
85
+ Child ExampleGroup
86
+ OUT
87
+ end
83
88
  end
84
89
 
85
- it "should push ExampleGroup name with two spaces of indentation" do
86
- expected_output = <<-OUT
87
- ExampleGroup
88
- Child ExampleGroup
89
- OUT
90
- io.string.should == expected_output.gsub(/^ /, '')
90
+ describe "and parent ExampleGroups have been printed" do
91
+ before do
92
+ formatter.add_example_group(example_group)
93
+ io.string = ""
94
+ formatter.add_example_group(child_example_group)
95
+ end
96
+
97
+ it "should print only the indented ExampleGroup" do
98
+ io.string.should == <<-OUT
99
+ Child ExampleGroup
100
+ OUT
101
+ end
91
102
  end
92
103
  end
93
104
 
94
- describe "and parent ExampleGroups have been printed" do
95
- before do
96
- formatter.add_example_group(example_group)
97
- io.string = ""
98
- formatter.add_example_group(child_example_group)
105
+ describe "when ExampleGroup has two parents with description args" do
106
+ attr_reader :child_example_group, :grand_child_example_group
107
+ def add_example_group
108
+ example_group.description_args.should_not be_nil
109
+ @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
110
+ @grand_child_example_group = Class.new(child_example_group).describe("GrandChild ExampleGroup")
99
111
  end
100
112
 
101
- it "should print only the indented ExampleGroup" do
102
- expected_output = <<-OUT
103
- Child ExampleGroup
104
- OUT
105
- io.string.should == expected_output.gsub(/^ /, '')
113
+ describe "and parent ExampleGroups have not been printed" do
114
+ before do
115
+ formatter.add_example_group(grand_child_example_group)
116
+ end
117
+
118
+ it "should print the entire nested ExampleGroup heirarchy" do
119
+ io.string.should == <<-OUT
120
+ ExampleGroup
121
+ Child ExampleGroup
122
+ GrandChild ExampleGroup
123
+ OUT
124
+ end
125
+ end
126
+
127
+ describe "and parent ExampleGroups have been printed" do
128
+ before do
129
+ formatter.add_example_group(child_example_group)
130
+ io.string = ""
131
+ formatter.add_example_group(grand_child_example_group)
132
+ end
133
+
134
+ it "should print only the indented ExampleGroup" do
135
+ io.string.should == <<-OUT
136
+ GrandChild ExampleGroup
137
+ OUT
138
+ end
106
139
  end
107
140
  end
108
141
  end
109
142
 
110
- describe "when ExampleGroup has two parents with description args" do
111
- attr_reader :child_example_group, :grand_child_example_group
112
- def add_example_group
113
- example_group.description_args.should_not be_nil
114
- @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
115
- @grand_child_example_group = Class.new(child_example_group).describe("GrandChild ExampleGroup")
116
- end
143
+ describe "when ExampleGroup description_args is nil" do
144
+ attr_reader :child_example_group
117
145
 
118
146
  describe "and parent ExampleGroups have not been printed" do
119
- before do
120
- formatter.add_example_group(grand_child_example_group)
147
+ def add_example_group
148
+ @child_example_group = Class.new(example_group)
149
+ child_example_group.description_args.should be_empty
150
+ formatter.add_example_group(child_example_group)
121
151
  end
122
152
 
123
- it "should print the entire nested ExampleGroup heirarchy" do
124
- expected_output = <<-OUT
125
- ExampleGroup
126
- Child ExampleGroup
127
- GrandChild ExampleGroup
128
- OUT
129
- io.string.should == expected_output.gsub(/^ /, '')
153
+ it "should render only the parent ExampleGroup" do
154
+ io.string.should == <<-OUT
155
+ ExampleGroup
156
+ OUT
130
157
  end
131
158
  end
132
159
 
133
160
  describe "and parent ExampleGroups have been printed" do
134
- before do
135
- formatter.add_example_group(child_example_group)
161
+ def add_example_group
162
+ @child_example_group = Class.new(example_group)
163
+ child_example_group.description_args.should be_empty
164
+ formatter.add_example_group(example_group)
136
165
  io.string = ""
137
- formatter.add_example_group(grand_child_example_group)
166
+ formatter.add_example_group(child_example_group)
138
167
  end
139
168
 
140
- it "should print only the indented ExampleGroup" do
141
- expected_output = <<-OUT
142
- GrandChild ExampleGroup
143
- OUT
144
- io.string.should == expected_output.gsub(/^ /, '')
169
+ it "should not render anything" do
170
+ io.string.should == ""
145
171
  end
146
172
  end
147
173
  end
148
- end
149
-
150
- describe "when ExampleGroup description_args is nil" do
151
- attr_reader :child_example_group
152
-
153
- describe "and parent ExampleGroups have not been printed" do
154
- def add_example_group
155
- @child_example_group = Class.new(example_group)
156
- child_example_group.description_args.should be_nil
157
- formatter.add_example_group(child_example_group)
158
- end
159
-
160
- it "should render only the parent ExampleGroup" do
161
- expected_output = <<-OUT
162
- ExampleGroup
163
- OUT
164
- io.string.should == expected_output.gsub(/^ /, '')
165
- end
166
- end
167
174
 
168
- describe "and parent ExampleGroups have been printed" do
175
+ describe "when ExampleGroup description_args is empty" do
169
176
  def add_example_group
170
- @child_example_group = Class.new(example_group)
171
- child_example_group.description_args.should be_nil
172
- formatter.add_example_group(example_group)
173
- io.string = ""
174
- formatter.add_example_group(child_example_group)
177
+ example_group.set_description
178
+ example_group.description_args.should be_empty
179
+ super
175
180
  end
176
181
 
177
182
  it "should not render anything" do
@@ -180,154 +185,134 @@ module Spec
180
185
  end
181
186
  end
182
187
 
183
- describe "when ExampleGroup description_args is empty" do
184
- def add_example_group
185
- example_group.set_description
186
- example_group.description_args.should be_empty
187
- super
188
- end
189
-
190
- it "should not render anything" do
191
- io.string.should == ""
192
- end
193
- end
194
- end
195
-
196
- describe "#example_failed" do
197
- describe "where ExampleGroup has no superclasss with a description" do
198
- describe "when having an error" do
199
- it "should push failing spec name and failure number" do
200
- formatter.example_failed(
201
- example_group.it("spec"),
202
- 98,
203
- Reporter::Failure.new("c s", RuntimeError.new)
204
- )
205
- expected_output = <<-OUT
206
- ExampleGroup
207
- spec (ERROR - 98)
208
- OUT
209
- io.string.should == expected_output.gsub(/^ /, '')
188
+ describe "#example_failed" do
189
+ describe "where ExampleGroup has no superclasss with a description" do
190
+ describe "when having an error" do
191
+ it "should push failing spec name and failure number" do
192
+ formatter.example_failed(
193
+ example_group.it("spec"),
194
+ 98,
195
+ Reporter::Failure.new("c s", RuntimeError.new)
196
+ )
197
+ io.string.should == <<-OUT
198
+ ExampleGroup
199
+ spec (ERROR - 98)
200
+ OUT
201
+ end
210
202
  end
211
- end
212
203
 
213
- describe "when having an expectation failure" do
214
- it "should push failing spec name and failure number" do
215
- formatter.example_failed(
216
- example_group.it("spec"),
217
- 98,
218
- Reporter::Failure.new("c s", Spec::Expectations::ExpectationNotMetError.new)
219
- )
220
- expected_output = <<-OUT
221
- ExampleGroup
222
- spec (FAILED - 98)
223
- OUT
224
- io.string.should == expected_output.gsub(/^ /, '')
204
+ describe "when having an expectation failure" do
205
+ it "should push failing spec name and failure number" do
206
+ formatter.example_failed(
207
+ example_group.it("spec"),
208
+ 98,
209
+ Reporter::Failure.new("c s", Spec::Expectations::ExpectationNotMetError.new)
210
+ )
211
+ io.string.should == <<-OUT
212
+ ExampleGroup
213
+ spec (FAILED - 98)
214
+ OUT
215
+ end
225
216
  end
226
217
  end
227
- end
228
218
 
229
- describe "where ExampleGroup has two superclasses with a description" do
230
- attr_reader :child_example_group, :grand_child_example_group
219
+ describe "where ExampleGroup has two superclasses with a description" do
220
+ attr_reader :child_example_group, :grand_child_example_group
231
221
 
232
- def add_example_group
233
- @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
234
- @grand_child_example_group = Class.new(child_example_group).describe("GrandChild ExampleGroup")
235
- formatter.add_example_group(grand_child_example_group)
236
- end
222
+ def add_example_group
223
+ @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
224
+ @grand_child_example_group = Class.new(child_example_group).describe("GrandChild ExampleGroup")
225
+ formatter.add_example_group(grand_child_example_group)
226
+ end
237
227
 
238
- describe "when having an error" do
239
- it "should push failing spec name and failure number" do
240
- formatter.example_failed(
241
- grand_child_example_group.it("spec"),
242
- 98,
243
- Reporter::Failure.new("c s", RuntimeError.new)
244
- )
245
- expected_output = <<-OUT
246
- ExampleGroup
247
- Child ExampleGroup
248
- GrandChild ExampleGroup
249
- spec (ERROR - 98)
250
- OUT
251
- io.string.should == expected_output.gsub(/^ /, '')
228
+ describe "when having an error" do
229
+ it "should push failing spec name and failure number" do
230
+ formatter.example_failed(
231
+ grand_child_example_group.it("spec"),
232
+ 98,
233
+ Reporter::Failure.new("c s", RuntimeError.new)
234
+ )
235
+ io.string.should == <<-OUT
236
+ ExampleGroup
237
+ Child ExampleGroup
238
+ GrandChild ExampleGroup
239
+ spec (ERROR - 98)
240
+ OUT
241
+ end
252
242
  end
253
- end
254
243
 
255
- describe "when having an expectation" do
256
- it "should push failing spec name and failure number" do
257
- formatter.example_failed(
258
- grand_child_example_group.it("spec"),
259
- 98,
260
- Reporter::Failure.new("c s", Spec::Expectations::ExpectationNotMetError.new)
261
- )
262
- expected_output = <<-OUT
263
- ExampleGroup
264
- Child ExampleGroup
265
- GrandChild ExampleGroup
266
- spec (FAILED - 98)
267
- OUT
268
- io.string.should == expected_output.gsub(/^ /, '')
244
+ describe "when having an expectation" do
245
+ it "should push failing spec name and failure number" do
246
+ formatter.example_failed(
247
+ grand_child_example_group.it("spec"),
248
+ 98,
249
+ Reporter::Failure.new("c s", Spec::Expectations::ExpectationNotMetError.new)
250
+ )
251
+ io.string.should == <<-OUT
252
+ ExampleGroup
253
+ Child ExampleGroup
254
+ GrandChild ExampleGroup
255
+ spec (FAILED - 98)
256
+ OUT
257
+ end
269
258
  end
270
259
  end
271
260
  end
272
- end
273
261
 
274
- describe "#start" do
275
- it "should push nothing on start" do
276
- formatter.start(5)
277
- expected_output = <<-OUT
278
- ExampleGroup
279
- OUT
280
- io.string.should == expected_output.gsub(/^ /, '')
262
+ describe "#start" do
263
+ it "should push nothing on start" do
264
+ formatter.start(5)
265
+ io.string.should == <<-OUT
266
+ ExampleGroup
267
+ OUT
268
+ end
281
269
  end
282
- end
283
270
 
284
- describe "#start_dump" do
285
- it "should push nothing on start dump" do
286
- formatter.start_dump
287
- expected_output = <<-OUT
288
- ExampleGroup
289
- OUT
290
- io.string.should == expected_output.gsub(/^ /, '')
271
+ describe "#start_dump" do
272
+ it "should push nothing on start dump" do
273
+ formatter.start_dump
274
+ io.string.should == <<-OUT
275
+ ExampleGroup
276
+ OUT
277
+ end
291
278
  end
292
- end
293
279
 
294
- describe "#example_passed" do
295
- it "should push passing spec name" do
296
- formatter.example_passed(example_group.it("spec"))
297
- expected_output = <<-OUT
298
- ExampleGroup
299
- spec
300
- OUT
301
- io.string.should == expected_output.gsub(/^ /, '')
280
+ describe "#example_passed" do
281
+ it "should push passing spec name" do
282
+ formatter.example_passed(example_group.it("spec"))
283
+ io.string.should == <<-OUT
284
+ ExampleGroup
285
+ spec
286
+ OUT
287
+ end
302
288
  end
303
- end
304
289
 
305
- describe "#example_pending" do
306
- it "should push pending example name and message" do
307
- formatter.example_pending(example_group.examples.first, 'reason', "#{__FILE__}:#{__LINE__}")
308
- expected_output = <<-OUT
309
- ExampleGroup
310
- example (PENDING: reason)
311
- OUT
312
- io.string.should == expected_output.gsub(/^ /, '')
313
- end
290
+ describe "#example_pending" do
291
+ it "should push pending example name and message" do
292
+ formatter.example_pending(example_group.examples.first, 'reason', "#{__FILE__}:#{__LINE__}")
293
+ io.string.should == <<-OUT
294
+ ExampleGroup
295
+ example (PENDING: reason)
296
+ OUT
297
+ end
314
298
 
315
- it "should dump pending" do
316
- formatter.example_pending(example_group.examples.first, 'reason', "#{__FILE__}:#{__LINE__}")
317
- io.rewind
318
- formatter.dump_pending
319
- io.string.should =~ /Pending\:\nExampleGroup example \(reason\)\n/
299
+ it "should dump pending" do
300
+ formatter.example_pending(example_group.examples.first, 'reason', "#{__FILE__}:#{__LINE__}")
301
+ io.rewind
302
+ formatter.dump_pending
303
+ io.string.should =~ /Pending\:\nExampleGroup example \(reason\)\n/
304
+ end
320
305
  end
321
- end
322
306
 
323
- def have_single_level_example_group_output(expected_output)
324
- expected = "ExampleGroup\n #{expected_output}"
325
- ::Spec::Matchers::SimpleMatcher.new(expected) do |actual|
326
- actual == expected
307
+ def have_single_level_example_group_output(expected_output)
308
+ expected = "ExampleGroup\n #{expected_output}"
309
+ ::Spec::Matchers::SimpleMatcher.new(expected) do |actual|
310
+ actual == expected
311
+ end
327
312
  end
328
313
  end
329
314
  end
330
315
  end
331
316
  end
332
317
  end
333
- end
318
+ end