rspec-core 2.0.0.beta.20 → 2.0.0.beta.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.rspec +1 -1
  2. data/Gemfile +7 -6
  3. data/History.md +30 -0
  4. data/Rakefile +3 -43
  5. data/bin/rspec +2 -1
  6. data/features/configuration/{options_file.feature → read_options_from_file.feature} +29 -25
  7. data/features/example_groups/shared_example_group.feature +10 -6
  8. data/features/hooks/before_and_after_hooks.feature +38 -0
  9. data/lib/autotest/rspec2.rb +10 -2
  10. data/lib/rspec/core.rb +8 -0
  11. data/lib/rspec/core/configuration.rb +16 -10
  12. data/lib/rspec/core/configuration_options.rb +7 -3
  13. data/lib/rspec/core/example.rb +7 -0
  14. data/lib/rspec/core/example_group.rb +15 -2
  15. data/lib/rspec/core/extensions/module_eval_with_args.rb +9 -29
  16. data/lib/rspec/core/extensions/object.rb +0 -2
  17. data/lib/rspec/core/formatters/base_formatter.rb +8 -6
  18. data/lib/rspec/core/formatters/base_text_formatter.rb +18 -10
  19. data/lib/rspec/core/formatters/documentation_formatter.rb +9 -9
  20. data/lib/rspec/core/option_parser.rb +0 -4
  21. data/lib/rspec/core/rake_task.rb +85 -39
  22. data/lib/rspec/core/reporter.rb +18 -5
  23. data/lib/rspec/core/runner.rb +8 -18
  24. data/lib/rspec/core/shared_example_group.rb +2 -1
  25. data/lib/rspec/core/version.rb +1 -1
  26. data/rspec-core.gemspec +33 -233
  27. data/spec/autotest/failed_results_re_spec.rb +1 -2
  28. data/spec/autotest/rspec_spec.rb +62 -42
  29. data/spec/rspec/core/configuration_options_spec.rb +12 -29
  30. data/spec/rspec/core/configuration_spec.rb +8 -8
  31. data/spec/rspec/core/example_group_spec.rb +38 -7
  32. data/spec/rspec/core/example_spec.rb +16 -1
  33. data/spec/rspec/core/formatters/base_formatter_spec.rb +6 -0
  34. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +125 -10
  35. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +36 -0
  36. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +282 -0
  37. data/spec/rspec/core/formatters/html_formatted-1.9.1.html +22 -2
  38. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +280 -0
  39. data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +280 -0
  40. data/spec/rspec/core/rake_task_spec.rb +128 -0
  41. data/spec/rspec/core/reporter_spec.rb +36 -0
  42. data/spec/rspec/core/runner_spec.rb +0 -18
  43. data/spec/rspec/core/shared_example_group_spec.rb +22 -2
  44. data/spec/rspec/core/world_spec.rb +13 -15
  45. data/spec/spec_helper.rb +2 -1
  46. metadata +110 -13
  47. data/VERSION +0 -1
  48. data/lib/rspec/autorun.rb +0 -2
@@ -95,13 +95,6 @@ describe RSpec::Core::ConfigurationOptions do
95
95
  end
96
96
  end
97
97
 
98
- describe "options file" do
99
- it "is parsed from --options or -o" do
100
- options_from_args("--options", "custom/path").should include(:options_file => "custom/path")
101
- options_from_args("-o", "custom/path").should include(:options_file => "custom/path")
102
- end
103
- end
104
-
105
98
  describe "files_or_directories_to_run" do
106
99
  it "parses files from '-c file.rb dir/file.rb'" do
107
100
  options_from_args("-c", "file.rb", "dir/file.rb").should include(:files_or_directories_to_run => ["file.rb", "dir/file.rb"])
@@ -159,14 +152,14 @@ describe RSpec::Core::ConfigurationOptions do
159
152
 
160
153
  it "turns off the debugger option if --drb is specified in the options file" do
161
154
  File.stub(:exist?) { true }
162
- File.stub(:readlines) { %w[ --drb ] }
155
+ IO.stub(:read) { "--drb" }
163
156
  config_options_object("--debug").drb_argv.should_not include("--debug")
164
157
  config_options_object("-d" ).drb_argv.should_not include("--debug")
165
158
  end
166
159
 
167
160
  it "turns off the debugger option if --debug is specified in the options file" do
168
161
  File.stub(:exist?) { true }
169
- File.stub(:readlines) { %w[ --debug ] }
162
+ IO.stub(:read) { "--debug" }
170
163
  config_options_object("--drb").drb_argv.should_not include("--debug")
171
164
  config_options_object("-X" ).drb_argv.should_not include("--debug")
172
165
  end
@@ -197,7 +190,7 @@ describe RSpec::Core::ConfigurationOptions do
197
190
  context "--drb specified in the options file" do
198
191
  it "renders all the original arguments except --drb" do
199
192
  File.stub(:exist?) { true }
200
- File.stub(:readlines) { %w[ --drb --color ] }
193
+ IO.stub(:read) { "--drb --color" }
201
194
  config_options_object(*%w[ --format s --line_number 1 --example pattern --profile --backtrace ]).
202
195
  drb_argv.should eq(%w[ --color --profile --backtrace --format s --line_number 1 --example pattern ])
203
196
  end
@@ -206,7 +199,7 @@ describe RSpec::Core::ConfigurationOptions do
206
199
  context "--drb specified in ARGV and the options file" do
207
200
  it "renders all the original arguments except --drb" do
208
201
  File.stub(:exist?) { true }
209
- File.stub(:readlines) { %w[ --drb --color ] }
202
+ IO.stub(:read) { "--drb --color" }
210
203
  config_options_object(*%w[ --drb --format s --line_number 1 --example pattern --profile --backtrace]).
211
204
  drb_argv.should eq(%w[ --color --profile --backtrace --format s --line_number 1 --example pattern ])
212
205
  end
@@ -215,7 +208,7 @@ describe RSpec::Core::ConfigurationOptions do
215
208
  context "--drb specified in ARGV and in as ARGV-specified --options file" do
216
209
  it "renders all the original arguments except --drb and --options" do
217
210
  File.stub(:exist?) { true }
218
- File.stub(:readlines) { %w[ --drb --color ] }
211
+ IO.stub(:read) { "--drb --color" }
219
212
  config_options_object(*%w[ --drb --format s --line_number 1 --example pattern --profile --backtrace]).
220
213
  drb_argv.should eq(%w[ --color --profile --backtrace --format s --line_number 1 --example pattern ])
221
214
  end
@@ -227,17 +220,7 @@ describe RSpec::Core::ConfigurationOptions do
227
220
 
228
221
  it "loads automatically" do
229
222
  File.stub(:exist?) { true }
230
- File.stub(:readlines) { ["--format", "doc"] }
231
-
232
- config_options = RSpec::Core::ConfigurationOptions.new([])
233
- config_options.parse_options
234
- config_options.configure(config)
235
- config.formatter.should == 'doc'
236
- end
237
-
238
- it "allows options on one line" do
239
- File.stub(:exist?) { true }
240
- File.stub(:readlines) { ["--format doc"] }
223
+ IO.stub(:read) { "--format doc" }
241
224
 
242
225
  config_options = RSpec::Core::ConfigurationOptions.new([])
243
226
  config_options.parse_options
@@ -247,12 +230,12 @@ describe RSpec::Core::ConfigurationOptions do
247
230
 
248
231
  it "merges options from the global and local .rspec and the command line" do
249
232
  File.stub(:exist?){ true }
250
- File.stub(:readlines) do |path|
233
+ IO.stub(:read) do |path|
251
234
  case path
252
235
  when ".rspec"
253
- ["--format", "documentation"]
236
+ "--format documentation"
254
237
  when /\.rspec/
255
- ["--line", "37"]
238
+ "--line 37"
256
239
  else
257
240
  raise "Unexpected path: #{path}"
258
241
  end
@@ -269,12 +252,12 @@ describe RSpec::Core::ConfigurationOptions do
269
252
 
270
253
  it "prefers local options over global" do
271
254
  File.stub(:exist?){ true }
272
- File.stub(:readlines) do |path|
255
+ IO.stub(:read) do |path|
273
256
  case path
274
257
  when ".rspec"
275
- ["--format", "local"]
258
+ "--format local"
276
259
  when /\.rspec/
277
- ["--format", "global"]
260
+ "--format global"
278
261
  else
279
262
  raise "Unexpected path: #{path}"
280
263
  end
@@ -138,7 +138,7 @@ module RSpec::Core
138
138
 
139
139
  end
140
140
 
141
- describe "include" do
141
+ describe "#include" do
142
142
 
143
143
  module InstanceLevelMethods
144
144
  def you_call_this_a_blt?
@@ -172,7 +172,7 @@ module RSpec::Core
172
172
 
173
173
  end
174
174
 
175
- describe "extend" do
175
+ describe "#extend" do
176
176
 
177
177
  module ThatThingISentYou
178
178
  def that_thing
@@ -202,7 +202,7 @@ module RSpec::Core
202
202
  end
203
203
  end
204
204
 
205
- describe 'color_enabled=' do
205
+ describe "#color_enabled=" do
206
206
  context "given true" do
207
207
  context "on windows" do
208
208
  before do
@@ -337,7 +337,7 @@ module RSpec::Core
337
337
  end
338
338
  end
339
339
 
340
- describe "full_backtrace=" do
340
+ describe "#full_backtrace=" do
341
341
  it "clears the backtrace clean patterns" do
342
342
  config.full_backtrace = true
343
343
  config.backtrace_clean_patterns.should == []
@@ -352,14 +352,14 @@ module RSpec::Core
352
352
  end
353
353
  end
354
354
 
355
- describe "debug=true" do
355
+ describe "#debug=true" do
356
356
  it "requires 'ruby-debug'" do
357
357
  config.should_receive(:require).with('ruby-debug')
358
358
  config.debug = true
359
359
  end
360
360
  end
361
361
 
362
- describe "debug=false" do
362
+ describe "#debug=false" do
363
363
  it "does not require 'ruby-debug'" do
364
364
  config.should_not_receive(:require).with('ruby-debug')
365
365
  config.debug = false
@@ -374,14 +374,14 @@ module RSpec::Core
374
374
  end
375
375
  end
376
376
 
377
- describe "libs=" do
377
+ describe "#libs=" do
378
378
  it "adds directories to the LOAD_PATH" do
379
379
  $LOAD_PATH.should_receive(:unshift).with("a/dir")
380
380
  config.libs = ["a/dir"]
381
381
  end
382
382
  end
383
383
 
384
- describe "requires=" do
384
+ describe "#requires=" do
385
385
  it "requires paths" do
386
386
  config.should_receive(:require).with("a/path")
387
387
  config.requires = ["a/path"]
@@ -325,14 +325,15 @@ module RSpec::Core
325
325
  end
326
326
 
327
327
  it "treats an error in before(:all) as a failure" do
328
- pending("fix issue 21 - treat error in before all as failure") do
329
- group = ExampleGroup.describe
330
- group.before(:all) { raise "error in before all" }
331
- example = group.example("equality") { 1.should == 2}
332
- group.run_all
328
+ group = ExampleGroup.describe
329
+ group.before(:all) { raise "error in before all" }
330
+ example = group.example("equality") { 1.should == 2}
331
+ group.run_all
333
332
 
334
- example.metadata[:execution_result][:exception_encountered].message.should == "error in before all"
335
- end
333
+ example.metadata.should_not be_nil
334
+ example.metadata[:execution_result].should_not be_nil
335
+ example.metadata[:execution_result][:exception_encountered].should_not be_nil
336
+ example.metadata[:execution_result][:exception_encountered].message.should == "error in before all"
336
337
  end
337
338
 
338
339
  it "has no 'running example' within before(:all)" do
@@ -584,6 +585,36 @@ module RSpec::Core
584
585
  describe "#run" do
585
586
  let(:reporter) { double("reporter").as_null_object }
586
587
 
588
+ context "with RSpec.wants_to_quit=true" do
589
+ before do
590
+ RSpec.stub(:clear_remaining_example_groups)
591
+ RSpec.stub(:wants_to_quit) { true }
592
+ end
593
+
594
+ it "returns without starting the group" do
595
+ group = RSpec::Core::ExampleGroup.describe
596
+ reporter.should_not_receive(:example_group_started)
597
+ group.run(reporter)
598
+ end
599
+
600
+ context "at top level" do
601
+ it "purges remaining groups" do
602
+ group = RSpec::Core::ExampleGroup.describe
603
+ RSpec.should_receive(:clear_remaining_example_groups)
604
+ group.run(reporter)
605
+ end
606
+ end
607
+
608
+ context "in a nested group" do
609
+ it "does not purge remaining groups" do
610
+ group = RSpec::Core::ExampleGroup.describe
611
+ nested_group = group.describe
612
+ RSpec.should_not_receive(:clear_remaining_example_groups)
613
+ nested_group.run(reporter)
614
+ end
615
+ end
616
+ end
617
+
587
618
  context "with all examples passing" do
588
619
  it "returns true" do
589
620
  group = describe("something") do
@@ -40,6 +40,19 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
40
40
  end
41
41
 
42
42
  describe "#run" do
43
+ context "with RSpec.wants_to_quit=true" do
44
+ it "returns without starting the example" do
45
+ RSpec.stub(:wants_to_quit) { true }
46
+ group = RSpec::Core::ExampleGroup.describe
47
+ example = group.example('example') {}
48
+
49
+ reporter = double('reporter').as_null_object
50
+ reporter.should_not_receive(:example_started)
51
+
52
+ example.run(group.new,reporter)
53
+ end
54
+ end
55
+
43
56
  it "runs after(:each) when the example passes" do
44
57
  after_run = false
45
58
  group = RSpec::Core::ExampleGroup.describe do
@@ -163,11 +176,13 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
163
176
  end
164
177
 
165
178
  context "in before(:all)" do
166
- it "is not supported" do
179
+ pending "is not supported" do
167
180
  group = RSpec::Core::ExampleGroup.describe do
168
181
  before(:all) { pending }
169
182
  example {}
170
183
  end
184
+ group.run_all
185
+ group.examples.first.should be_pending
171
186
  expect do
172
187
  group.run_all
173
188
  end.to raise_error(/undefined method `metadata'/)
@@ -9,6 +9,12 @@ describe RSpec::Core::Formatters::BaseFormatter do
9
9
  it "trims current working directory" do
10
10
  formatter.__send__(:backtrace_line, File.expand_path(__FILE__)).should == "./spec/rspec/core/formatters/base_formatter_spec.rb"
11
11
  end
12
+
13
+ it "leaves the original line intact" do
14
+ original_line = File.expand_path(__FILE__)
15
+ formatter.__send__(:backtrace_line, original_line)
16
+ original_line.should eq(File.expand_path(__FILE__))
17
+ end
12
18
  end
13
19
 
14
20
  end
@@ -3,10 +3,10 @@ require "spec_helper"
3
3
  module RSpec::Core::Formatters
4
4
 
5
5
  describe BaseTextFormatter do
6
- describe "#summary_line" do
7
- let(:output) { StringIO.new }
8
- let(:formatter) { RSpec::Core::Formatters::BaseTextFormatter.new(output) }
6
+ let(:output) { StringIO.new }
7
+ let(:formatter) { RSpec::Core::Formatters::BaseTextFormatter.new(output) }
9
8
 
9
+ describe "#summary_line" do
10
10
  context "with 0s" do
11
11
  it "outputs pluralized (excluding pending)" do
12
12
  formatter.summary_line(0,0,0).should eq("0 examples, 0 failures")
@@ -27,18 +27,133 @@ module RSpec::Core::Formatters
27
27
  end
28
28
 
29
29
  describe "#dump_failures" do
30
- it "preserves formatting" do
31
- output = StringIO.new
32
- group = RSpec::Core::ExampleGroup.describe("group name")
33
- example = group.example("example name") { "this".should eq("that") }
34
- formatter = RSpec::Core::Formatters::BaseTextFormatter.new(output)
35
- group.run_all(formatter)
30
+ let(:group) { RSpec::Core::ExampleGroup.describe("group name") }
31
+
32
+ before { RSpec.configuration.stub(:color_enabled?) { false } }
36
33
 
37
- RSpec.configuration.stub(:color_enabled?) { false }
34
+ def run_all_and_dump_failures
35
+ group.run_all(formatter)
38
36
  formatter.dump_failures
37
+ end
38
+
39
+ it "preserves formatting" do
40
+ group.example("example name") { "this".should eq("that") }
41
+
42
+ run_all_and_dump_failures
43
+
39
44
  output.string.should =~ /group name example name/m
40
45
  output.string.should =~ /(\s+)expected \"that\"\n\1 got \"this\"/m
41
46
  end
47
+
48
+ context 'for #share_examples_for' do
49
+ it 'outputs the name and location' do
50
+
51
+ share_examples_for 'foo bar' do
52
+ it("example name") { "this".should eq("that") }
53
+ end
54
+
55
+ line = __LINE__.next
56
+ group.it_should_behave_like('foo bar')
57
+
58
+ run_all_and_dump_failures
59
+
60
+ output.string.should include(
61
+ 'Shared Example Group: "foo bar" called from ' +
62
+ "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
63
+ )
64
+ end
65
+
66
+ context 'that contains nested example groups' do
67
+ it 'outputs the name and location' do
68
+ share_examples_for 'foo bar' do
69
+ describe 'nested group' do
70
+ it("example name") { "this".should eq("that") }
71
+ end
72
+ end
73
+
74
+ line = __LINE__.next
75
+ group.it_should_behave_like('foo bar')
76
+
77
+ run_all_and_dump_failures
78
+
79
+ output.string.should include(
80
+ 'Shared Example Group: "foo bar" called from ' +
81
+ "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
82
+ )
83
+ end
84
+ end
85
+ end
86
+
87
+ context 'for #share_as' do
88
+ it 'outputs the name and location' do
89
+
90
+ share_as :FooBar do
91
+ it("example name") { "this".should eq("that") }
92
+ end
93
+
94
+ line = __LINE__.next
95
+ group.send(:include, FooBar)
96
+
97
+ run_all_and_dump_failures
98
+
99
+ output.string.should include(
100
+ 'Shared Example Group: "FooBar" called from ' +
101
+ "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
102
+ )
103
+ end
104
+
105
+ context 'that contains nested example groups' do
106
+ it 'outputs the name and location' do
107
+
108
+ share_as :NestedFoo do
109
+ describe 'nested group' do
110
+ describe 'hell' do
111
+ it("example name") { "this".should eq("that") }
112
+ end
113
+ end
114
+ end
115
+
116
+ line = __LINE__.next
117
+ group.send(:include, NestedFoo)
118
+
119
+ run_all_and_dump_failures
120
+
121
+ output.string.should include(
122
+ 'Shared Example Group: "NestedFoo" called from ' +
123
+ "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
124
+ )
125
+ end
126
+ end
127
+ end
128
+ end
129
+
130
+ describe "#dump_profile" do
131
+ before do
132
+ formatter.stub(:examples) do
133
+ group = RSpec::Core::ExampleGroup.describe("group") do
134
+ example("example")
135
+ end
136
+ group.run_all(double('reporter').as_null_object)
137
+ group.examples
138
+ end
139
+ end
140
+
141
+ it "names the example" do
142
+ formatter.dump_profile
143
+ output.string.should =~ /group example/m
144
+ end
145
+
146
+ it "prints the time" do
147
+ formatter.dump_profile
148
+ output.string.should =~ /0\.\d+ seconds/
149
+ end
150
+
151
+ it "prints the path" do
152
+ formatter.dump_profile
153
+ filename = __FILE__.split(File::SEPARATOR).last
154
+
155
+ output.string.should =~ /#{filename}\:134/
156
+ end
42
157
  end
43
158
  end
44
159
  end
@@ -25,5 +25,41 @@ module RSpec::Core::Formatters
25
25
  output.string.should =~ /first example \(FAILED - 1\)/m
26
26
  output.string.should =~ /second example \(FAILED - 2\)/m
27
27
  end
28
+
29
+ it "represents nested group using hierarchy tree" do
30
+
31
+ output = StringIO.new
32
+ RSpec.configuration.stub(:color_enabled?) { false }
33
+
34
+ formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output)
35
+
36
+ group = RSpec::Core::ExampleGroup.describe("root")
37
+ context1 = group.describe("context 1")
38
+ context1.example("nested example 1.1"){}
39
+ context1.example("nested example 1.2"){}
40
+
41
+ context11 = context1.describe("context 1.1")
42
+ context11.example("nested example 1.1.1"){}
43
+ context11.example("nested example 1.1.2"){}
44
+
45
+ context2 = group.describe("context 2")
46
+ context2.example("nested example 2.1"){}
47
+ context2.example("nested example 2.2"){}
48
+
49
+ group.run_all(RSpec::Core::Reporter.new(formatter))
50
+
51
+ output.string.should eql "
52
+ root
53
+ context 1
54
+ nested example 1.1
55
+ nested example 1.2
56
+ context 1.1
57
+ nested example 1.1.1
58
+ nested example 1.1.2
59
+ context 2
60
+ nested example 2.1
61
+ nested example 2.2
62
+ "
63
+ end
28
64
  end
29
65
  end