rspec-core 2.6.0 → 2.7.0.rc1

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 (113) hide show
  1. data/README.md +1 -1
  2. data/features/Upgrade.md +11 -0
  3. data/features/command_line/exit_status.feature +20 -3
  4. data/features/command_line/format_option.feature +8 -0
  5. data/features/command_line/line_number_appended_to_path.feature +35 -1
  6. data/features/command_line/line_number_option.feature +16 -3
  7. data/features/command_line/pattern_option.feature +31 -0
  8. data/features/command_line/rake_task.feature +1 -1
  9. data/features/command_line/ruby.feature +22 -0
  10. data/features/configuration/default_path.feature +38 -0
  11. data/features/example_groups/{shared_example_group.feature → shared_examples.feature} +49 -26
  12. data/features/expectation_framework_integration/configure_expectation_framework.feature +1 -1
  13. data/features/filtering/inclusion_filters.feature +4 -5
  14. data/features/formatters/text_formatter.feature +16 -13
  15. data/features/helper_methods/let.feature +4 -4
  16. data/features/hooks/around_hooks.feature +1 -1
  17. data/features/hooks/before_and_after_hooks.feature +3 -3
  18. data/features/hooks/filtering.feature +13 -6
  19. data/features/metadata/user_defined.feature +12 -10
  20. data/features/pending/pending_examples.feature +21 -8
  21. data/features/step_definitions/additional_cli_steps.rb +1 -1
  22. data/features/subject/attribute_of_subject.feature +2 -2
  23. data/features/support/env.rb +1 -2
  24. data/lib/rspec/core/backward_compatibility.rb +1 -1
  25. data/lib/rspec/core/configuration.rb +71 -16
  26. data/lib/rspec/core/configuration_options.rb +46 -16
  27. data/lib/rspec/core/{extensions/object.rb → dsl.rb} +2 -4
  28. data/lib/rspec/core/example.rb +10 -7
  29. data/lib/rspec/core/example_group.rb +34 -18
  30. data/lib/rspec/core/expecting/with_rspec.rb +0 -2
  31. data/lib/rspec/core/extensions.rb +0 -1
  32. data/lib/rspec/core/formatters/base_formatter.rb +8 -4
  33. data/lib/rspec/core/formatters/base_text_formatter.rb +38 -18
  34. data/lib/rspec/core/formatters/html_formatter.rb +3 -1
  35. data/lib/rspec/core/formatters/snippet_extractor.rb +9 -3
  36. data/lib/rspec/core/formatters/text_mate_formatter.rb +20 -6
  37. data/lib/rspec/core/hooks.rb +7 -6
  38. data/lib/rspec/core/let.rb +5 -5
  39. data/lib/rspec/core/metadata.rb +136 -94
  40. data/lib/rspec/core/metadata_hash_builder.rb +1 -1
  41. data/lib/rspec/core/option_parser.rb +11 -7
  42. data/lib/rspec/core/pending.rb +2 -1
  43. data/lib/rspec/core/rake_task.rb +26 -15
  44. data/lib/rspec/core/reporter.rb +5 -6
  45. data/lib/rspec/core/runner.rb +1 -1
  46. data/lib/rspec/core/shared_example_group.rb +4 -4
  47. data/lib/rspec/core/subject.rb +7 -7
  48. data/lib/rspec/core/version.rb +1 -1
  49. data/lib/rspec/core/world.rb +9 -13
  50. data/lib/rspec/core.rb +14 -21
  51. data/spec/autotest/discover_spec.rb +2 -2
  52. data/spec/autotest/failed_results_re_spec.rb +29 -21
  53. data/spec/autotest/rspec_spec.rb +3 -3
  54. data/spec/rspec/core/command_line_spec.rb +1 -6
  55. data/spec/rspec/core/configuration_options_spec.rb +111 -27
  56. data/spec/rspec/core/configuration_spec.rb +161 -37
  57. data/spec/rspec/core/deprecations_spec.rb +2 -2
  58. data/spec/rspec/core/drb_command_line_spec.rb +6 -6
  59. data/spec/rspec/core/example_group_spec.rb +197 -61
  60. data/spec/rspec/core/example_spec.rb +33 -16
  61. data/spec/rspec/core/formatters/base_formatter_spec.rb +3 -3
  62. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +222 -71
  63. data/spec/rspec/core/formatters/helpers_spec.rb +8 -8
  64. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +90 -26
  65. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +12 -11
  66. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +12 -11
  67. data/spec/rspec/core/formatters/{html_formatted-1.9.1.html → html_formatted-1.9.3.html} +12 -11
  68. data/spec/rspec/core/formatters/html_formatter_spec.rb +5 -5
  69. data/spec/rspec/core/formatters/progress_formatter_spec.rb +2 -2
  70. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +2 -2
  71. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +91 -27
  72. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +13 -12
  73. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +29 -28
  74. data/spec/rspec/core/formatters/{text_mate_formatted-1.9.1.html → text_mate_formatted-1.9.3.html} +29 -28
  75. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +2 -2
  76. data/spec/rspec/core/hooks_filtering_spec.rb +18 -18
  77. data/spec/rspec/core/let_spec.rb +19 -6
  78. data/spec/rspec/core/metadata_spec.rb +146 -61
  79. data/spec/rspec/core/pending_example_spec.rb +4 -4
  80. data/spec/rspec/core/rake_task_spec.rb +71 -50
  81. data/spec/rspec/core/reporter_spec.rb +2 -2
  82. data/spec/rspec/core/ruby_project_spec.rb +2 -2
  83. data/spec/rspec/core/runner_spec.rb +4 -1
  84. data/spec/rspec/core/shared_example_group_spec.rb +15 -119
  85. data/spec/rspec/core/subject_spec.rb +13 -13
  86. data/spec/rspec/core/world_spec.rb +31 -22
  87. data/spec/rspec/core_spec.rb +1 -29
  88. data/spec/spec_helper.rb +51 -50
  89. data/spec/support/shared_example_groups.rb +3 -3
  90. data/spec/support/spec_files.rb +8 -8
  91. metadata +79 -94
  92. data/.document +0 -5
  93. data/.gitignore +0 -12
  94. data/.rspec +0 -0
  95. data/.travis.yml +0 -7
  96. data/Gemfile +0 -50
  97. data/Guardfile +0 -5
  98. data/License.txt +0 -23
  99. data/Rakefile +0 -89
  100. data/cucumber.yml +0 -2
  101. data/features/.nav +0 -57
  102. data/features/Changelog.md +0 -269
  103. data/rspec-core.gemspec +0 -24
  104. data/script/FullBuildRakeFile +0 -63
  105. data/script/console +0 -8
  106. data/script/cucumber +0 -1
  107. data/script/full_build +0 -1
  108. data/script/spec +0 -1
  109. data/spec/rspec/core/formatters/html_formatted-1.8.6.html +0 -398
  110. data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +0 -398
  111. data/spec.txt +0 -1126
  112. /data/{bin → exe}/autospec +0 -0
  113. /data/{bin → exe}/rspec +0 -0
@@ -28,12 +28,12 @@ module RSpec::Core
28
28
 
29
29
  it 'processes string args as part of the description' do
30
30
  group = ExampleGroup.describe("some", "separate", "strings")
31
- group.description.should == "some separate strings"
31
+ group.description.should eq("some separate strings")
32
32
  end
33
33
 
34
34
  it 'processes symbol args as part of the description' do
35
35
  group = ExampleGroup.describe(:some, :separate, :symbols)
36
- group.description.should == "some separate symbols"
36
+ group.description.should eq("some separate symbols")
37
37
  end
38
38
  end
39
39
 
@@ -48,7 +48,7 @@ module RSpec::Core
48
48
  end
49
49
 
50
50
  it 'treats the first argument as part of the description when it is a symbol' do
51
- group.description.should == "symbol"
51
+ group.description.should eq("symbol")
52
52
  end
53
53
  end
54
54
 
@@ -95,7 +95,7 @@ module RSpec::Core
95
95
  describe("grandchild 2") {}
96
96
  end
97
97
  end
98
- group.descendants.size.should == 4
98
+ group.descendants.size.should eq(4)
99
99
  end
100
100
  end
101
101
  end
@@ -104,7 +104,7 @@ module RSpec::Core
104
104
  it "is known by parent" do
105
105
  parent = ExampleGroup.describe
106
106
  child = parent.describe
107
- parent.children.should == [child]
107
+ parent.children.should eq([child])
108
108
  end
109
109
 
110
110
  it "is not registered in world" do
@@ -112,7 +112,7 @@ module RSpec::Core
112
112
  parent = ExampleGroup.describe
113
113
  world.register(parent)
114
114
  child = parent.describe
115
- world.example_groups.should == [parent]
115
+ world.example_groups.should eq([parent])
116
116
  end
117
117
  end
118
118
 
@@ -128,7 +128,7 @@ module RSpec::Core
128
128
  group.stub(:world) { world }
129
129
  all_examples = [ group.example("first"), group.example("second") ]
130
130
 
131
- group.filtered_examples.should == all_examples
131
+ group.filtered_examples.should eq(all_examples)
132
132
  end
133
133
 
134
134
  it "includes examples directly matching filter" do
@@ -140,7 +140,7 @@ module RSpec::Core
140
140
  ]
141
141
  group.example("third (not-filtered)")
142
142
 
143
- group.filtered_examples.should == filtered_examples
143
+ group.filtered_examples.should eq(filtered_examples)
144
144
  end
145
145
  end
146
146
 
@@ -163,7 +163,7 @@ module RSpec::Core
163
163
  ]
164
164
  unfiltered_example = group.example("third (not-filtered)")
165
165
 
166
- group.filtered_examples.should == [unfiltered_example]
166
+ group.filtered_examples.should eq([unfiltered_example])
167
167
  end
168
168
  end
169
169
  end
@@ -239,7 +239,7 @@ module RSpec::Core
239
239
  group = ExampleGroup.describe
240
240
  group.stub(:world) { world }
241
241
  example = group.example("does something")
242
- group.filtered_examples.should == [example]
242
+ group.filtered_examples.should eq([example])
243
243
  end
244
244
  end
245
245
 
@@ -249,7 +249,7 @@ module RSpec::Core
249
249
  group = ExampleGroup.describe
250
250
  group.stub(:world) { world }
251
251
  example = group.example("does something")
252
- group.filtered_examples.should == []
252
+ group.filtered_examples.should eq([])
253
253
  end
254
254
  end
255
255
  end
@@ -258,7 +258,7 @@ module RSpec::Core
258
258
 
259
259
  context "with a constant as the first parameter" do
260
260
  it "is that constant" do
261
- ExampleGroup.describe(Object) { }.describes.should == Object
261
+ ExampleGroup.describe(Object) { }.describes.should eq(Object)
262
262
  end
263
263
  end
264
264
 
@@ -308,7 +308,7 @@ module RSpec::Core
308
308
  describe '#description' do
309
309
  it "grabs the description from the metadata" do
310
310
  group = ExampleGroup.describe(Object, "my desc") { }
311
- group.description.should == group.metadata[:example_group][:description]
311
+ group.description.should eq(group.metadata[:example_group][:description])
312
312
  end
313
313
  end
314
314
 
@@ -318,15 +318,15 @@ module RSpec::Core
318
318
  end
319
319
 
320
320
  it "adds the the file_path to metadata" do
321
- ExampleGroup.describe(Object) { }.metadata[:example_group][:file_path].should == __FILE__
321
+ ExampleGroup.describe(Object) { }.metadata[:example_group][:file_path].should eq(__FILE__)
322
322
  end
323
323
 
324
324
  it "has a reader for file_path" do
325
- ExampleGroup.describe(Object) { }.file_path.should == __FILE__
325
+ ExampleGroup.describe(Object) { }.file_path.should eq(__FILE__)
326
326
  end
327
327
 
328
328
  it "adds the line_number to metadata" do
329
- ExampleGroup.describe(Object) { }.metadata[:example_group][:line_number].should == __LINE__
329
+ ExampleGroup.describe(Object) { }.metadata[:example_group][:line_number].should eq(__LINE__)
330
330
  end
331
331
  end
332
332
 
@@ -454,7 +454,7 @@ module RSpec::Core
454
454
 
455
455
  group.run
456
456
 
457
- order.should == [
457
+ order.should eq([
458
458
  :before_all_defined_in_config,
459
459
  :top_level_before_all,
460
460
  :before_each,
@@ -470,7 +470,7 @@ module RSpec::Core
470
470
  :nested_after_all,
471
471
  :top_level_after_all,
472
472
  :after_all_defined_in_config
473
- ]
473
+ ])
474
474
  end
475
475
 
476
476
  context "after(:all)" do
@@ -509,22 +509,22 @@ module RSpec::Core
509
509
  it "treats an error in before(:each) as a failure" do
510
510
  group = ExampleGroup.describe
511
511
  group.before(:each) { raise "error in before each" }
512
- example = group.example("equality") { 1.should == 2}
513
- group.run.should == false
512
+ example = group.example("equality") { 1.should eq(2) }
513
+ group.run.should be(false)
514
514
 
515
- example.metadata[:execution_result][:exception].message.should == "error in before each"
515
+ example.metadata[:execution_result][:exception].message.should eq("error in before each")
516
516
  end
517
517
 
518
518
  it "treats an error in before(:all) as a failure" do
519
519
  group = ExampleGroup.describe
520
520
  group.before(:all) { raise "error in before all" }
521
- example = group.example("equality") { 1.should == 2}
522
- group.run.should == false
521
+ example = group.example("equality") { 1.should eq(2) }
522
+ group.run.should be_false
523
523
 
524
524
  example.metadata.should_not be_nil
525
525
  example.metadata[:execution_result].should_not be_nil
526
526
  example.metadata[:execution_result][:exception].should_not be_nil
527
- example.metadata[:execution_result][:exception].message.should == "error in before all"
527
+ example.metadata[:execution_result][:exception].message.should eq("error in before all")
528
528
  end
529
529
 
530
530
  it "treats an error in before(:all) as a failure for a spec in a nested group" do
@@ -533,7 +533,7 @@ module RSpec::Core
533
533
  before(:all) { raise "error in before all" }
534
534
 
535
535
  describe "nested" do
536
- example = it("equality") { 1.should == 2}
536
+ example = it("equality") { 1.should eq(2) }
537
537
  end
538
538
  end
539
539
  group.run
@@ -541,7 +541,7 @@ module RSpec::Core
541
541
  example.metadata.should_not be_nil
542
542
  example.metadata[:execution_result].should_not be_nil
543
543
  example.metadata[:execution_result][:exception].should_not be_nil
544
- example.metadata[:execution_result][:exception].message.should == "error in before all"
544
+ example.metadata[:execution_result][:exception].message.should eq("error in before all")
545
545
  end
546
546
 
547
547
  context "when an error occurs in an after(:all) hook" do
@@ -552,7 +552,7 @@ module RSpec::Core
552
552
  let(:group) do
553
553
  ExampleGroup.describe do
554
554
  after(:all) { raise "error in after all" }
555
- it("equality") { 1.should == 1 }
555
+ it("equality") { 1.should eq(1) }
556
556
  end
557
557
  end
558
558
 
@@ -561,7 +561,7 @@ module RSpec::Core
561
561
  example = group.examples.first
562
562
  example.metadata.should_not be_nil
563
563
  example.metadata[:execution_result].should_not be_nil
564
- example.metadata[:execution_result][:status].should == "passed"
564
+ example.metadata[:execution_result][:status].should eq("passed")
565
565
  end
566
566
 
567
567
  it "rescues the error and prints it out" do
@@ -576,7 +576,7 @@ module RSpec::Core
576
576
  group.before(:all) { running_example = example }
577
577
  group.example("no-op") { }
578
578
  group.run
579
- running_example.should == nil
579
+ running_example.should be(nil)
580
580
  end
581
581
 
582
582
  it "has access to example options within before(:each)" do
@@ -585,7 +585,7 @@ module RSpec::Core
585
585
  group.before(:each) { option = example.options[:data] }
586
586
  group.example("no-op", :data => :sample) { }
587
587
  group.run
588
- option.should == :sample
588
+ option.should eq(:sample)
589
589
  end
590
590
 
591
591
  it "has access to example options within after(:each)" do
@@ -594,7 +594,7 @@ module RSpec::Core
594
594
  group.after(:each) { option = example.options[:data] }
595
595
  group.example("no-op", :data => :sample) { }
596
596
  group.run
597
- option.should == :sample
597
+ option.should eq(:sample)
598
598
  end
599
599
 
600
600
  it "has no 'running example' within after(:all)" do
@@ -603,7 +603,24 @@ module RSpec::Core
603
603
  group.after(:all) { running_example = example }
604
604
  group.example("no-op") { }
605
605
  group.run
606
- running_example.should == nil
606
+ running_example.should be(nil)
607
+ end
608
+ end
609
+
610
+ matcher :add_a_pending_example_with do |method_name|
611
+ match do |group|
612
+ group = ExampleGroup.describe
613
+ group.send(method_name, "is pending") { }
614
+ group.run
615
+ group.examples.first.should be_pending
616
+ end
617
+ end
618
+
619
+ %w[pending xit xspecify xexample].each do |method_name|
620
+ describe "##{method_name}" do
621
+ it "generates a pending example" do
622
+ ExampleGroup.describe.should add_a_pending_example_with(method_name)
623
+ end
607
624
  end
608
625
  end
609
626
 
@@ -612,14 +629,7 @@ module RSpec::Core
612
629
  it "allows adding an example using 'it'" do
613
630
  group = ExampleGroup.describe
614
631
  group.it("should do something") { }
615
- group.examples.size.should == 1
616
- end
617
-
618
- it "allows adding a pending example using 'xit'" do
619
- group = ExampleGroup.describe
620
- group.xit("is pending") { }
621
- group.run
622
- group.examples.first.should be_pending
632
+ group.examples.size.should eq(1)
623
633
  end
624
634
 
625
635
  it "exposes all examples at examples" do
@@ -635,9 +645,9 @@ module RSpec::Core
635
645
  group.it("should 1") { }
636
646
  group.it("should 2") { }
637
647
  group.it("should 3") { }
638
- group.examples[0].description.should == 'should 1'
639
- group.examples[1].description.should == 'should 2'
640
- group.examples[2].description.should == 'should 3'
648
+ group.examples[0].description.should eq('should 1')
649
+ group.examples[1].description.should eq('should 2')
650
+ group.examples[2].description.should eq('should 3')
641
651
  end
642
652
 
643
653
  end
@@ -650,7 +660,7 @@ module RSpec::Core
650
660
  end
651
661
 
652
662
  it "sets the description to 'A sample nested describe'" do
653
- example.example_group.description.should == 'A sample nested group'
663
+ example.example_group.description.should eq('A sample nested group')
654
664
  end
655
665
 
656
666
  it "has top level metadata from the example_group and its ancestors" do
@@ -670,8 +680,8 @@ module RSpec::Core
670
680
 
671
681
  it "returns true if all examples pass" do
672
682
  group = ExampleGroup.describe('group') do
673
- example('ex 1') { 1.should == 1 }
674
- example('ex 2') { 1.should == 1 }
683
+ example('ex 1') { 1.should eq(1) }
684
+ example('ex 2') { 1.should eq(1) }
675
685
  end
676
686
  group.stub(:filtered_examples) { group.examples }
677
687
  group.run(reporter).should be_true
@@ -679,8 +689,8 @@ module RSpec::Core
679
689
 
680
690
  it "returns false if any of the examples fail" do
681
691
  group = ExampleGroup.describe('group') do
682
- example('ex 1') { 1.should == 1 }
683
- example('ex 2') { 1.should == 2 }
692
+ example('ex 1') { 1.should eq(1) }
693
+ example('ex 2') { 1.should eq(2) }
684
694
  end
685
695
  group.stub(:filtered_examples) { group.examples }
686
696
  group.run(reporter).should be_false
@@ -688,8 +698,8 @@ module RSpec::Core
688
698
 
689
699
  it "runs all examples, regardless of any of them failing" do
690
700
  group = ExampleGroup.describe('group') do
691
- example('ex 1') { 1.should == 2 }
692
- example('ex 2') { 1.should == 1 }
701
+ example('ex 1') { 1.should eq(2) }
702
+ example('ex 2') { 1.should eq(1) }
693
703
  end
694
704
  group.stub(:filtered_examples) { group.examples }
695
705
  group.filtered_examples.each do |example|
@@ -709,11 +719,11 @@ module RSpec::Core
709
719
  end
710
720
 
711
721
  it "can access a before each ivar at the same level" do
712
- @before_each_top_level.should == 'before_each_top_level'
722
+ @before_each_top_level.should eq('before_each_top_level')
713
723
  end
714
724
 
715
725
  it "can access a before all ivar at the same level" do
716
- @before_all_top_level.should == 'before_all_top_level'
726
+ @before_all_top_level.should eq('before_all_top_level')
717
727
  end
718
728
 
719
729
  it "can access the before all ivars in the before_all_ivars hash", :ruby => 1.8 do
@@ -726,11 +736,11 @@ module RSpec::Core
726
736
 
727
737
  describe "but now I am nested" do
728
738
  it "can access a parent example groups before each ivar at a nested level" do
729
- @before_each_top_level.should == 'before_each_top_level'
739
+ @before_each_top_level.should eq('before_each_top_level')
730
740
  end
731
741
 
732
742
  it "can access a parent example groups before all ivar at a nested level" do
733
- @before_all_top_level.should == "before_all_top_level"
743
+ @before_all_top_level.should eq("before_all_top_level")
734
744
  end
735
745
 
736
746
  it "changes to before all ivars from within an example do not persist outside the current describe" do
@@ -739,7 +749,7 @@ module RSpec::Core
739
749
 
740
750
  describe "accessing a before_all ivar that was changed in a parent example_group" do
741
751
  it "does not have access to the modified version" do
742
- @before_all_top_level.should == 'before_all_top_level'
752
+ @before_all_top_level.should eq('before_all_top_level')
743
753
  end
744
754
  end
745
755
  end
@@ -749,12 +759,12 @@ module RSpec::Core
749
759
  describe "ivars are not shared across examples" do
750
760
  it "(first example)" do
751
761
  @a = 1
752
- @b.should be_nil
762
+ defined?(@b).should be_false
753
763
  end
754
764
 
755
765
  it "(second example)" do
756
766
  @b = 2
757
- @a.should be_nil
767
+ defined?(@a).should be_false
758
768
  end
759
769
  end
760
770
 
@@ -769,7 +779,7 @@ module RSpec::Core
769
779
  end
770
780
  end
771
781
 
772
- group.top_level_description.should == "top"
782
+ group.top_level_description.should eq("top")
773
783
  end
774
784
  end
775
785
 
@@ -826,7 +836,7 @@ module RSpec::Core
826
836
  it "does something" do
827
837
  # pass
828
838
  end
829
- describe ("nested") do
839
+ describe "nested" do
830
840
  it "does something else" do
831
841
  # pass
832
842
  end
@@ -843,7 +853,7 @@ module RSpec::Core
843
853
  it "does something (wrong - fail)" do
844
854
  raise "fail"
845
855
  end
846
- describe ("nested") do
856
+ describe "nested" do
847
857
  it "does something else" do
848
858
  # pass
849
859
  end
@@ -860,7 +870,7 @@ module RSpec::Core
860
870
  it "does something" do
861
871
  # pass
862
872
  end
863
- describe ("nested") do
873
+ describe "nested" do
864
874
  it "does something else (wrong -fail)" do
865
875
  raise "fail"
866
876
  end
@@ -888,6 +898,15 @@ module RSpec::Core
888
898
  end
889
899
  group.run.should be_true
890
900
  end
901
+
902
+ it "raises a helpful error message when shared context is not found" do
903
+ expect do
904
+ ExampleGroup.describe do
905
+ include_context "shared stuff"
906
+ end
907
+ end.to raise_error(ArgumentError,%q|Could not find shared context "shared stuff"|)
908
+ end
909
+
891
910
  end
892
911
 
893
912
  describe "#include_examples" do
@@ -904,7 +923,124 @@ module RSpec::Core
904
923
  end
905
924
  group.examples.first.description.should eq("does something")
906
925
  end
926
+
927
+ it "raises a helpful error message when shared context is not found" do
928
+ expect do
929
+ ExampleGroup.describe do
930
+ include_examples "shared stuff"
931
+ end
932
+ end.to raise_error(ArgumentError,%q|Could not find shared examples "shared stuff"|)
933
+ end
907
934
  end
908
935
 
936
+ describe "#it_should_behave_like" do
937
+ it "creates a nested group" do
938
+ shared_examples_for("thing") {}
939
+ group = ExampleGroup.describe('fake group')
940
+ group.it_should_behave_like("thing")
941
+ group.should have(1).children
942
+ end
943
+
944
+ it "creates a nested group for a class" do
945
+ klass = Class.new
946
+ shared_examples_for(klass) {}
947
+ group = ExampleGroup.describe('fake group')
948
+ group.it_should_behave_like(klass)
949
+ group.should have(1).children
950
+ end
951
+
952
+ it "adds shared examples to nested group" do
953
+ shared_examples_for("thing") do
954
+ it("does something")
955
+ end
956
+ group = ExampleGroup.describe('fake group')
957
+ shared_group = group.it_should_behave_like("thing")
958
+ shared_group.should have(1).examples
959
+ end
960
+
961
+ it "adds shared instance methods to nested group" do
962
+ shared_examples_for("thing") do
963
+ def foo; end
964
+ end
965
+ group = ExampleGroup.describe('fake group')
966
+ shared_group = group.it_should_behave_like("thing")
967
+ shared_group.public_instance_methods.map{|m| m.to_s}.should include("foo")
968
+ end
969
+
970
+ it "adds shared class methods to nested group" do
971
+ shared_examples_for("thing") do
972
+ def self.foo; end
973
+ end
974
+ group = ExampleGroup.describe('fake group')
975
+ shared_group = group.it_should_behave_like("thing")
976
+ shared_group.methods.map{|m| m.to_s}.should include("foo")
977
+ end
978
+
979
+ context "given some parameters" do
980
+ it "passes the parameters to the shared example group" do
981
+ passed_params = {}
982
+
983
+ shared_examples_for("thing") do |param1, param2|
984
+ it("has access to the given parameters") do
985
+ passed_params[:param1] = param1
986
+ passed_params[:param2] = param2
987
+ end
988
+ end
989
+
990
+ group = ExampleGroup.describe("group") do
991
+ it_should_behave_like "thing", :value1, :value2
992
+ end
993
+ group.run
994
+
995
+ passed_params.should eq({ :param1 => :value1, :param2 => :value2 })
996
+ end
997
+
998
+ it "adds shared instance methods to nested group" do
999
+ shared_examples_for("thing") do |param1|
1000
+ def foo; end
1001
+ end
1002
+ group = ExampleGroup.describe('fake group')
1003
+ shared_group = group.it_should_behave_like("thing", :a)
1004
+ shared_group.public_instance_methods.map{|m| m.to_s}.should include("foo")
1005
+ end
1006
+
1007
+ it "evals the shared example group only once" do
1008
+ eval_count = 0
1009
+ shared_examples_for("thing") { |p| eval_count += 1 }
1010
+ group = ExampleGroup.describe('fake group')
1011
+ shared_group = group.it_should_behave_like("thing", :a)
1012
+ eval_count.should eq(1)
1013
+ end
1014
+ end
1015
+
1016
+ context "given a block" do
1017
+ it "evaluates the block in nested group" do
1018
+ scopes = []
1019
+ shared_examples_for("thing") do
1020
+ it("gets run in the nested group") do
1021
+ scopes << self.class
1022
+ end
1023
+ end
1024
+ group = ExampleGroup.describe("group") do
1025
+ it_should_behave_like "thing" do
1026
+ it("gets run in the same nested group") do
1027
+ scopes << self.class
1028
+ end
1029
+ end
1030
+ end
1031
+ group.run
1032
+
1033
+ scopes[0].should be(scopes[1])
1034
+ end
1035
+ end
1036
+
1037
+ it "raises a helpful error message when shared context is not found" do
1038
+ expect do
1039
+ ExampleGroup.describe do
1040
+ it_should_behave_like "shared stuff"
1041
+ end
1042
+ end.to raise_error(ArgumentError,%q|Could not find shared examples "shared stuff"|)
1043
+ end
1044
+ end
909
1045
  end
910
1046
  end
@@ -16,9 +16,24 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
16
16
  end
17
17
  end
18
18
 
19
+ describe "#exception" do
20
+ it "supplies the first exception raised, if any" do
21
+ example = example_group.example { raise "first" }
22
+ example_group.after { raise "second" }
23
+ example_group.run
24
+ example.exception.message.should eq("first")
25
+ end
26
+
27
+ it "returns nil if there is no exception" do
28
+ example = example_group.example('example') { }
29
+ example_group.run
30
+ example.exception.should be_nil
31
+ end
32
+ end
33
+
19
34
  describe "auto-generated example descriptions" do
20
35
  let(:generated_description) { "the generated description" }
21
- let(:rspec_example) { example_group.specify { 5.should == 5 } }
36
+ let(:rspec_example) { example_group.specify { 5.should eq(5) } }
22
37
  before(:each) { RSpec::Matchers.stub(:generated_description => generated_description) }
23
38
 
24
39
  def expect_with(*frameworks)
@@ -71,13 +86,13 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
71
86
 
72
87
  describe '#described_class' do
73
88
  it "returns the class (if any) of the outermost example group" do
74
- described_class.should == RSpec::Core::Example
89
+ described_class.should eq(RSpec::Core::Example)
75
90
  end
76
91
  end
77
92
 
78
93
  describe "accessing metadata within a running example" do
79
94
  it "has a reference to itself when running" do
80
- example.description.should == "has a reference to itself when running"
95
+ example.description.should eq("has a reference to itself when running")
81
96
  end
82
97
 
83
98
  it "can access the example group's top level metadata as if it were its own" do
@@ -88,7 +103,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
88
103
 
89
104
  describe "accessing options within a running example" do
90
105
  it "can look up option values by key", :demo => :data do
91
- example.options[:demo].should == :data
106
+ example.options[:demo].should eq(:data)
92
107
  end
93
108
  end
94
109
 
@@ -105,7 +120,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
105
120
  after_run = false
106
121
  group = RSpec::Core::ExampleGroup.describe do
107
122
  after(:each) { after_run = true }
108
- example('example') { 1.should == 1 }
123
+ example('example') { 1.should eq(1) }
109
124
  end
110
125
  group.run
111
126
  after_run.should be_true, "expected after(:each) to be run"
@@ -115,7 +130,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
115
130
  after_run = false
116
131
  group = RSpec::Core::ExampleGroup.describe do
117
132
  after(:each) { after_run = true }
118
- example('example') { 1.should == 2 }
133
+ example('example') { 1.should eq(2) }
119
134
  end
120
135
  group.run
121
136
  after_run.should be_true, "expected after(:each) to be run"
@@ -137,7 +152,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
137
152
  group = RSpec::Core::ExampleGroup.describe do
138
153
  after(:each) { after_run = true }
139
154
  after(:each) { raise "FOO" }
140
- example('example') { 1.should == 1 }
155
+ example('example') { 1.should eq(1) }
141
156
  end
142
157
  group.run
143
158
  after_run.should be_true, "expected after(:each) to be run"
@@ -146,11 +161,11 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
146
161
  it "stores the exception" do
147
162
  group = RSpec::Core::ExampleGroup.describe
148
163
  group.after(:each) { raise "FOO" }
149
- example = group.example('example') { 1.should == 1 }
164
+ example = group.example('example') { 1.should eq(1) }
150
165
 
151
166
  group.run
152
167
 
153
- example.metadata[:execution_result][:exception].message.should == "FOO"
168
+ example.metadata[:execution_result][:exception].message.should eq("FOO")
154
169
  end
155
170
  end
156
171
 
@@ -185,14 +200,15 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
185
200
  after(:each) { @after_each = :after_each }
186
201
  after(:all) { @after_all = :after_all }
187
202
  end
188
- example = group.example("does something") do
189
- @in_example = :in_example
203
+ group.example("does something") do
204
+ @before_all.should eq(:before_all)
205
+ @before_each.should eq(:before_each)
190
206
  end
191
- example_group_instance = group.new
192
- example.run(example_group_instance, double('reporter').as_null_object)
193
-
194
- %w[@before_all @before_each @after_each @after_all].each do |ivar|
195
- example_group_instance.instance_variable_get(ivar).should be_nil
207
+ group.run(double.as_null_object).should be_true
208
+ group.new do |example|
209
+ %w[@before_all @before_each @after_each @after_all].each do |ivar|
210
+ example.instance_variable_get(ivar).should be_nil
211
+ end
196
212
  end
197
213
  end
198
214
 
@@ -269,4 +285,5 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
269
285
  end
270
286
 
271
287
  end
288
+
272
289
  end