rspec-core 2.5.2 → 2.6.0.rc2

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 (117) hide show
  1. data/.travis.yml +7 -0
  2. data/Gemfile +10 -13
  3. data/README.md +4 -1
  4. data/Rakefile +29 -12
  5. data/cucumber.yml +1 -1
  6. data/features/.nav +10 -4
  7. data/features/Autotest.md +31 -7
  8. data/features/Changelog.md +36 -6
  9. data/features/command_line/configure.feature +2 -2
  10. data/features/command_line/example_name_option.feature +10 -10
  11. data/features/command_line/exit_status.feature +4 -4
  12. data/features/command_line/format_option.feature +4 -4
  13. data/features/command_line/line_number_appended_to_path.feature +11 -11
  14. data/features/command_line/line_number_option.feature +2 -2
  15. data/features/command_line/rake_task.feature +3 -3
  16. data/features/command_line/tag.feature +26 -10
  17. data/features/configuration/alias_example_to.feature +48 -0
  18. data/features/configuration/custom_settings.feature +3 -3
  19. data/features/configuration/fail_fast.feature +3 -3
  20. data/features/configuration/read_options_from_file.feature +4 -4
  21. data/features/example_groups/basic_structure.feature +11 -15
  22. data/features/example_groups/shared_context.feature +74 -0
  23. data/features/example_groups/shared_example_group.feature +21 -17
  24. data/features/expectation_framework_integration/configure_expectation_framework.feature +15 -4
  25. data/features/filtering/exclusion_filters.feature +28 -4
  26. data/features/filtering/{implicit_filters.feature → if_and_unless.feature} +9 -7
  27. data/features/filtering/inclusion_filters.feature +26 -3
  28. data/features/filtering/run_all_when_everything_filtered.feature +1 -1
  29. data/features/formatters/custom_formatter.feature +1 -1
  30. data/features/formatters/text_formatter.feature +45 -0
  31. data/features/helper_methods/arbitrary_methods.feature +2 -2
  32. data/features/helper_methods/let.feature +2 -2
  33. data/features/helper_methods/modules.feature +149 -0
  34. data/features/hooks/around_hooks.feature +11 -11
  35. data/features/hooks/before_and_after_hooks.feature +15 -19
  36. data/features/hooks/filtering.feature +160 -124
  37. data/features/metadata/current_example.feature +17 -0
  38. data/features/metadata/described_class.feature +2 -2
  39. data/features/metadata/user_defined.feature +111 -0
  40. data/features/mock_framework_integration/use_any_framework.feature +1 -1
  41. data/features/mock_framework_integration/use_flexmock.feature +83 -10
  42. data/features/mock_framework_integration/use_mocha.feature +84 -10
  43. data/features/mock_framework_integration/use_rr.feature +85 -10
  44. data/features/mock_framework_integration/use_rspec.feature +84 -10
  45. data/features/pending/pending_examples.feature +8 -8
  46. data/features/spec_files/arbitrary_file_suffix.feature +1 -1
  47. data/features/step_definitions/additional_cli_steps.rb +11 -1
  48. data/features/subject/attribute_of_subject.feature +24 -4
  49. data/features/subject/explicit_subject.feature +5 -5
  50. data/features/subject/implicit_receiver.feature +2 -2
  51. data/features/subject/implicit_subject.feature +2 -2
  52. data/features/support/env.rb +6 -1
  53. data/lib/rspec/core.rb +22 -0
  54. data/lib/rspec/core/backward_compatibility.rb +12 -2
  55. data/lib/rspec/core/command_line.rb +1 -4
  56. data/lib/rspec/core/configuration.rb +25 -17
  57. data/lib/rspec/core/configuration_options.rb +6 -23
  58. data/lib/rspec/core/drb_command_line.rb +5 -11
  59. data/lib/rspec/core/example.rb +29 -21
  60. data/lib/rspec/core/example_group.rb +36 -4
  61. data/lib/rspec/core/formatters/base_formatter.rb +6 -0
  62. data/lib/rspec/core/formatters/base_text_formatter.rb +1 -1
  63. data/lib/rspec/core/formatters/helpers.rb +0 -4
  64. data/lib/rspec/core/hooks.rb +14 -4
  65. data/lib/rspec/core/metadata.rb +1 -1
  66. data/lib/rspec/core/metadata_hash_builder.rb +93 -0
  67. data/lib/rspec/core/mocking/with_flexmock.rb +2 -0
  68. data/lib/rspec/core/mocking/with_mocha.rb +2 -0
  69. data/lib/rspec/core/mocking/with_rr.rb +2 -0
  70. data/lib/rspec/core/mocking/with_rspec.rb +3 -1
  71. data/lib/rspec/core/option_parser.rb +5 -2
  72. data/lib/rspec/core/pending.rb +10 -3
  73. data/lib/rspec/core/reporter.rb +2 -2
  74. data/lib/rspec/core/runner.rb +7 -1
  75. data/lib/rspec/core/shared_example_group.rb +18 -4
  76. data/lib/rspec/core/subject.rb +4 -6
  77. data/lib/rspec/core/version.rb +1 -1
  78. data/lib/rspec/core/world.rb +16 -4
  79. data/rspec-core.gemspec +4 -3
  80. data/spec.txt +1126 -0
  81. data/spec/autotest/failed_results_re_spec.rb +2 -2
  82. data/spec/rspec/core/command_line_spec.rb +0 -2
  83. data/spec/rspec/core/configuration_spec.rb +84 -1
  84. data/spec/rspec/core/deprecations_spec.rb +21 -0
  85. data/spec/rspec/core/drb_command_line_spec.rb +3 -11
  86. data/spec/rspec/core/example_group_spec.rb +213 -56
  87. data/spec/rspec/core/example_spec.rb +110 -0
  88. data/spec/rspec/core/formatters/base_formatter_spec.rb +23 -2
  89. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +9 -0
  90. data/spec/rspec/core/formatters/helpers_spec.rb +1 -1
  91. data/spec/rspec/core/formatters/html_formatted-1.8.6.html +5 -5
  92. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +8 -10
  93. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +5 -5
  94. data/spec/rspec/core/formatters/html_formatted-1.9.1.html +5 -5
  95. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +5 -5
  96. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -1
  97. data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +5 -5
  98. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +8 -10
  99. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +5 -5
  100. data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +5 -5
  101. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +5 -5
  102. data/spec/rspec/core/hooks_spec.rb +86 -0
  103. data/spec/rspec/core/metadata_spec.rb +7 -7
  104. data/spec/rspec/core/option_parser_spec.rb +8 -0
  105. data/spec/rspec/core/pending_example_spec.rb +12 -51
  106. data/spec/rspec/core/reporter_spec.rb +19 -3
  107. data/spec/rspec/core/resources/formatter_specs.rb +7 -1
  108. data/spec/rspec/core/rspec_matchers_spec.rb +45 -0
  109. data/spec/rspec/core/runner_spec.rb +35 -10
  110. data/spec/rspec/core/shared_example_group_spec.rb +57 -21
  111. data/spec/rspec/core/subject_spec.rb +32 -11
  112. data/spec/rspec/core/world_spec.rb +38 -15
  113. data/spec/rspec/core_spec.rb +28 -0
  114. data/spec/spec_helper.rb +22 -2
  115. data/spec/support/matchers.rb +44 -13
  116. data/spec/support/shared_example_groups.rb +41 -0
  117. metadata +39 -16
@@ -19,7 +19,7 @@ describe "failed_results_re for autotest" do
19
19
  it "matches a failure" do
20
20
  re = Autotest::Rspec2.new.failed_results_re
21
21
  example_output.should =~ re
22
- example_output[re, 2].should == __FILE__.sub(File.expand_path('.'),'.')
22
+ example_output.should include(__FILE__.sub(File.expand_path('.'),'.'))
23
23
  end
24
24
  end
25
25
 
@@ -31,7 +31,7 @@ describe "failed_results_re for autotest" do
31
31
  it "matches a failure" do
32
32
  re = Autotest::Rspec2.new.failed_results_re
33
33
  example_output.should =~ re
34
- example_output[re, 2].should == __FILE__.sub(File.expand_path('.'),'.')
34
+ example_output.should include(__FILE__.sub(File.expand_path('.'),'.'))
35
35
  end
36
36
  end
37
37
  end
@@ -50,8 +50,6 @@ module RSpec::Core
50
50
  config.stub(:run_hook)
51
51
 
52
52
  config.should_receive(:load_spec_files)
53
- config.should_receive(:configure_mock_framework)
54
- config.should_receive(:configure_expectation_framework)
55
53
 
56
54
  world.should_receive(:announce_inclusion_filter)
57
55
  world.should_receive(:announce_exclusion_filter)
@@ -5,7 +5,7 @@ module RSpec::Core
5
5
 
6
6
  describe Configuration do
7
7
 
8
- let(:config) { subject }
8
+ let(:config) { Configuration.new }
9
9
 
10
10
  describe "#load_spec_files" do
11
11
 
@@ -30,6 +30,17 @@ module RSpec::Core
30
30
  end
31
31
  end
32
32
 
33
+ describe "#treat_symbols_as_metadata_keys_with_true_values?" do
34
+ it 'defaults to false' do
35
+ config.treat_symbols_as_metadata_keys_with_true_values?.should be_false
36
+ end
37
+
38
+ it 'can be set to true' do
39
+ config.treat_symbols_as_metadata_keys_with_true_values = true
40
+ config.treat_symbols_as_metadata_keys_with_true_values?.should be_true
41
+ end
42
+ end
43
+
33
44
  describe "#mock_framework" do
34
45
  it "defaults to :rspec" do
35
46
  config.should_receive(:require).with('rspec/core/mocking/with_rspec')
@@ -100,6 +111,38 @@ module RSpec::Core
100
111
  end
101
112
  end
102
113
 
114
+ describe "#expecting_with_rspec?" do
115
+ before(:each) do
116
+ # prevent minitest assertions from being required and included,
117
+ # as that causes problems in some of our specs.
118
+ config.stub(:require)
119
+ end
120
+
121
+ it "returns false by default" do
122
+ config.should_not be_expecting_with_rspec
123
+ end
124
+
125
+ it "returns true when `expect_with :rspec` has been configured" do
126
+ config.expect_with :rspec
127
+ config.should be_expecting_with_rspec
128
+ end
129
+
130
+ it "returns true when `expect_with :rspec, :stdlib` has been configured" do
131
+ config.expect_with :rspec, :stdlib
132
+ config.should be_expecting_with_rspec
133
+ end
134
+
135
+ it "returns true when `expect_with :stdlib, :rspec` has been configured" do
136
+ config.expect_with :stdlib, :rspec
137
+ config.should be_expecting_with_rspec
138
+ end
139
+
140
+ it "returns false when `expect_with :stdlib` has been configured" do
141
+ config.expect_with :stdlib
142
+ config.should_not be_expecting_with_rspec
143
+ end
144
+ end
145
+
103
146
  context "setting the files to run" do
104
147
 
105
148
  it "loads files not following pattern if named explicitly" do
@@ -205,6 +248,13 @@ module RSpec::Core
205
248
  end
206
249
  end
207
250
 
251
+ it_behaves_like "metadata hash builder" do
252
+ def metadata_hash(*args)
253
+ config.include(InstanceLevelMethods, *args)
254
+ config.include_or_extend_modules.last.last
255
+ end
256
+ end
257
+
208
258
  context "with no filter" do
209
259
  it "includes the given module into each example group" do
210
260
  RSpec.configure do |c|
@@ -238,6 +288,13 @@ module RSpec::Core
238
288
  end
239
289
  end
240
290
 
291
+ it_behaves_like "metadata hash builder" do
292
+ def metadata_hash(*args)
293
+ config.extend(ThatThingISentYou, *args)
294
+ config.include_or_extend_modules.last.last
295
+ end
296
+ end
297
+
241
298
  it "extends the given module into each matching example group" do
242
299
  RSpec.configure do |c|
243
300
  c.extend(ThatThingISentYou, :magic_key => :extend)
@@ -421,6 +478,13 @@ module RSpec::Core
421
478
  end
422
479
 
423
480
  describe "#filter_run" do
481
+ it_behaves_like "metadata hash builder" do
482
+ def metadata_hash(*args)
483
+ config.filter_run *args
484
+ config.filter
485
+ end
486
+ end
487
+
424
488
  it "sets the filter" do
425
489
  config.filter_run :focus => true
426
490
  config.filter[:focus].should == true
@@ -454,6 +518,13 @@ module RSpec::Core
454
518
  end
455
519
 
456
520
  describe "#filter_run_excluding" do
521
+ it_behaves_like "metadata hash builder" do
522
+ def metadata_hash(*args)
523
+ config.filter_run_excluding *args
524
+ config.exclusion_filter
525
+ end
526
+ end
527
+
457
528
  it "sets the filter" do
458
529
  config.filter_run_excluding :slow => true
459
530
  config.exclusion_filter[:slow].should == true
@@ -712,5 +783,17 @@ module RSpec::Core
712
783
  group.included_modules.should include(mod2)
713
784
  end
714
785
  end
786
+
787
+ describe "#alias_example_to" do
788
+ it_behaves_like "metadata hash builder" do
789
+ def metadata_hash(*args)
790
+ config.alias_example_to :my_example, *args
791
+ group = ExampleGroup.describe("group")
792
+ example = group.my_example("description")
793
+ example.metadata
794
+ end
795
+ end
796
+ end
797
+
715
798
  end
716
799
  end
@@ -11,6 +11,16 @@ describe "deprecations" do
11
11
  RSpec.stub(:warn_deprecation)
12
12
  Spec.should == RSpec
13
13
  end
14
+
15
+ it "doesn't include backward compatibility in const_missing backtrace" do
16
+ RSpec.stub(:warn_deprecation)
17
+ exception = nil
18
+ begin
19
+ ConstantThatDoesNotExist
20
+ rescue Exception => exception
21
+ end
22
+ exception.backtrace.find { |l| l =~ /lib\/rspec\/core\/backward_compatibility/ }.should be_nil
23
+ end
14
24
  end
15
25
 
16
26
  describe RSpec::Core::ExampleGroup do
@@ -41,5 +51,16 @@ describe "deprecations" do
41
51
  RSpec.should_receive(:deprecate)
42
52
  Spec::Rake::SpecTask
43
53
  end
54
+
55
+ it "doesn't include backward compatibility in const_missing backtrace" do
56
+ RSpec.stub(:warn_deprecation)
57
+ exception = nil
58
+ begin
59
+ Spec::Rake::ConstantThatDoesNotExist
60
+ rescue Exception => exception
61
+ end
62
+ exception.backtrace.find { |l| l =~ /lib\/rspec\/core\/backward_compatibility/ }.should be_nil
63
+ end
44
64
  end
65
+
45
66
  end
@@ -20,16 +20,8 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
20
20
  end
21
21
 
22
22
  context "without server running" do
23
- it "prints error" do
24
- run_with []
25
-
26
- err.rewind
27
- err.read.should =~ /No DRb server is running/
28
- end
29
-
30
- it "returns false" do
31
- result = run_with []
32
- result.should be_false
23
+ it "raises an error" do
24
+ lambda { run_with [] }.should raise_error(DRb::DRbConnError)
33
25
  end
34
26
  end
35
27
 
@@ -136,7 +128,7 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
136
128
  it "integrates via Runner.new.run" do
137
129
  err, out = StringIO.new, StringIO.new
138
130
  result = RSpec::Core::Runner.run(%W[ --drb --drb-port #{@drb_port} #{dummy_spec_filename}], err, out)
139
- result.should be_true
131
+ result.should be_false
140
132
  end
141
133
 
142
134
  def run_spec_via_druby
@@ -13,6 +13,44 @@ end
13
13
  module RSpec::Core
14
14
 
15
15
  describe ExampleGroup do
16
+ it_behaves_like "metadata hash builder" do
17
+ def metadata_hash(*args)
18
+ group = ExampleGroup.describe('example description', *args)
19
+ group.metadata
20
+ end
21
+ end
22
+
23
+ context 'when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to false' do
24
+ before(:each) do
25
+ RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = false }
26
+ Kernel.stub(:warn)
27
+ end
28
+
29
+ it 'processes string args as part of the description' do
30
+ group = ExampleGroup.describe("some", "separate", "strings")
31
+ group.description.should == "some separate strings"
32
+ end
33
+
34
+ it 'processes symbol args as part of the description' do
35
+ group = ExampleGroup.describe(:some, :separate, :symbols)
36
+ group.description.should == "some separate symbols"
37
+ end
38
+ end
39
+
40
+ context 'when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to true' do
41
+ let(:group) { ExampleGroup.describe(:symbol) }
42
+ before(:each) do
43
+ RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = true }
44
+ end
45
+
46
+ it 'does not treat the first argument as a metadata key even if it is a symbol' do
47
+ group.metadata.should_not include(:symbol)
48
+ end
49
+
50
+ it 'treats the first argument as part of the description when it is a symbol' do
51
+ group.description.should == "symbol"
52
+ end
53
+ end
16
54
 
17
55
  describe "top level group" do
18
56
  it "runs its children" do
@@ -81,49 +119,119 @@ module RSpec::Core
81
119
  describe "filtering" do
82
120
  let(:world) { World.new }
83
121
 
84
- it "includes all examples in an explicitly included group" do
85
- world.stub(:inclusion_filter).and_return({ :awesome => true })
86
- group = ExampleGroup.describe("does something", :awesome => true)
87
- group.stub(:world) { world }
122
+ shared_examples "matching filters" do
123
+ context "inclusion" do
124
+ before { world.stub(:inclusion_filter).and_return(filter_metadata) }
88
125
 
89
- examples = [
90
- group.example("first"),
91
- group.example("second")
92
- ]
93
- group.filtered_examples.should == examples
126
+ it "includes examples in groups matching filter" do
127
+ group = ExampleGroup.describe("does something", spec_metadata)
128
+ group.stub(:world) { world }
129
+ all_examples = [ group.example("first"), group.example("second") ]
130
+
131
+ group.filtered_examples.should == all_examples
132
+ end
133
+
134
+ it "includes examples directly matching filter" do
135
+ group = ExampleGroup.describe("does something")
136
+ group.stub(:world) { world }
137
+ filtered_examples = [
138
+ group.example("first", spec_metadata),
139
+ group.example("second", spec_metadata)
140
+ ]
141
+ group.example("third (not-filtered)")
142
+
143
+ group.filtered_examples.should == filtered_examples
144
+ end
145
+ end
146
+
147
+ context "exclusion" do
148
+ before { world.stub(:exclusion_filter).and_return(filter_metadata) }
149
+ it "excludes examples in groups matching filter" do
150
+ group = ExampleGroup.describe("does something", spec_metadata)
151
+ group.stub(:world) { world }
152
+ all_examples = [ group.example("first"), group.example("second") ]
153
+
154
+ group.filtered_examples.should be_empty
155
+ end
156
+
157
+ it "excludes examples directly matching filter" do
158
+ group = ExampleGroup.describe("does something")
159
+ group.stub(:world) { world }
160
+ filtered_examples = [
161
+ group.example("first", spec_metadata),
162
+ group.example("second", spec_metadata)
163
+ ]
164
+ unfiltered_example = group.example("third (not-filtered)")
165
+
166
+ group.filtered_examples.should == [unfiltered_example]
167
+ end
168
+ end
94
169
  end
95
170
 
96
- it "includes explicitly included examples" do
97
- world.stub(:inclusion_filter).and_return({ :include_me => true })
98
- group = ExampleGroup.describe
99
- group.stub(:world) { world }
100
- example = group.example("does something", :include_me => true)
101
- group.example("don't run me")
102
- group.filtered_examples.should == [example]
171
+ context "matching false" do
172
+ let(:spec_metadata) { { :awesome => false }}
173
+
174
+ context "against false" do
175
+ let(:filter_metadata) { { :awesome => false }}
176
+ include_examples "matching filters"
177
+ end
178
+
179
+ context "against 'false'" do
180
+ let(:filter_metadata) { { :awesome => 'false' }}
181
+ include_examples "matching filters"
182
+ end
183
+
184
+ context "against :false" do
185
+ let(:filter_metadata) { { :awesome => :false }}
186
+ include_examples "matching filters"
187
+ end
103
188
  end
104
189
 
105
- it "excludes all examples in an excluded group" do
106
- world.stub(:exclusion_filter).and_return({ :include_me => false })
107
- group = ExampleGroup.describe("does something", :include_me => false)
108
- group.stub(:world) { world }
190
+ context "matching true" do
191
+ let(:spec_metadata) { { :awesome => true }}
109
192
 
110
- examples = [
111
- group.example("first"),
112
- group.example("second")
113
- ]
114
- group.filtered_examples.should == []
193
+ context "against true" do
194
+ let(:filter_metadata) { { :awesome => true }}
195
+ include_examples "matching filters"
196
+ end
197
+
198
+ context "against 'true'" do
199
+ let(:filter_metadata) { { :awesome => 'true' }}
200
+ include_examples "matching filters"
201
+ end
202
+
203
+ context "against :true" do
204
+ let(:filter_metadata) { { :awesome => :true }}
205
+ include_examples "matching filters"
206
+ end
115
207
  end
116
208
 
117
- it "filters out excluded examples" do
118
- world.stub(:exclusion_filter).and_return({ :exclude_me => true })
119
- group = ExampleGroup.describe("does something")
120
- group.stub(:world) { world }
209
+ context "matching a string" do
210
+ let(:spec_metadata) { { :type => 'special' }}
121
211
 
122
- examples = [
123
- group.example("first", :exclude_me => true),
124
- group.example("second")
125
- ]
126
- group.filtered_examples.should == [examples[1]]
212
+ context "against a string" do
213
+ let(:filter_metadata) { { :type => 'special' }}
214
+ include_examples "matching filters"
215
+ end
216
+
217
+ context "against a symbol" do
218
+ let(:filter_metadata) { { :type => :special }}
219
+ include_examples "matching filters"
220
+ end
221
+ end
222
+
223
+ context "matching a symbol" do
224
+ let(:spec_metadata) { { :type => :special }}
225
+
226
+ context "against a string" do
227
+ let(:filter_metadata) { { :type => 'special' }}
228
+ include_examples "matching filters"
229
+ end
230
+
231
+ context "against a symbol" do
232
+ let(:filter_metadata) { { :type => :special }}
233
+ include_examples "matching filters"
234
+ end
127
235
  end
128
236
 
129
237
  context "with no filters" do
@@ -189,8 +297,6 @@ module RSpec::Core
189
297
  group.run.should be_true, "expected examples in group to pass"
190
298
  end
191
299
  end
192
-
193
-
194
300
  end
195
301
 
196
302
  describe '#described_class' do
@@ -200,16 +306,13 @@ module RSpec::Core
200
306
  end
201
307
 
202
308
  describe '#description' do
203
-
204
309
  it "grabs the description from the metadata" do
205
310
  group = ExampleGroup.describe(Object, "my desc") { }
206
311
  group.description.should == group.metadata[:example_group][:description]
207
312
  end
208
-
209
313
  end
210
314
 
211
315
  describe '#metadata' do
212
-
213
316
  it "adds the third parameter to the metadata" do
214
317
  ExampleGroup.describe(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' })
215
318
  end
@@ -225,7 +328,6 @@ module RSpec::Core
225
328
  it "adds the line_number to metadata" do
226
329
  ExampleGroup.describe(Object) { }.metadata[:example_group][:line_number].should == __LINE__
227
330
  end
228
-
229
331
  end
230
332
 
231
333
  [:focus, :focused].each do |example_alias|
@@ -244,7 +346,6 @@ module RSpec::Core
244
346
  end
245
347
 
246
348
  describe "#before, after, and around hooks" do
247
-
248
349
  it "runs the before alls in order" do
249
350
  group = ExampleGroup.describe
250
351
  order = []
@@ -255,7 +356,7 @@ module RSpec::Core
255
356
 
256
357
  group.run
257
358
 
258
- order.should == [1,2,3]
359
+ order.should eq([1,2,3])
259
360
  end
260
361
 
261
362
  it "runs the before eachs in order" do
@@ -268,7 +369,7 @@ module RSpec::Core
268
369
 
269
370
  group.run
270
371
 
271
- order.should == [1,2,3]
372
+ order.should eq([1,2,3])
272
373
  end
273
374
 
274
375
  it "runs the after eachs in reverse order" do
@@ -281,7 +382,7 @@ module RSpec::Core
281
382
 
282
383
  group.run
283
384
 
284
- order.should == [3,2,1]
385
+ order.should eq([3,2,1])
285
386
  end
286
387
 
287
388
  it "runs the after alls in reverse order" do
@@ -294,7 +395,7 @@ module RSpec::Core
294
395
 
295
396
  group.run
296
397
 
297
- order.should == [3,2,1]
398
+ order.should eq([3,2,1])
298
399
  end
299
400
 
300
401
  it "only runs before/after(:all) hooks from example groups that have specs that run" do
@@ -325,7 +426,7 @@ module RSpec::Core
325
426
  unfiltered_group.run
326
427
  filtered_group.run
327
428
 
328
- hooks_run.should == [:filtered_before_all, :filtered_after_all]
429
+ hooks_run.should eq([:filtered_before_all, :filtered_after_all])
329
430
  end
330
431
 
331
432
  it "runs before_all_defined_in_config, before all, before each, example, after each, after all, after_all_defined_in_config in that order" do
@@ -372,22 +473,44 @@ module RSpec::Core
372
473
  ]
373
474
  end
374
475
 
375
- it "accesses before(:all) state in after(:all)" do
376
- group = ExampleGroup.describe
377
- group.before(:all) { @ivar = "value" }
378
- group.after(:all) { @ivar.should eq("value") }
379
- group.example("ignore") { }
476
+ context "after(:all)" do
477
+ let(:outer) { ExampleGroup.describe }
478
+ let(:inner) { outer.describe }
380
479
 
381
- expect do
382
- group.run
383
- end.to_not raise_error
480
+ it "has access to state defined before(:all)" do
481
+ outer.before(:all) { @outer = "outer" }
482
+ inner.before(:all) { @inner = "inner" }
483
+
484
+ outer.after(:all) do
485
+ @outer.should eq("outer")
486
+ @inner.should eq("inner")
487
+ end
488
+ inner.after(:all) do
489
+ @inner.should eq("inner")
490
+ @outer.should eq("outer")
491
+ end
492
+
493
+ outer.run
494
+ end
495
+
496
+ it "cleans up ivars in after(:all)" do
497
+ outer.before(:all) { @outer = "outer" }
498
+ inner.before(:all) { @inner = "inner" }
499
+
500
+ outer.run
501
+
502
+ inner.before_all_ivars[:@inner].should be_nil
503
+ inner.before_all_ivars[:@outer].should be_nil
504
+ outer.before_all_ivars[:@inner].should be_nil
505
+ outer.before_all_ivars[:@outer].should be_nil
506
+ end
384
507
  end
385
508
 
386
509
  it "treats an error in before(:each) as a failure" do
387
510
  group = ExampleGroup.describe
388
511
  group.before(:each) { raise "error in before each" }
389
512
  example = group.example("equality") { 1.should == 2}
390
- group.run
513
+ group.run.should == false
391
514
 
392
515
  example.metadata[:execution_result][:exception].message.should == "error in before each"
393
516
  end
@@ -396,7 +519,7 @@ module RSpec::Core
396
519
  group = ExampleGroup.describe
397
520
  group.before(:all) { raise "error in before all" }
398
521
  example = group.example("equality") { 1.should == 2}
399
- group.run
522
+ group.run.should == false
400
523
 
401
524
  example.metadata.should_not be_nil
402
525
  example.metadata[:execution_result].should_not be_nil
@@ -749,5 +872,39 @@ module RSpec::Core
749
872
  end
750
873
  end
751
874
 
875
+ describe "#include_context" do
876
+ before do
877
+ shared_context "named this" do
878
+ def foo; 'foo'; end
879
+ end
880
+ end
881
+
882
+ it "includes the named context" do
883
+ group = ExampleGroup.describe do
884
+ include_context "named this"
885
+ it "accesses foo" do
886
+ foo.should eq('foo')
887
+ end
888
+ end
889
+ group.run.should be_true
890
+ end
891
+ end
892
+
893
+ describe "#include_examples" do
894
+ before do
895
+ shared_examples "named this" do
896
+ example("does something") do
897
+ end
898
+ end
899
+ end
900
+
901
+ it "includes the named examples" do
902
+ group = ExampleGroup.describe do
903
+ include_examples "named this"
904
+ end
905
+ group.examples.first.description.should eq("does something")
906
+ end
907
+ end
908
+
752
909
  end
753
910
  end