rspec-core 2.6.4 → 2.7.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/README.md +1 -1
  2. data/{bin → exe}/autospec +0 -0
  3. data/{bin → exe}/rspec +0 -0
  4. data/features/Upgrade.md +11 -0
  5. data/features/command_line/exit_status.feature +20 -3
  6. data/features/command_line/format_option.feature +8 -0
  7. data/features/command_line/line_number_appended_to_path.feature +35 -1
  8. data/features/command_line/line_number_option.feature +16 -3
  9. data/features/command_line/pattern_option.feature +31 -0
  10. data/features/command_line/rake_task.feature +1 -1
  11. data/features/command_line/ruby.feature +22 -0
  12. data/features/configuration/default_path.feature +38 -0
  13. data/features/example_groups/{shared_example_group.feature → shared_examples.feature} +49 -26
  14. data/features/expectation_framework_integration/configure_expectation_framework.feature +1 -1
  15. data/features/filtering/inclusion_filters.feature +4 -5
  16. data/features/formatters/text_formatter.feature +16 -13
  17. data/features/helper_methods/let.feature +4 -4
  18. data/features/hooks/around_hooks.feature +1 -1
  19. data/features/hooks/before_and_after_hooks.feature +3 -3
  20. data/features/hooks/filtering.feature +13 -6
  21. data/features/metadata/user_defined.feature +12 -10
  22. data/features/pending/pending_examples.feature +21 -8
  23. data/features/step_definitions/additional_cli_steps.rb +1 -1
  24. data/features/subject/attribute_of_subject.feature +2 -2
  25. data/features/support/env.rb +1 -2
  26. data/lib/rspec/core.rb +1 -23
  27. data/lib/rspec/core/configuration.rb +64 -16
  28. data/lib/rspec/core/configuration_options.rb +11 -4
  29. data/lib/rspec/core/example.rb +10 -7
  30. data/lib/rspec/core/example_group.rb +34 -18
  31. data/lib/rspec/core/formatters/base_text_formatter.rb +10 -2
  32. data/lib/rspec/core/formatters/html_formatter.rb +3 -1
  33. data/lib/rspec/core/formatters/snippet_extractor.rb +9 -3
  34. data/lib/rspec/core/formatters/text_mate_formatter.rb +20 -6
  35. data/lib/rspec/core/hooks.rb +2 -2
  36. data/lib/rspec/core/let.rb +5 -5
  37. data/lib/rspec/core/metadata.rb +136 -94
  38. data/lib/rspec/core/option_parser.rb +10 -5
  39. data/lib/rspec/core/pending.rb +2 -1
  40. data/lib/rspec/core/rake_task.rb +26 -15
  41. data/lib/rspec/core/reporter.rb +2 -3
  42. data/lib/rspec/core/runner.rb +1 -1
  43. data/lib/rspec/core/shared_example_group.rb +4 -4
  44. data/lib/rspec/core/subject.rb +7 -7
  45. data/lib/rspec/core/version.rb +1 -1
  46. data/lib/rspec/core/world.rb +4 -8
  47. data/spec/autotest/discover_spec.rb +2 -2
  48. data/spec/autotest/failed_results_re_spec.rb +29 -21
  49. data/spec/autotest/rspec_spec.rb +3 -3
  50. data/spec/rspec/core/command_line_spec.rb +1 -6
  51. data/spec/rspec/core/configuration_options_spec.rb +65 -13
  52. data/spec/rspec/core/configuration_spec.rb +148 -37
  53. data/spec/rspec/core/deprecations_spec.rb +2 -2
  54. data/spec/rspec/core/drb_command_line_spec.rb +6 -6
  55. data/spec/rspec/core/example_group_spec.rb +197 -61
  56. data/spec/rspec/core/example_spec.rb +33 -16
  57. data/spec/rspec/core/formatters/base_formatter_spec.rb +3 -3
  58. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +149 -1
  59. data/spec/rspec/core/formatters/helpers_spec.rb +8 -8
  60. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +85 -17
  61. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +12 -11
  62. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +12 -11
  63. data/spec/rspec/core/formatters/{html_formatted-1.9.1.html → html_formatted-1.9.3.html} +12 -11
  64. data/spec/rspec/core/formatters/html_formatter_spec.rb +5 -5
  65. data/spec/rspec/core/formatters/progress_formatter_spec.rb +2 -2
  66. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +2 -2
  67. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +86 -18
  68. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +13 -12
  69. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +29 -28
  70. data/spec/rspec/core/formatters/{text_mate_formatted-1.9.1.html → text_mate_formatted-1.9.3.html} +29 -28
  71. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +2 -2
  72. data/spec/rspec/core/hooks_filtering_spec.rb +18 -18
  73. data/spec/rspec/core/let_spec.rb +19 -6
  74. data/spec/rspec/core/metadata_spec.rb +146 -61
  75. data/spec/rspec/core/pending_example_spec.rb +4 -4
  76. data/spec/rspec/core/rake_task_spec.rb +71 -50
  77. data/spec/rspec/core/reporter_spec.rb +2 -2
  78. data/spec/rspec/core/ruby_project_spec.rb +2 -2
  79. data/spec/rspec/core/runner_spec.rb +4 -1
  80. data/spec/rspec/core/shared_example_group_spec.rb +15 -119
  81. data/spec/rspec/core/subject_spec.rb +13 -13
  82. data/spec/rspec/core/world_spec.rb +31 -22
  83. data/spec/rspec/core_spec.rb +1 -29
  84. data/spec/spec_helper.rb +51 -49
  85. data/spec/support/shared_example_groups.rb +3 -3
  86. data/spec/support/spec_files.rb +8 -8
  87. metadata +79 -93
  88. data/.document +0 -5
  89. data/.gitignore +0 -12
  90. data/.rspec +0 -0
  91. data/.travis.yml +0 -9
  92. data/Changelog.md +0 -305
  93. data/Gemfile +0 -49
  94. data/Guardfile +0 -5
  95. data/License.txt +0 -23
  96. data/Rakefile +0 -93
  97. data/cucumber.yml +0 -2
  98. data/features/.nav +0 -57
  99. data/rspec-core.gemspec +0 -24
  100. data/script/FullBuildRakeFile +0 -63
  101. data/script/console +0 -8
  102. data/script/cucumber +0 -1
  103. data/script/full_build +0 -1
  104. data/script/spec +0 -1
  105. data/spec.txt +0 -1126
  106. data/spec/rspec/core/formatters/html_formatted-1.8.6.html +0 -398
  107. data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +0 -398
@@ -71,6 +71,18 @@ module RSpec::Core
71
71
  config.should_receive(:require).with('rspec/core/mocking/with_absolutely_nothing')
72
72
  config.mock_framework = :crazy_new_mocking_framework_ive_not_yet_heard_of
73
73
  end
74
+
75
+ context 'when there are already some example groups defined' do
76
+ before(:each) do
77
+ RSpec.world.stub(:example_groups).and_return([double.as_null_object])
78
+ end
79
+
80
+ it 'raises an error since this setting must be applied before any groups are defined' do
81
+ expect {
82
+ config.mock_framework = :rspec
83
+ }.to raise_error(/must be configured before any example groups are defined/)
84
+ end
85
+ end
74
86
  end
75
87
 
76
88
  describe "#mock_with" do
@@ -109,6 +121,18 @@ module RSpec::Core
109
121
  config.expect_with :not_supported
110
122
  end.to raise_error(ArgumentError)
111
123
  end
124
+
125
+ context 'when there are already some example groups defined' do
126
+ before(:each) do
127
+ RSpec.world.stub(:example_groups).and_return([double.as_null_object])
128
+ end
129
+
130
+ it 'raises an error since this setting must be applied before any groups are defined' do
131
+ expect {
132
+ config.expect_with :rspec
133
+ }.to raise_error(/must be configured before any example groups are defined/)
134
+ end
135
+ end
112
136
  end
113
137
 
114
138
  describe "#expecting_with_rspec?" do
@@ -145,22 +169,47 @@ module RSpec::Core
145
169
 
146
170
  describe "#files_to_run" do
147
171
  it "loads files not following pattern if named explicitly" do
148
- file = "./spec/rspec/core/resources/a_bar.rb"
149
- config.files_or_directories_to_run = file
150
- config.files_to_run.should == [file]
172
+ config.files_or_directories_to_run = "spec/rspec/core/resources/a_bar.rb"
173
+ config.files_to_run.should eq([ "spec/rspec/core/resources/a_bar.rb"])
174
+ end
175
+
176
+ it "prevents repitition of dir when start of the pattern" do
177
+ config.pattern = "spec/**/a_spec.rb"
178
+ config.files_or_directories_to_run = "spec"
179
+ config.files_to_run.should eq(["spec/rspec/core/resources/a_spec.rb"])
180
+ end
181
+
182
+ it "does not prevent repitition of dir when later of the pattern" do
183
+ config.pattern = "rspec/**/a_spec.rb"
184
+ config.files_or_directories_to_run = "spec"
185
+ config.files_to_run.should eq(["spec/rspec/core/resources/a_spec.rb"])
151
186
  end
152
187
 
153
188
  context "with default pattern" do
154
189
  it "loads files named _spec.rb" do
155
- dir = "./spec/rspec/core/resources"
156
- config.files_or_directories_to_run = dir
157
- config.files_to_run.should == ["#{dir}/a_spec.rb"]
190
+ dir = "spec/rspec/core/resources"
191
+ config.files_or_directories_to_run = "spec/rspec/core/resources"
192
+ config.files_to_run.should eq([ "spec/rspec/core/resources/a_spec.rb"])
158
193
  end
159
194
 
160
195
  it "loads files in Windows" do
161
196
  file = "C:\\path\\to\\project\\spec\\sub\\foo_spec.rb"
162
197
  config.files_or_directories_to_run = file
163
- config.files_to_run.should == [file]
198
+ config.files_to_run.should eq([file])
199
+ end
200
+ end
201
+
202
+ context "with default default_path" do
203
+ it "loads files in the default path when run by rspec" do
204
+ config.stub(:command) { 'rspec' }
205
+ config.files_or_directories_to_run = []
206
+ config.files_to_run.should_not be_empty
207
+ end
208
+
209
+ it "does not load files in the default path when run by ruby" do
210
+ config.stub(:command) { 'ruby' }
211
+ config.files_or_directories_to_run = []
212
+ config.files_to_run.should be_empty
164
213
  end
165
214
  end
166
215
  end
@@ -209,9 +258,9 @@ module RSpec::Core
209
258
  end
210
259
 
211
260
  describe "path with line number" do
212
- it "assigns the line number as the filter" do
261
+ it "assigns the line number as a location filter" do
213
262
  config.files_or_directories_to_run = "path/to/a_spec.rb:37"
214
- config.filter.should == {:line_number => 37}
263
+ config.filter.should eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37]}})
215
264
  end
216
265
  end
217
266
 
@@ -221,10 +270,42 @@ module RSpec::Core
221
270
  config.full_description = "foo"
222
271
  config.filter.should_not have_key(:focused)
223
272
  end
273
+ end
224
274
 
225
- it "assigns the example name as the filter on description" do
226
- config.full_description = "foo"
227
- config.filter.should == {:full_description => /foo/}
275
+ context "with line number" do
276
+
277
+ it "assigns the file and line number as a location filter" do
278
+ config.files_or_directories_to_run = "path/to/a_spec.rb:37"
279
+ config.filter.should eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37]}})
280
+ end
281
+
282
+ it "assigns multiple files with line numbers as location filters" do
283
+ config.files_or_directories_to_run = "path/to/a_spec.rb:37", "other_spec.rb:44"
284
+ config.filter.should eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37],
285
+ File.expand_path("other_spec.rb") => [44]}})
286
+ end
287
+
288
+ it "assigns files with multiple line numbers as location filters" do
289
+ config.files_or_directories_to_run = "path/to/a_spec.rb:37", "path/to/a_spec.rb:44"
290
+ config.filter.should eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37, 44]}})
291
+ end
292
+ end
293
+
294
+ context "with multiple line numbers" do
295
+ it "assigns the file and line numbers as a location filter" do
296
+ config.files_or_directories_to_run = "path/to/a_spec.rb:1:3:5:7"
297
+ config.filter.should eq({:locations => {File.expand_path("path/to/a_spec.rb") => [1,3,5,7]}})
298
+ end
299
+ end
300
+
301
+ it "assigns the example name as the filter on description" do
302
+ config.full_description = "foo"
303
+ config.filter.should eq({:full_description => /foo/})
304
+ end
305
+
306
+ describe "#default_path" do
307
+ it 'defaults to "spec"' do
308
+ config.default_path.should eq('spec')
228
309
  end
229
310
  end
230
311
 
@@ -251,7 +332,7 @@ module RSpec::Core
251
332
 
252
333
  group = ExampleGroup.describe('does like, stuff and junk', :magic_key => :include) { }
253
334
  group.should_not respond_to(:you_call_this_a_blt?)
254
- group.new.you_call_this_a_blt?.should == "egad man, where's the mayo?!?!?"
335
+ group.new.you_call_this_a_blt?.should eq("egad man, where's the mayo?!?!?")
255
336
  end
256
337
  end
257
338
 
@@ -263,7 +344,7 @@ module RSpec::Core
263
344
 
264
345
  group = ExampleGroup.describe('does like, stuff and junk', :magic_key => :include) { }
265
346
  group.should_not respond_to(:you_call_this_a_blt?)
266
- group.new.you_call_this_a_blt?.should == "egad man, where's the mayo?!?!?"
347
+ group.new.you_call_this_a_blt?.should eq("egad man, where's the mayo?!?!?")
267
348
  end
268
349
  end
269
350
 
@@ -468,29 +549,29 @@ module RSpec::Core
468
549
  describe "#filter_run" do
469
550
  it_behaves_like "metadata hash builder" do
470
551
  def metadata_hash(*args)
471
- config.filter_run *args
552
+ config.filter_run(*args)
472
553
  config.filter
473
554
  end
474
555
  end
475
556
 
476
557
  it "sets the filter" do
477
558
  config.filter_run :focus => true
478
- config.filter[:focus].should == true
559
+ config.filter[:focus].should be(true)
479
560
  end
480
561
 
481
562
  it "merges with existing filters" do
482
563
  config.filter_run :filter1 => true
483
564
  config.filter_run :filter2 => false
484
565
 
485
- config.filter[:filter1].should == true
486
- config.filter[:filter2].should == false
566
+ config.filter[:filter1].should be(true)
567
+ config.filter[:filter2].should be(false)
487
568
  end
488
569
 
489
- it "warns if :line_number is already a filter" do
490
- config.filter_run :line_number => 100
570
+ it "warns if :line_numbers is already a filter" do
571
+ config.filter_run :line_numbers => [100]
491
572
  config.should_receive(:warn).with(
492
573
  "Filtering by {:focus=>true} is not possible since you " \
493
- "are already filtering by {:line_number=>100}"
574
+ "are already filtering by {:line_numbers=>[100]}"
494
575
  )
495
576
  config.filter_run :focus => true
496
577
  end
@@ -508,22 +589,22 @@ module RSpec::Core
508
589
  describe "#filter_run_excluding" do
509
590
  it_behaves_like "metadata hash builder" do
510
591
  def metadata_hash(*args)
511
- config.filter_run_excluding *args
592
+ config.filter_run_excluding(*args)
512
593
  config.exclusion_filter
513
594
  end
514
595
  end
515
596
 
516
597
  it "sets the filter" do
517
598
  config.filter_run_excluding :slow => true
518
- config.exclusion_filter[:slow].should == true
599
+ config.exclusion_filter[:slow].should be(true)
519
600
  end
520
601
 
521
602
  it "merges with existing filters" do
522
603
  config.filter_run_excluding :filter1 => true
523
604
  config.filter_run_excluding :filter2 => false
524
605
 
525
- config.exclusion_filter[:filter1].should == true
526
- config.exclusion_filter[:filter2].should == false
606
+ config.exclusion_filter[:filter1].should be(true)
607
+ config.exclusion_filter[:filter2].should be(false)
527
608
  end
528
609
  end
529
610
 
@@ -574,24 +655,24 @@ module RSpec::Core
574
655
  end
575
656
  end
576
657
 
577
- describe "#line_number=" do
658
+ describe "line_numbers=" do
578
659
  before { config.stub(:warn) }
579
660
 
580
- it "sets the line number" do
581
- config.line_number = '37'
582
- config.filter.should == {:line_number => 37}
661
+ it "sets the line numbers" do
662
+ config.line_numbers = ['37']
663
+ config.filter.should eq({:line_numbers => [37]})
583
664
  end
584
665
 
585
666
  it "overrides :focused" do
586
667
  config.filter_run :focused => true
587
- config.line_number = '37'
588
- config.filter.should == {:line_number => 37}
668
+ config.line_numbers = ['37']
669
+ config.filter.should eq({:line_numbers => [37]})
589
670
  end
590
671
 
591
672
  it "prevents :focused" do
592
- config.line_number = '37'
673
+ config.line_numbers = ['37']
593
674
  config.filter_run :focused => true
594
- config.filter.should == {:line_number => 37}
675
+ config.filter.should eq({:line_numbers => [37]})
595
676
  end
596
677
  end
597
678
 
@@ -599,14 +680,14 @@ module RSpec::Core
599
680
  context "given true" do
600
681
  it "clears the backtrace clean patterns" do
601
682
  config.full_backtrace = true
602
- config.backtrace_clean_patterns.should == []
683
+ config.backtrace_clean_patterns.should eq([])
603
684
  end
604
685
  end
605
686
 
606
687
  context "given false" do
607
688
  it "restores backtrace clean patterns" do
608
689
  config.full_backtrace = false
609
- config.backtrace_clean_patterns.should == RSpec::Core::Configuration::DEFAULT_BACKTRACE_PATTERNS
690
+ config.backtrace_clean_patterns.should eq(RSpec::Core::Configuration::DEFAULT_BACKTRACE_PATTERNS)
610
691
  end
611
692
  end
612
693
 
@@ -619,6 +700,23 @@ module RSpec::Core
619
700
  end
620
701
  end
621
702
 
703
+ describe "#cleaned_from_backtrace? defaults" do
704
+ it "returns true for rspec files" do
705
+ config.cleaned_from_backtrace?("lib/rspec/core.rb").
706
+ should be_true
707
+ end
708
+
709
+ it "returns true for spec_helper" do
710
+ config.cleaned_from_backtrace?("spec/spec_helper.rb").
711
+ should be_true
712
+ end
713
+
714
+ it "returns true for java files (for JRuby)" do
715
+ config.cleaned_from_backtrace?("org/jruby/RubyArray.java:2336").
716
+ should be_true
717
+ end
718
+ end
719
+
622
720
  describe "#debug=true" do
623
721
  before do
624
722
  if defined?(Debugger)
@@ -733,12 +831,12 @@ module RSpec::Core
733
831
 
734
832
  it "delegates the getter to the other option" do
735
833
  config.another_custom_option = "this value"
736
- config.custom_option.should == "this value"
834
+ config.custom_option.should eq("this value")
737
835
  end
738
836
 
739
837
  it "delegates the setter to the other option" do
740
838
  config.custom_option = "this value"
741
- config.another_custom_option.should == "this value"
839
+ config.another_custom_option.should eq("this value")
742
840
  end
743
841
 
744
842
  it "delegates the predicate to the other option" do
@@ -805,5 +903,18 @@ module RSpec::Core
805
903
  end
806
904
  end
807
905
 
906
+ describe "#reset" do
907
+ it "clears the reporter" do
908
+ config.reporter.should_not be_nil
909
+ config.reset
910
+ config.instance_variable_get("@reporter").should be_nil
911
+ end
912
+
913
+ it "clears the formatters" do
914
+ config.add_formatter "doc"
915
+ config.reset
916
+ config.formatters.should be_empty
917
+ end
918
+ end
808
919
  end
809
920
  end
@@ -9,7 +9,7 @@ describe "deprecations" do
9
9
 
10
10
  it "returns RSpec" do
11
11
  RSpec.stub(:warn_deprecation)
12
- Spec.should == RSpec
12
+ Spec.should eq(RSpec)
13
13
  end
14
14
 
15
15
  it "doesn't include backward compatibility in const_missing backtrace" do
@@ -32,7 +32,7 @@ describe "deprecations" do
32
32
 
33
33
  it "delegates to example" do
34
34
  RSpec.stub(:warn_deprecation)
35
- running_example.should == example
35
+ running_example.should eq(example)
36
36
  end
37
37
  end
38
38
  end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "::DRbCommandLine", :ruby => "!jruby" do
3
+ describe "::DRbCommandLine", :type => :drb, :unless => RUBY_PLATFORM == 'java' do
4
4
  let(:config) { RSpec::Core::Configuration.new }
5
5
  let(:out) { StringIO.new }
6
6
  let(:err) { StringIO.new }
@@ -41,14 +41,14 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
41
41
  context "without RSPEC_DRB environment variable set" do
42
42
  it "defaults to 8989" do
43
43
  with_RSPEC_DRB_set_to(nil) do
44
- command_line([]).drb_port.should == 8989
44
+ command_line([]).drb_port.should eq(8989)
45
45
  end
46
46
  end
47
47
 
48
48
  it "sets the DRb port" do
49
49
  with_RSPEC_DRB_set_to(nil) do
50
- command_line(["--drb-port", "1234"]).drb_port.should == 1234
51
- command_line(["--drb-port", "5678"]).drb_port.should == 5678
50
+ command_line(["--drb-port", "1234"]).drb_port.should eq(1234)
51
+ command_line(["--drb-port", "5678"]).drb_port.should eq(5678)
52
52
  end
53
53
  end
54
54
  end
@@ -58,7 +58,7 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
58
58
  context "without config variable set" do
59
59
  it "uses RSPEC_DRB value" do
60
60
  with_RSPEC_DRB_set_to('9000') do
61
- command_line([]).drb_port.should == "9000"
61
+ command_line([]).drb_port.should eq("9000")
62
62
  end
63
63
  end
64
64
  end
@@ -66,7 +66,7 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
66
66
  context "and config variable set" do
67
67
  it "uses configured value" do
68
68
  with_RSPEC_DRB_set_to('9000') do
69
- command_line(%w[--drb-port 5678]).drb_port.should == 5678
69
+ command_line(%w[--drb-port 5678]).drb_port.should eq(5678)
70
70
  end
71
71
  end
72
72
  end
@@ -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