rspec-core 2.0.0.beta.12 → 2.0.0.beta.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +14 -0
  3. data/Rakefile +15 -12
  4. data/VERSION +1 -1
  5. data/features/command_line/example_name_option.feature +17 -3
  6. data/features/command_line/exit_status.feature +49 -0
  7. data/features/hooks/before_and_after_hooks.feature +51 -19
  8. data/features/hooks/halt.feature +1 -1
  9. data/features/support/env.rb +5 -3
  10. data/lib/rspec/core/command_line.rb +14 -5
  11. data/lib/rspec/core/configuration.rb +14 -24
  12. data/lib/rspec/core/configuration_options.rb +13 -8
  13. data/lib/rspec/core/drb_command_line.rb +2 -3
  14. data/lib/rspec/core/example.rb +5 -5
  15. data/lib/rspec/core/example_group.rb +23 -25
  16. data/lib/rspec/core/formatters/base_text_formatter.rb +13 -4
  17. data/lib/rspec/core/hooks.rb +57 -24
  18. data/lib/rspec/core/metadata.rb +1 -1
  19. data/lib/rspec/core/pending.rb +3 -3
  20. data/lib/rspec/core/rake_task.rb +48 -11
  21. data/lib/rspec/core/runner.rb +19 -8
  22. data/lib/rspec/core/subject.rb +3 -3
  23. data/lib/rspec/core/world.rb +3 -7
  24. data/rspec-core.gemspec +16 -12
  25. data/spec/rspec/core/command_line_spec.rb +72 -0
  26. data/spec/rspec/core/configuration_options_spec.rb +12 -3
  27. data/spec/rspec/core/configuration_spec.rb +6 -1
  28. data/spec/rspec/core/deprecations_spec.rb +19 -0
  29. data/spec/rspec/core/drb_command_line_spec.rb +1 -1
  30. data/spec/rspec/core/example_group_spec.rb +120 -12
  31. data/spec/rspec/core/example_spec.rb +27 -17
  32. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +23 -0
  33. data/spec/rspec/core/metadata_spec.rb +32 -0
  34. data/spec/rspec/core/runner_spec.rb +2 -1
  35. data/spec/rspec/core/shared_example_group_spec.rb +1 -1
  36. data/spec/spec_helper.rb +49 -51
  37. data/specs.watchr +1 -1
  38. metadata +31 -27
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rspec-core}
8
- s.version = "2.0.0.beta.12"
8
+ s.version = "2.0.0.beta.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chad Humphries", "David Chelimsky"]
12
- s.date = %q{2010-06-14}
13
- s.description = %q{RSpec runner and example group classes}
12
+ s.date = %q{2010-06-23}
13
+ s.description = %q{RSpec runner and example groups}
14
14
  s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
15
15
  s.executables = ["rspec", "spec"]
16
16
  s.extra_rdoc_files = [
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  ".gitignore",
22
22
  ".rspec",
23
23
  ".treasure_map.rb",
24
+ "Gemfile",
24
25
  "License.txt",
25
26
  "README.markdown",
26
27
  "Rakefile",
@@ -31,6 +32,7 @@ Gem::Specification.new do |s|
31
32
  "bin/spec",
32
33
  "cucumber.yml",
33
34
  "features/command_line/example_name_option.feature",
35
+ "features/command_line/exit_status.feature",
34
36
  "features/command_line/line_number_appended_to_path.feature",
35
37
  "features/command_line/line_number_option.feature",
36
38
  "features/configuration/custom_settings.feature",
@@ -95,6 +97,7 @@ Gem::Specification.new do |s|
95
97
  "script/console",
96
98
  "spec/autotest/failed_results_re_spec.rb",
97
99
  "spec/autotest/rspec_spec.rb",
100
+ "spec/rspec/core/command_line_spec.rb",
98
101
  "spec/rspec/core/configuration_options_spec.rb",
99
102
  "spec/rspec/core/configuration_spec.rb",
100
103
  "spec/rspec/core/deprecations_spec.rb",
@@ -128,10 +131,10 @@ Gem::Specification.new do |s|
128
131
  "spec/support/matchers.rb",
129
132
  "specs.watchr"
130
133
  ]
131
- s.homepage = %q{http://github.com/rspec/core}
134
+ s.homepage = %q{http://github.com/rspec/rspec-core}
132
135
  s.post_install_message = %q{**************************************************
133
136
 
134
- Thank you for installing rspec-core-2.0.0.beta.12
137
+ Thank you for installing rspec-core-2.0.0.beta.13
135
138
 
136
139
  **************************************************
137
140
  }
@@ -139,10 +142,11 @@ Gem::Specification.new do |s|
139
142
  s.require_paths = ["lib"]
140
143
  s.rubyforge_project = %q{rspec}
141
144
  s.rubygems_version = %q{1.3.6}
142
- s.summary = %q{rspec-core-2.0.0.beta.12}
145
+ s.summary = %q{rspec-core-2.0.0.beta.13}
143
146
  s.test_files = [
144
147
  "spec/autotest/failed_results_re_spec.rb",
145
148
  "spec/autotest/rspec_spec.rb",
149
+ "spec/rspec/core/command_line_spec.rb",
146
150
  "spec/rspec/core/configuration_options_spec.rb",
147
151
  "spec/rspec/core/configuration_spec.rb",
148
152
  "spec/rspec/core/deprecations_spec.rb",
@@ -181,19 +185,19 @@ Gem::Specification.new do |s|
181
185
  s.specification_version = 3
182
186
 
183
187
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
184
- s.add_development_dependency(%q<rspec-expectations>, [">= 2.0.0.beta.12"])
185
- s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.12"])
188
+ s.add_development_dependency(%q<rspec-expectations>, [">= 2.0.0.beta.13"])
189
+ s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.13"])
186
190
  s.add_development_dependency(%q<cucumber>, [">= 0.5.3"])
187
191
  s.add_development_dependency(%q<autotest>, [">= 4.2.9"])
188
192
  else
189
- s.add_dependency(%q<rspec-expectations>, [">= 2.0.0.beta.12"])
190
- s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.12"])
193
+ s.add_dependency(%q<rspec-expectations>, [">= 2.0.0.beta.13"])
194
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.13"])
191
195
  s.add_dependency(%q<cucumber>, [">= 0.5.3"])
192
196
  s.add_dependency(%q<autotest>, [">= 4.2.9"])
193
197
  end
194
198
  else
195
- s.add_dependency(%q<rspec-expectations>, [">= 2.0.0.beta.12"])
196
- s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.12"])
199
+ s.add_dependency(%q<rspec-expectations>, [">= 2.0.0.beta.13"])
200
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.13"])
197
201
  s.add_dependency(%q<cucumber>, [">= 0.5.3"])
198
202
  s.add_dependency(%q<autotest>, [">= 4.2.9"])
199
203
  end
@@ -0,0 +1,72 @@
1
+ require "spec_helper"
2
+ require "stringio"
3
+
4
+ module RSpec::Core
5
+ describe CommandLine do
6
+ context "given an array" do
7
+ it "converts the contents to a ConfigurationOptions object" do
8
+ command_line = CommandLine.new(%w[--color])
9
+ command_line.instance_eval { @options }.should be_a(ConfigurationOptions)
10
+ end
11
+ end
12
+
13
+ context "given a ConfigurationOptions object" do
14
+ it "assigns it to @options" do
15
+ config_options = ConfigurationOptions.new(%w[--color])
16
+ config_options.parse_options
17
+ command_line = CommandLine.new(config_options)
18
+ command_line.instance_eval { @options }.should be(config_options)
19
+ end
20
+ end
21
+
22
+ describe "#run" do
23
+ let(:config_options) do
24
+ config_options = ConfigurationOptions.new(%w[--color])
25
+ config_options.parse_options
26
+ config_options
27
+ end
28
+
29
+ let(:command_line) do
30
+ CommandLine.new(config_options)
31
+ end
32
+
33
+ let(:config) do
34
+ RSpec::Core::Configuration.new
35
+ end
36
+
37
+ let(:out) { ::StringIO.new }
38
+
39
+ before do
40
+ command_line.stub(:configuration) { config }
41
+ config.stub(:run_hook)
42
+ end
43
+
44
+ it "runs before suite hooks" do
45
+ config.should_receive(:run_hook).with(:before, :suite)
46
+ command_line.run(out, out)
47
+ end
48
+
49
+ it "runs after suite hooks" do
50
+ config.should_receive(:run_hook).with(:after, :suite)
51
+ command_line.run(out, out)
52
+ end
53
+
54
+ it "runs after suite hooks even after an error" do
55
+ after_suite_called = false
56
+ config.stub(:run_hook) do |*args|
57
+ case args.first
58
+ when :before
59
+ raise "this error"
60
+ when :after
61
+ after_suite_called = true
62
+ end
63
+ end
64
+ expect do
65
+ command_line.run(out, out)
66
+ end.to raise_error
67
+ after_suite_called.should be_true
68
+ end
69
+ end
70
+
71
+ end
72
+ end
@@ -22,6 +22,14 @@ describe RSpec::Core::ConfigurationOptions do
22
22
  config.should_receive(:requires=).ordered
23
23
  opts.configure(config)
24
24
  end
25
+
26
+ it "sends requires before formatter" do
27
+ opts = config_options_object(*%w[--require a/path -f a/formatter])
28
+ config = double("config").as_null_object
29
+ config.should_receive(:requires=).ordered
30
+ config.should_receive(:formatter=).ordered
31
+ opts.configure(config)
32
+ end
25
33
  end
26
34
 
27
35
  describe 'color_enabled' do
@@ -175,13 +183,14 @@ describe RSpec::Core::ConfigurationOptions do
175
183
  # TODO check if we need to spec that the short options are "expanded" ("-v" becomes "--version" currently)
176
184
  describe "#drb_argv" do
177
185
  it "preserves extra arguments" do
178
- config_options_object(*%w[ a --drb b --color c ]).drb_argv.should eq(%w[ --color a b c ])
186
+ File.stub(:exist?) { false }
187
+ config_options_object(*%w[ a --drb b --color c ]).drb_argv.should =~ %w[ --color a b c ]
179
188
  end
180
189
 
181
190
  context "--drb specified in ARGV" do
182
191
  it "renders all the original arguments except --drb" do
183
- config_options_object(*%w[ --drb --color --format s --line_number 1 --example pattern --profile --backtrace]).
184
- drb_argv.should eq(%w[ --color --profile --backtrace --format s --line_number 1 --example pattern ])
192
+ config_options_object(*%w[ --drb --color --format s --line_number 1 --example pattern --profile --backtrace -I path/a -I path/b --require path/c --require path/d]).
193
+ drb_argv.should eq(%w[ --color --profile --backtrace --format s --line_number 1 --example pattern -I path/a -I path/b --require path/c --require path/d])
185
194
  end
186
195
  end
187
196
 
@@ -246,6 +246,12 @@ module RSpec::Core
246
246
  config.formatter.should be_an_instance_of(formatter_class)
247
247
  end
248
248
 
249
+ it "sets a formatter based on its class name" do
250
+ Object.const_set("CustomFormatter",Class.new(Formatters::BaseFormatter))
251
+ config.formatter = "CustomFormatter"
252
+ config.formatter.should be_an_instance_of(CustomFormatter)
253
+ end
254
+
249
255
  it "raises ArgumentError if formatter is unknown" do
250
256
  lambda { config.formatter = :progresss }.should raise_error(ArgumentError)
251
257
  end
@@ -395,6 +401,5 @@ module RSpec::Core
395
401
  end
396
402
  end
397
403
  end
398
-
399
404
  end
400
405
  end
@@ -6,5 +6,24 @@ describe "deprecations" do
6
6
  RSpec.should_receive(:warn_deprecation).with /Spec .* RSpec/i
7
7
  Spec
8
8
  end
9
+
10
+ it "returns RSpec" do
11
+ RSpec.stub(:warn_deprecation)
12
+ Spec.should == RSpec
13
+ end
14
+ end
15
+
16
+ describe RSpec::Core::ExampleGroup do
17
+ describe 'running_example' do
18
+ it 'is deprecated' do
19
+ RSpec.should_receive(:warn_deprecation).with /running_example.*example/m
20
+ self.running_example
21
+ end
22
+
23
+ it "delegates to example" do
24
+ RSpec.stub(:warn_deprecation)
25
+ running_example.should == example
26
+ end
27
+ end
9
28
  end
10
29
  end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "::DRbCommandLine" do
3
+ describe "::DRbCommandLine", :ruby => "!jruby" do
4
4
  before do
5
5
  RSpec.stub(:configuration).and_return(RSpec::Core::Configuration.new)
6
6
  end
@@ -17,15 +17,15 @@ module RSpec::Core
17
17
  describe "top level group" do
18
18
  it "runs its children" do
19
19
  examples_run = []
20
- parent = ExampleGroup.describe("parent")
21
- child = parent.describe("child") do
22
- it "does something" do
23
- examples_run << running_example
20
+ group = ExampleGroup.describe("parent") do
21
+ describe("child") do
22
+ it "does something" do
23
+ examples_run << example
24
+ end
24
25
  end
25
26
  end
26
27
 
27
- child.filtered_examples.replace(child.examples)
28
- parent.run_all
28
+ group.run_all
29
29
  examples_run.should have(1).example
30
30
  end
31
31
 
@@ -127,6 +127,23 @@ module RSpec::Core
127
127
  end
128
128
  end
129
129
 
130
+ context "with a constant in an outer group" do
131
+ context "and a string in an inner group" do
132
+ it "is the top level constant" do
133
+ group = ExampleGroup.describe(String) do
134
+ describe :symbol do
135
+ example "describes is String" do
136
+ debugger
137
+ described_class.should eq(String)
138
+ end
139
+ end
140
+ end
141
+
142
+ group.run_all.should be_true
143
+ end
144
+ end
145
+ end
146
+
130
147
  end
131
148
 
132
149
  describe '#description' do
@@ -268,6 +285,42 @@ module RSpec::Core
268
285
  example.metadata[:execution_result][:exception_encountered].message.should == "error in before all"
269
286
  end
270
287
  end
288
+
289
+ it "has no 'running example' within before(:all)" do
290
+ group = ExampleGroup.describe
291
+ running_example = :none
292
+ group.before(:all) { running_example = example }
293
+ group.example("no-op") { }
294
+ group.run_all
295
+ running_example.should == nil
296
+ end
297
+
298
+ it "has access to example options within before(:each)" do
299
+ group = ExampleGroup.describe
300
+ option = nil
301
+ group.before(:each) { option = example.options[:data] }
302
+ group.example("no-op", :data => :sample) { }
303
+ group.run_all
304
+ option.should == :sample
305
+ end
306
+
307
+ it "has access to example options within after(:each)" do
308
+ group = ExampleGroup.describe
309
+ option = nil
310
+ group.after(:each) { option = example.options[:data] }
311
+ group.example("no-op", :data => :sample) { }
312
+ group.run_all
313
+ option.should == :sample
314
+ end
315
+
316
+ it "has no 'running example' within after(:all)" do
317
+ group = ExampleGroup.describe
318
+ running_example = :none
319
+ group.after(:all) { running_example = example }
320
+ group.example("no-op") { }
321
+ group.run_all
322
+ running_example.should == nil
323
+ end
271
324
  end
272
325
 
273
326
  describe "adding examples" do
@@ -308,19 +361,19 @@ module RSpec::Core
308
361
 
309
362
  describe "A sample nested group", :nested_describe => "yep" do
310
363
  it "sets the described class to the constant Object" do
311
- running_example.example_group.describes.should == Object
364
+ example.example_group.describes.should == Object
312
365
  end
313
366
 
314
367
  it "sets the description to 'A sample nested describe'" do
315
- running_example.example_group.description.should == 'A sample nested group'
368
+ example.example_group.description.should == 'A sample nested group'
316
369
  end
317
370
 
318
371
  it "has top level metadata from the example_group and its ancestors" do
319
- running_example.example_group.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
372
+ example.example_group.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
320
373
  end
321
374
 
322
375
  it "exposes the parent metadata to the contained examples" do
323
- running_example.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
376
+ example.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
324
377
  end
325
378
  end
326
379
 
@@ -379,11 +432,11 @@ module RSpec::Core
379
432
  end
380
433
 
381
434
  it "should be able to access the before all ivars in the before_all_ivars hash", :ruby => 1.8 do
382
- running_example.example_group.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
435
+ example.example_group.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
383
436
  end
384
437
 
385
438
  it "should be able to access the before all ivars in the before_all_ivars hash", :ruby => 1.9 do
386
- running_example.example_group.before_all_ivars.should include(:@before_all_top_level => 'before_all_top_level')
439
+ example.example_group.before_all_ivars.should include(:@before_all_top_level => 'before_all_top_level')
387
440
  end
388
441
 
389
442
  describe "but now I am nested" do
@@ -455,5 +508,60 @@ module RSpec::Core
455
508
  end
456
509
  end
457
510
 
511
+ describe "#run" do
512
+ let(:reporter) { double("reporter").as_null_object }
513
+
514
+ context "with all examples passing" do
515
+ it "returns true" do
516
+ group = describe("something") do
517
+ it "does something" do
518
+ # pass
519
+ end
520
+ describe ("nested") do
521
+ it "does something else" do
522
+ # pass
523
+ end
524
+ end
525
+ end
526
+
527
+ group.run(reporter).should be_true
528
+ end
529
+ end
530
+
531
+ context "with top level example failing" do
532
+ it "returns false" do
533
+ group = describe("something") do
534
+ it "does something (wrong - fail)" do
535
+ raise "fail"
536
+ end
537
+ describe ("nested") do
538
+ it "does something else" do
539
+ # pass
540
+ end
541
+ end
542
+ end
543
+
544
+ group.run(reporter).should be_false
545
+ end
546
+ end
547
+
548
+ context "with nested example failing" do
549
+ it "returns true" do
550
+ group = describe("something") do
551
+ it "does something" do
552
+ # pass
553
+ end
554
+ describe ("nested") do
555
+ it "does something else (wrong -fail)" do
556
+ raise "fail"
557
+ end
558
+ end
559
+ end
560
+
561
+ group.run(reporter).should be_false
562
+ end
563
+ end
564
+ end
565
+
458
566
  end
459
567
  end
@@ -5,37 +5,41 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
5
5
  RSpec::Core::ExampleGroup.describe('group description')
6
6
  end
7
7
 
8
- let(:example) do
8
+ let(:example_instance) do
9
9
  example_group.example('example description')
10
10
  end
11
11
 
12
12
  describe "attr readers" do
13
13
  it "should have one for the parent example group" do
14
- example.should respond_to(:example_group)
14
+ example_instance.should respond_to(:example_group)
15
15
  end
16
16
 
17
- it "should have one for it's description" do
18
- example.should respond_to(:description)
17
+ it "should have one for its description" do
18
+ example_instance.should respond_to(:description)
19
19
  end
20
20
 
21
- it "should have one for it's metadata" do
22
- example.should respond_to(:metadata)
21
+ it "should have one for its metadata" do
22
+ example_instance.should respond_to(:metadata)
23
23
  end
24
24
 
25
- it "should have one for it's block" do
26
- example.should respond_to(:example_block)
25
+ it "should have one for its block" do
26
+ example_instance.should respond_to(:example_block)
27
+ end
28
+
29
+ it "should have one for its options" do
30
+ example_instance.should respond_to(:options)
27
31
  end
28
32
  end
29
33
 
30
34
  describe '#inspect' do
31
35
  it "should return 'group description - description'" do
32
- example.inspect.should == 'group description example description'
36
+ example_instance.inspect.should == 'group description example description'
33
37
  end
34
38
  end
35
39
 
36
40
  describe '#to_s' do
37
41
  it "should return #inspect" do
38
- example.to_s.should == example.inspect
42
+ example_instance.to_s.should == example_instance.inspect
39
43
  end
40
44
  end
41
45
 
@@ -47,12 +51,18 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
47
51
 
48
52
  describe "accessing metadata within a running example" do
49
53
  it "should have a reference to itself when running" do
50
- running_example.description.should == "should have a reference to itself when running"
54
+ example.description.should == "should have a reference to itself when running"
51
55
  end
52
56
 
53
57
  it "should be able to access the example group's top level metadata as if it were its own" do
54
- running_example.example_group.metadata.should include(:parent_metadata => 'sample')
55
- running_example.metadata.should include(:parent_metadata => 'sample')
58
+ example.example_group.metadata.should include(:parent_metadata => 'sample')
59
+ example.metadata.should include(:parent_metadata => 'sample')
60
+ end
61
+ end
62
+
63
+ describe "accessing options within a running example" do
64
+ it "should be able to look up option values by key", :demo => :data do
65
+ example.options[:demo].should == :data
56
66
  end
57
67
  end
58
68
 
@@ -81,7 +91,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
81
91
  after_run = false
82
92
  group = RSpec::Core::ExampleGroup.describe do
83
93
  after(:each) { after_run = true }
84
- example('example') { raise "this error" }
94
+ example('example') { raise "this error" }
85
95
  end
86
96
  group.run_all
87
97
  after_run.should be_true, "expected after(:each) to be run"
@@ -90,13 +100,13 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
90
100
 
91
101
  describe "#in_block?" do
92
102
  before do
93
- running_example.should_not be_in_block
103
+ example.should_not be_in_block
94
104
  end
95
105
  it "is only true during the example (but not before or after)" do
96
- running_example.should be_in_block
106
+ example.should be_in_block
97
107
  end
98
108
  after do
99
- running_example.should_not be_in_block
109
+ example.should_not be_in_block
100
110
  end
101
111
  end
102
112
  end