rspec-core 2.5.1 → 2.6.0
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.
- data/.travis.yml +7 -0
- data/Gemfile +12 -14
- data/README.md +4 -1
- data/Rakefile +29 -12
- data/cucumber.yml +1 -1
- data/features/.nav +15 -9
- data/features/Autotest.md +31 -7
- data/features/Changelog.md +46 -3
- data/features/Upgrade.md +35 -2
- data/features/command_line/README.md +22 -0
- data/features/command_line/configure.feature +2 -2
- data/features/command_line/example_name_option.feature +10 -10
- data/features/command_line/exit_status.feature +4 -4
- data/features/command_line/format_option.feature +4 -4
- data/features/command_line/line_number_appended_to_path.feature +11 -11
- data/features/command_line/line_number_option.feature +2 -2
- data/features/command_line/rake_task.feature +3 -3
- data/features/command_line/tag.feature +30 -14
- data/features/configuration/alias_example_to.feature +48 -0
- data/features/configuration/custom_settings.feature +3 -3
- data/features/configuration/fail_fast.feature +3 -3
- data/features/configuration/read_options_from_file.feature +4 -4
- data/features/example_groups/basic_structure.feature +11 -15
- data/features/example_groups/shared_context.feature +74 -0
- data/features/example_groups/shared_example_group.feature +21 -17
- data/features/expectation_framework_integration/configure_expectation_framework.feature +15 -4
- data/features/filtering/exclusion_filters.feature +28 -4
- data/features/filtering/{implicit_filters.feature → if_and_unless.feature} +9 -7
- data/features/filtering/inclusion_filters.feature +26 -3
- data/features/filtering/run_all_when_everything_filtered.feature +2 -2
- data/features/formatters/custom_formatter.feature +1 -1
- data/features/formatters/text_formatter.feature +43 -0
- data/features/helper_methods/arbitrary_methods.feature +2 -2
- data/features/helper_methods/let.feature +2 -2
- data/features/helper_methods/modules.feature +149 -0
- data/features/hooks/around_hooks.feature +18 -11
- data/features/hooks/before_and_after_hooks.feature +15 -19
- data/features/hooks/filtering.feature +160 -124
- data/features/metadata/current_example.feature +17 -0
- data/features/metadata/described_class.feature +2 -2
- data/features/metadata/user_defined.feature +111 -0
- data/features/mock_framework_integration/use_any_framework.feature +1 -1
- data/features/mock_framework_integration/use_flexmock.feature +83 -10
- data/features/mock_framework_integration/use_mocha.feature +84 -10
- data/features/mock_framework_integration/use_rr.feature +85 -10
- data/features/mock_framework_integration/use_rspec.feature +84 -10
- data/features/pending/pending_examples.feature +8 -8
- data/features/spec_files/arbitrary_file_suffix.feature +1 -1
- data/features/step_definitions/additional_cli_steps.rb +11 -1
- data/features/subject/attribute_of_subject.feature +24 -4
- data/features/subject/explicit_subject.feature +5 -5
- data/features/subject/implicit_receiver.feature +2 -2
- data/features/subject/implicit_subject.feature +2 -2
- data/features/support/env.rb +6 -1
- data/lib/rspec/core/backward_compatibility.rb +12 -2
- data/lib/rspec/core/command_line.rb +2 -5
- data/lib/rspec/core/configuration.rb +70 -38
- data/lib/rspec/core/configuration_options.rb +6 -23
- data/lib/rspec/core/drb_command_line.rb +5 -11
- data/lib/rspec/core/example.rb +29 -21
- data/lib/rspec/core/example_group.rb +40 -8
- data/lib/rspec/core/extensions/object.rb +0 -1
- data/lib/rspec/core/formatters/base_formatter.rb +6 -0
- data/lib/rspec/core/formatters/base_text_formatter.rb +1 -1
- data/lib/rspec/core/formatters/helpers.rb +0 -4
- data/lib/rspec/core/hooks.rb +14 -4
- data/lib/rspec/core/metadata.rb +1 -1
- data/lib/rspec/core/metadata_hash_builder.rb +93 -0
- data/lib/rspec/core/mocking/with_flexmock.rb +2 -0
- data/lib/rspec/core/mocking/with_mocha.rb +2 -0
- data/lib/rspec/core/mocking/with_rr.rb +2 -0
- data/lib/rspec/core/mocking/with_rspec.rb +3 -1
- data/lib/rspec/core/option_parser.rb +9 -2
- data/lib/rspec/core/pending.rb +10 -3
- data/lib/rspec/core/reporter.rb +2 -2
- data/lib/rspec/core/runner.rb +38 -13
- data/lib/rspec/core/shared_example_group.rb +18 -4
- data/lib/rspec/core/subject.rb +4 -6
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/world.rb +70 -18
- data/lib/rspec/core.rb +29 -0
- data/lib/rspec/monkey/spork/test_framework/rspec.rb +1 -0
- data/rspec-core.gemspec +3 -5
- data/spec/autotest/failed_results_re_spec.rb +2 -2
- data/spec/rspec/core/command_line_spec.rb +36 -2
- data/spec/rspec/core/configuration_spec.rb +150 -70
- data/spec/rspec/core/deprecations_spec.rb +21 -0
- data/spec/rspec/core/drb_command_line_spec.rb +21 -56
- data/spec/rspec/core/example_group_spec.rb +213 -56
- data/spec/rspec/core/example_spec.rb +110 -0
- data/spec/rspec/core/formatters/base_formatter_spec.rb +23 -2
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +9 -0
- data/spec/rspec/core/formatters/helpers_spec.rb +1 -1
- data/spec/rspec/core/formatters/html_formatted-1.8.6.html +5 -5
- data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +8 -10
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +5 -5
- data/spec/rspec/core/formatters/html_formatted-1.9.1.html +5 -5
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +5 -5
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -1
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +5 -5
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +8 -10
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +5 -5
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +5 -5
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +5 -5
- data/spec/rspec/core/hooks_spec.rb +86 -0
- data/spec/rspec/core/metadata_spec.rb +7 -7
- data/spec/rspec/core/option_parser_spec.rb +26 -15
- data/spec/rspec/core/pending_example_spec.rb +12 -51
- data/spec/rspec/core/reporter_spec.rb +19 -3
- data/spec/rspec/core/resources/formatter_specs.rb +7 -1
- data/spec/rspec/core/rspec_matchers_spec.rb +45 -0
- data/spec/rspec/core/runner_spec.rb +42 -10
- data/spec/rspec/core/shared_example_group_spec.rb +57 -21
- data/spec/rspec/core/subject_spec.rb +32 -11
- data/spec/rspec/core/world_spec.rb +147 -15
- data/spec/rspec/core_spec.rb +28 -0
- data/spec/spec_helper.rb +22 -2
- data/spec/support/matchers.rb +44 -13
- data/spec/support/shared_example_groups.rb +41 -0
- data/spec/support/spec_files.rb +44 -0
- data/spec.txt +1126 -0
- metadata +35 -16
- data/spec/ruby_forker.rb +0 -13
|
@@ -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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
106
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
118
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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
|
-
|
|
382
|
-
|
|
383
|
-
|
|
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
|
|
@@ -9,6 +9,66 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
|
9
9
|
example_group.example('example description')
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
it_behaves_like "metadata hash builder" do
|
|
13
|
+
def metadata_hash(*args)
|
|
14
|
+
example = example_group.example('example description', *args)
|
|
15
|
+
example.metadata
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe "auto-generated example descriptions" do
|
|
20
|
+
let(:generated_description) { "the generated description" }
|
|
21
|
+
let(:rspec_example) { example_group.specify { 5.should == 5 } }
|
|
22
|
+
before(:each) { RSpec::Matchers.stub(:generated_description => generated_description) }
|
|
23
|
+
|
|
24
|
+
def expect_with(*frameworks)
|
|
25
|
+
RSpec.configuration.stub(:expecting_with_rspec?).and_return(frameworks.include?(:rspec))
|
|
26
|
+
|
|
27
|
+
if frameworks.include?(:stdlib)
|
|
28
|
+
example_group.class_eval do
|
|
29
|
+
def assert(val)
|
|
30
|
+
raise "Expected #{val} to be true" unless val
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "when `expect_with :rspec` is configured" do
|
|
37
|
+
before(:each) { expect_with :rspec }
|
|
38
|
+
|
|
39
|
+
it "generates a description for an example with no description" do
|
|
40
|
+
expect {
|
|
41
|
+
example_group.run
|
|
42
|
+
}.to change { rspec_example.metadata[:description] }.from("").to(generated_description)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context "when `expect_with :rspec, :stdlib` is configured" do
|
|
47
|
+
before(:each) { expect_with :rspec, :stdlib }
|
|
48
|
+
|
|
49
|
+
it "generates a description for an example with no description" do
|
|
50
|
+
expect {
|
|
51
|
+
example_group.run
|
|
52
|
+
}.to change { rspec_example.metadata[:description] }.from("").to(generated_description)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
context "when `expect_with :stdlib` is configured" do
|
|
57
|
+
let!(:stdlib_example) { example_group.specify { assert 5 == 5 } }
|
|
58
|
+
before(:each) { expect_with :stdlib }
|
|
59
|
+
|
|
60
|
+
it "does not attempt to get the generated description from RSpec::Matchers" do
|
|
61
|
+
RSpec::Matchers.should_not_receive(:generated_description)
|
|
62
|
+
example_group.run
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "fails an example with no description" do
|
|
66
|
+
example_group.run
|
|
67
|
+
stdlib_example.should have_failed_with(NotImplementedError)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
12
72
|
describe '#described_class' do
|
|
13
73
|
it "returns the class (if any) of the outermost example group" do
|
|
14
74
|
described_class.should == RSpec::Core::Example
|
|
@@ -33,6 +93,14 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
|
33
93
|
end
|
|
34
94
|
|
|
35
95
|
describe "#run" do
|
|
96
|
+
it "sets its reference to the example group instance to nil" do
|
|
97
|
+
group = RSpec::Core::ExampleGroup.describe do
|
|
98
|
+
example('example') { 1.should eq(1) }
|
|
99
|
+
end
|
|
100
|
+
group.run
|
|
101
|
+
group.examples.first.instance_variable_get("@example_group_instance").should be_nil
|
|
102
|
+
end
|
|
103
|
+
|
|
36
104
|
it "runs after(:each) when the example passes" do
|
|
37
105
|
after_run = false
|
|
38
106
|
group = RSpec::Core::ExampleGroup.describe do
|
|
@@ -108,6 +176,35 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
|
108
176
|
"around (after)"
|
|
109
177
|
])
|
|
110
178
|
end
|
|
179
|
+
|
|
180
|
+
context "clearing ivars" do
|
|
181
|
+
it "sets ivars to nil to prep them for GC" do
|
|
182
|
+
group = RSpec::Core::ExampleGroup.describe do
|
|
183
|
+
before(:all) { @before_all = :before_all }
|
|
184
|
+
before(:each) { @before_each = :before_each }
|
|
185
|
+
after(:each) { @after_each = :after_each }
|
|
186
|
+
after(:all) { @after_all = :after_all }
|
|
187
|
+
end
|
|
188
|
+
example = group.example("does something") do
|
|
189
|
+
@in_example = :in_example
|
|
190
|
+
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
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
it "does not impact the before_all_ivars which are copied to each example" do
|
|
200
|
+
group = RSpec::Core::ExampleGroup.describe do
|
|
201
|
+
before(:all) { @before_all = "abc" }
|
|
202
|
+
example("first") { @before_all.should_not be_nil }
|
|
203
|
+
example("second") { @before_all.should_not be_nil }
|
|
204
|
+
end
|
|
205
|
+
group.run.should be_true
|
|
206
|
+
end
|
|
207
|
+
end
|
|
111
208
|
end
|
|
112
209
|
|
|
113
210
|
describe "#pending" do
|
|
@@ -119,6 +216,19 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
|
119
216
|
group.run
|
|
120
217
|
group.examples.first.should be_pending
|
|
121
218
|
end
|
|
219
|
+
|
|
220
|
+
it "allows post-example processing in around hooks (see https://github.com/rspec/rspec-core/issues/322)" do
|
|
221
|
+
blah = nil
|
|
222
|
+
group = RSpec::Core::ExampleGroup.describe do
|
|
223
|
+
around do |example|
|
|
224
|
+
example.run
|
|
225
|
+
blah = :success
|
|
226
|
+
end
|
|
227
|
+
example { pending }
|
|
228
|
+
end
|
|
229
|
+
group.run
|
|
230
|
+
blah.should be(:success)
|
|
231
|
+
end
|
|
122
232
|
end
|
|
123
233
|
|
|
124
234
|
context "in before(:each)" do
|
|
@@ -34,18 +34,19 @@ describe RSpec::Core::Formatters::BaseFormatter do
|
|
|
34
34
|
|
|
35
35
|
context "when String alias to_int to_i" do
|
|
36
36
|
before do
|
|
37
|
-
|
|
37
|
+
String.class_eval do
|
|
38
38
|
alias :to_int :to_i
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
after do
|
|
43
|
-
|
|
43
|
+
String.class_eval do
|
|
44
44
|
undef to_int
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it "doesn't hang when file exists" do
|
|
49
|
+
pending("This issue still exists on JRuby, but should be resolved shortly: https://github.com/rspec/rspec-core/issues/295", :if => RUBY_PLATFORM == 'java')
|
|
49
50
|
exception = mock(:Exception, :backtrace => [ "#{__FILE__}:#{__LINE__}"])
|
|
50
51
|
|
|
51
52
|
example = mock(:Example, :file_path => __FILE__)
|
|
@@ -56,4 +57,24 @@ describe RSpec::Core::Formatters::BaseFormatter do
|
|
|
56
57
|
end
|
|
57
58
|
end
|
|
58
59
|
|
|
60
|
+
describe "#format_backtrace" do
|
|
61
|
+
let(:rspec_expectations_dir) { "/path/to/rspec-expectations/lib" }
|
|
62
|
+
let(:rspec_core_dir) { "/path/to/rspec-core/lib" }
|
|
63
|
+
let(:backtrace) do
|
|
64
|
+
[
|
|
65
|
+
"#{rspec_expectations_dir}/rspec/matchers/operator_matcher.rb:51:in `eval_match'",
|
|
66
|
+
"#{rspec_expectations_dir}/rspec/matchers/operator_matcher.rb:29:in `=='",
|
|
67
|
+
"./my_spec.rb:5",
|
|
68
|
+
"#{rspec_core_dir}/rspec/core/example.rb:52:in `run'",
|
|
69
|
+
"#{rspec_core_dir}/rspec/core/runner.rb:37:in `run'",
|
|
70
|
+
RSpec::Core::Runner::AT_EXIT_HOOK_BACKTRACE_LINE,
|
|
71
|
+
"./my_spec.rb:3"
|
|
72
|
+
]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "removes lines from rspec and lines that come before the invocation of the at_exit autorun hook" do
|
|
76
|
+
formatter.format_backtrace(backtrace, stub.as_null_object).should == ["./my_spec.rb:5"]
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
59
80
|
end
|
|
@@ -46,6 +46,15 @@ module RSpec::Core::Formatters
|
|
|
46
46
|
output.string.should =~ /(\s+)expected \"that\"\n\1 got \"this\"/m
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
context "with an exception without a message" do
|
|
50
|
+
it "does not throw NoMethodError" do
|
|
51
|
+
exception_without_message = Exception.new()
|
|
52
|
+
exception_without_message.stub(:message) { nil }
|
|
53
|
+
group.example("example name") { raise exception_without_message }
|
|
54
|
+
expect { run_all_and_dump_failures }.not_to raise_error(NoMethodError)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
49
58
|
context "with an exception class other than RSpec" do
|
|
50
59
|
it "does not show the error class" do
|
|
51
60
|
group.example("example name") { raise NameError.new('foo') }
|
|
@@ -319,11 +319,11 @@ a {
|
|
|
319
319
|
./spec/rspec/core/formatters/html_formatter_spec.rb:46
|
|
320
320
|
./spec/rspec/core/formatters/html_formatter_spec.rb:45:in `chdir'
|
|
321
321
|
./spec/rspec/core/formatters/html_formatter_spec.rb:45</pre></div>
|
|
322
|
-
<pre class="ruby"><code><span class="linenum">
|
|
323
|
-
<span class="linenum">
|
|
324
|
-
<span class="offending"><span class="linenum">
|
|
325
|
-
<span class="linenum">
|
|
326
|
-
<span class="linenum">
|
|
322
|
+
<pre class="ruby"><code><span class="linenum">29</span> <span class="ident">teardown_mocks_for_rspec</span>
|
|
323
|
+
<span class="linenum">30</span> <span class="keyword">end</span>
|
|
324
|
+
<span class="offending"><span class="linenum">31</span> <span class="keyword">raise</span> <span class="constant">RSpec</span><span class="punct">::</span><span class="constant">Core</span><span class="punct">::</span><span class="constant">PendingExampleFixedError</span><span class="punct">.</span><span class="ident">new</span> <span class="keyword">if</span> <span class="ident">result</span></span>
|
|
325
|
+
<span class="linenum">32</span> <span class="keyword">end</span>
|
|
326
|
+
<span class="linenum">33</span> <span class="keyword">raise</span> <span class="constant">PendingDeclaredInExample</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">message</span><span class="punct">)</span></code></pre>
|
|
327
327
|
</div>
|
|
328
328
|
</dd>
|
|
329
329
|
</dl>
|
|
@@ -318,13 +318,12 @@ a {
|
|
|
318
318
|
./spec/rspec/core/formatters/html_formatter_spec.rb:46:in `open'
|
|
319
319
|
./spec/rspec/core/formatters/html_formatter_spec.rb:46
|
|
320
320
|
./spec/rspec/core/formatters/html_formatter_spec.rb:45:in `chdir'
|
|
321
|
-
./spec/rspec/core/formatters/html_formatter_spec.rb:45
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
<span class="linenum">
|
|
325
|
-
<span class="
|
|
326
|
-
<span class="linenum">
|
|
327
|
-
<span class="linenum">26</span> <span class="ident">throw</span> <span class="symbol">:pending_declared_in_example</span><span class="punct">,</span> <span class="ident">message</span></code></pre>
|
|
321
|
+
./spec/rspec/core/formatters/html_formatter_spec.rb:45</pre></div>
|
|
322
|
+
<pre class="ruby"><code><span class="linenum">24</span> <span class="keyword">rescue</span> <span class="constant">Exception</span>
|
|
323
|
+
<span class="linenum">25</span> <span class="keyword">end</span>
|
|
324
|
+
<span class="offending"><span class="linenum">26</span> <span class="keyword">raise</span> <span class="constant">RSpec</span><span class="punct">::</span><span class="constant">Core</span><span class="punct">::</span><span class="constant">PendingExampleFixedError</span><span class="punct">.</span><span class="ident">new</span> <span class="keyword">if</span> <span class="ident">result</span></span>
|
|
325
|
+
<span class="linenum">27</span> <span class="keyword">end</span>
|
|
326
|
+
<span class="linenum">28</span> <span class="keyword">raise</span> <span class="constant">PendingDeclaredInExample</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">message</span><span class="punct">)</span></code></pre>
|
|
328
327
|
</div>
|
|
329
328
|
</dd>
|
|
330
329
|
</dl>
|
|
@@ -357,8 +356,7 @@ expected 2
|
|
|
357
356
|
./spec/rspec/core/formatters/html_formatter_spec.rb:46:in `open'
|
|
358
357
|
./spec/rspec/core/formatters/html_formatter_spec.rb:46
|
|
359
358
|
./spec/rspec/core/formatters/html_formatter_spec.rb:45:in `chdir'
|
|
360
|
-
./spec/rspec/core/formatters/html_formatter_spec.rb:45
|
|
361
|
-
:1</pre></div>
|
|
359
|
+
./spec/rspec/core/formatters/html_formatter_spec.rb:45</pre></div>
|
|
362
360
|
<pre class="ruby"><code><span class="linenum">27</span> <span class="keyword">end</span>
|
|
363
361
|
<span class="linenum">28</span>
|
|
364
362
|
<span class="offending"><span class="linenum">29</span> <span class="keyword">raise</span><span class="punct">(</span><span class="constant">RSpec</span><span class="punct">::</span><span class="constant">Expectations</span><span class="punct">::</span><span class="constant">ExpectationNotMetError</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">message</span><span class="punct">))</span></span>
|
|
@@ -385,7 +383,7 @@ expected 2
|
|
|
385
383
|
<dd class="example failed">
|
|
386
384
|
<span class="failed_spec_name">fails with a backtrace containing an erb file</span>
|
|
387
385
|
<div class="failure" id="failure_4">
|
|
388
|
-
<div class="message"><pre
|
|
386
|
+
<div class="message"><pre>Exception</pre></div>
|
|
389
387
|
<div class="backtrace"><pre>/foo.html.erb:1:in `<main>': foo (RuntimeError)</pre></div>
|
|
390
388
|
<pre class="ruby"><code><span class="linenum">-1</span><span class="comment"># Couldn't get snippet for /foo.html.erb</span></code></pre>
|
|
391
389
|
</div>
|