rspec-core 2.14.4 → 2.14.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +15 -0
- data/lib/rspec/core/example_group.rb +2 -12
- data/lib/rspec/core/formatters/json_formatter.rb +0 -2
- data/lib/rspec/core/hooks.rb +25 -4
- data/lib/rspec/core/shared_example_group.rb +13 -12
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/world.rb +1 -1
- data/spec/rspec/core/example_group_spec.rb +13 -3
- data/spec/rspec/core/formatters/json_formatter_spec.rb +5 -0
- data/spec/rspec/core/shared_example_group_spec.rb +26 -2
- metadata +5 -5
data/Changelog.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
### 2.14.5 / 2013-08-13
|
2
|
+
[full changelog](http://github.com/rspec/rspec-core/compare/v2.14.4...v2.14.5)
|
3
|
+
|
4
|
+
Bug fixes:
|
5
|
+
|
6
|
+
* Fix a `NoMethodError` that was being raised when there were no shared
|
7
|
+
examples or contexts declared and `RSpec.world.reset` is invoked.
|
8
|
+
(thepoho, Jon Rowe, Myron Marston)
|
9
|
+
* Fix a deprecation warning that was being incorrectly displayed when
|
10
|
+
`shared_examples` are declared at top level in a `module` scope.
|
11
|
+
(Jon Rowe)
|
12
|
+
* Fix after(:all) hooks so consecutive (same context) scopes will run even if
|
13
|
+
one raises an error. (Jon Rowe, Trejkaz)
|
14
|
+
* JsonFormatter no longer dies if `dump_profile` isn't defined (Alex / @MasterLambaster, Jon Rowe)
|
15
|
+
|
1
16
|
### 2.14.4 / 2013-07-21
|
2
17
|
[full changelog](http://github.com/rspec/rspec-core/compare/v2.14.3...v2.14.4)
|
3
18
|
|
@@ -21,6 +21,7 @@ module RSpec
|
|
21
21
|
include Extensions::InstanceEvalWithArgs
|
22
22
|
include Pending
|
23
23
|
include SharedExampleGroup
|
24
|
+
extend SharedExampleGroup
|
24
25
|
|
25
26
|
# @private
|
26
27
|
def self.world
|
@@ -354,18 +355,7 @@ module RSpec
|
|
354
355
|
return if descendant_filtered_examples.empty?
|
355
356
|
assign_before_all_ivars(before_all_ivars, example_group_instance)
|
356
357
|
|
357
|
-
|
358
|
-
run_hook(:after, :all, example_group_instance)
|
359
|
-
rescue => e
|
360
|
-
# TODO: come up with a better solution for this.
|
361
|
-
RSpec.configuration.reporter.message <<-EOS
|
362
|
-
|
363
|
-
An error occurred in an after(:all) hook.
|
364
|
-
#{e.class}: #{e.message}
|
365
|
-
occurred at #{e.backtrace.first}
|
366
|
-
|
367
|
-
EOS
|
368
|
-
end
|
358
|
+
run_hook(:after, :all, example_group_instance)
|
369
359
|
end
|
370
360
|
|
371
361
|
# Runs all the examples in this group
|
@@ -27,8 +27,6 @@ module RSpec
|
|
27
27
|
:pending_count => pending_count
|
28
28
|
}
|
29
29
|
@output_hash[:summary_line] = summary_line(example_count, failure_count, pending_count)
|
30
|
-
|
31
|
-
dump_profile unless mute_profile_output?(failure_count)
|
32
30
|
end
|
33
31
|
|
34
32
|
def summary_line(example_count, failure_count, pending_count)
|
data/lib/rspec/core/hooks.rb
CHANGED
@@ -36,6 +36,25 @@ module RSpec
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
class AfterAllHook < Hook
|
40
|
+
def run(example)
|
41
|
+
example.instance_exec(example, &block)
|
42
|
+
rescue Exception => e
|
43
|
+
# TODO: come up with a better solution for this.
|
44
|
+
RSpec.configuration.reporter.message <<-EOS
|
45
|
+
|
46
|
+
An error occurred in an after(:all) hook.
|
47
|
+
#{e.class}: #{e.message}
|
48
|
+
occurred at #{e.backtrace.first}
|
49
|
+
|
50
|
+
EOS
|
51
|
+
end
|
52
|
+
|
53
|
+
def display_name
|
54
|
+
"after(:all) hook"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
39
58
|
class AroundHook < Hook
|
40
59
|
def display_name
|
41
60
|
"around hook"
|
@@ -437,11 +456,13 @@ module RSpec
|
|
437
456
|
SCOPES = [:each, :all, :suite]
|
438
457
|
|
439
458
|
HOOK_TYPES = {
|
440
|
-
:before => BeforeHook,
|
441
|
-
:after => AfterHook,
|
442
|
-
:around => AroundHook
|
459
|
+
:before => Hash.new { BeforeHook },
|
460
|
+
:after => Hash.new { AfterHook },
|
461
|
+
:around => Hash.new { AroundHook }
|
443
462
|
}
|
444
463
|
|
464
|
+
HOOK_TYPES[:after][:all] = AfterAllHook
|
465
|
+
|
445
466
|
def before_all_hooks_for(group)
|
446
467
|
GroupHookCollection.new(hooks[:before][:all]).for(group)
|
447
468
|
end
|
@@ -460,7 +481,7 @@ module RSpec
|
|
460
481
|
|
461
482
|
def register_hook prepend_or_append, hook, *args, &block
|
462
483
|
scope, options = scope_and_options_from(*args)
|
463
|
-
hooks[hook][scope].send(prepend_or_append, HOOK_TYPES[hook].new(block, options))
|
484
|
+
hooks[hook][scope].send(prepend_or_append, HOOK_TYPES[hook][scope].new(block, options))
|
464
485
|
end
|
465
486
|
|
466
487
|
def find_hook(hook, scope, example_or_group, initial_procsy)
|
@@ -29,7 +29,7 @@ module RSpec
|
|
29
29
|
# @see ExampleGroup.include_examples
|
30
30
|
# @see ExampleGroup.include_context
|
31
31
|
def shared_examples(*args, &block)
|
32
|
-
|
32
|
+
SharedExampleGroup.registry.add_group(self, *args, &block)
|
33
33
|
end
|
34
34
|
|
35
35
|
alias_method :shared_context, :shared_examples
|
@@ -40,16 +40,16 @@ module RSpec
|
|
40
40
|
def share_as(name, &block)
|
41
41
|
RSpec.deprecate("Rspec::Core::SharedExampleGroup#share_as",
|
42
42
|
:replacement => "RSpec::SharedContext or shared_examples")
|
43
|
-
|
43
|
+
SharedExampleGroup.registry.add_const(self, name, &block)
|
44
44
|
end
|
45
45
|
|
46
46
|
def shared_example_groups
|
47
|
-
|
47
|
+
SharedExampleGroup.registry.shared_example_groups_for('main', *ancestors[0..-1])
|
48
48
|
end
|
49
49
|
|
50
50
|
module TopLevelDSL
|
51
51
|
def shared_examples(*args, &block)
|
52
|
-
|
52
|
+
SharedExampleGroup.registry.add_group('main', *args, &block)
|
53
53
|
end
|
54
54
|
|
55
55
|
alias_method :shared_context, :shared_examples
|
@@ -59,14 +59,18 @@ module RSpec
|
|
59
59
|
def share_as(name, &block)
|
60
60
|
RSpec.deprecate("Rspec::Core::SharedExampleGroup#share_as",
|
61
61
|
:replacement => "RSpec::SharedContext or shared_examples")
|
62
|
-
|
62
|
+
SharedExampleGroup.registry.add_const('main', name, &block)
|
63
63
|
end
|
64
64
|
|
65
65
|
def shared_example_groups
|
66
|
-
|
66
|
+
SharedExampleGroup.registry.shared_example_groups_for('main')
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
def self.registry
|
71
|
+
@registry ||= Registry.new
|
72
|
+
end
|
73
|
+
|
70
74
|
# @private
|
71
75
|
#
|
72
76
|
# Used internally to manage the shared example groups and
|
@@ -74,9 +78,7 @@ module RSpec
|
|
74
78
|
# to objects we don't own (main and Module) so this allows
|
75
79
|
# us to have helper methods that don't get added to those
|
76
80
|
# objects.
|
77
|
-
|
78
|
-
extend self
|
79
|
-
|
81
|
+
class Registry
|
80
82
|
def add_group(source, *args, &block)
|
81
83
|
ensure_block_has_source_location(block, caller[1])
|
82
84
|
|
@@ -128,7 +130,7 @@ module RSpec
|
|
128
130
|
end
|
129
131
|
|
130
132
|
def clear
|
131
|
-
|
133
|
+
shared_example_groups.clear
|
132
134
|
end
|
133
135
|
|
134
136
|
private
|
@@ -180,5 +182,4 @@ module RSpec
|
|
180
182
|
end
|
181
183
|
|
182
184
|
extend RSpec::Core::SharedExampleGroup::TopLevelDSL
|
183
|
-
Module.send(:include, RSpec::Core::SharedExampleGroup)
|
184
|
-
|
185
|
+
Module.send(:include, RSpec::Core::SharedExampleGroup::TopLevelDSL)
|
data/lib/rspec/core/version.rb
CHANGED
data/lib/rspec/core/world.rb
CHANGED
@@ -638,13 +638,17 @@ module RSpec::Core
|
|
638
638
|
end
|
639
639
|
|
640
640
|
context "when an error occurs in an after(:all) hook" do
|
641
|
+
hooks_run = []
|
642
|
+
|
641
643
|
before(:each) do
|
644
|
+
hooks_run = []
|
642
645
|
RSpec.configuration.reporter.stub(:message)
|
643
646
|
end
|
644
647
|
|
645
648
|
let(:group) do
|
646
649
|
ExampleGroup.describe do
|
647
|
-
after(:all) { raise "error in after
|
650
|
+
after(:all) { hooks_run << :one; raise "An error in an after(:all) hook" }
|
651
|
+
after(:all) { hooks_run << :two; raise "A different hook raising an error" }
|
648
652
|
it("equality") { expect(1).to eq(1) }
|
649
653
|
end
|
650
654
|
end
|
@@ -657,9 +661,15 @@ module RSpec::Core
|
|
657
661
|
expect(example.metadata[:execution_result][:status]).to eq("passed")
|
658
662
|
end
|
659
663
|
|
660
|
-
it "rescues
|
661
|
-
RSpec.configuration.reporter.should_receive(:message).with(/error in after
|
664
|
+
it "rescues any error(s) and prints them out" do
|
665
|
+
RSpec.configuration.reporter.should_receive(:message).with(/An error in an after\(:all\) hook/)
|
666
|
+
RSpec.configuration.reporter.should_receive(:message).with(/A different hook raising an error/)
|
667
|
+
group.run
|
668
|
+
end
|
669
|
+
|
670
|
+
it "still runs both after blocks" do
|
662
671
|
group.run
|
672
|
+
expect(hooks_run).to eq [:two,:one]
|
663
673
|
end
|
664
674
|
end
|
665
675
|
|
@@ -106,5 +106,10 @@ describe RSpec::Core::Formatters::JsonFormatter do
|
|
106
106
|
summary_line = formatter.output_hash[:summary_line]
|
107
107
|
expect(summary_line).to eq "2 examples, 1 failure, 1 pending"
|
108
108
|
end
|
109
|
+
|
110
|
+
it "ignores --profile" do
|
111
|
+
allow(RSpec.configuration).to receive(:profile_examples).and_return(true)
|
112
|
+
formatter.dump_summary(1.0, 2, 1, 1)
|
113
|
+
end
|
109
114
|
end
|
110
115
|
end
|
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
module RandomTopLevelModule
|
4
|
+
def self.setup!
|
5
|
+
shared_examples_for("top level in module") {}
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
module RSpec::Core
|
4
10
|
describe SharedExampleGroup do
|
5
11
|
|
@@ -11,6 +17,19 @@ module RSpec::Core
|
|
11
17
|
expect(Module.private_methods & seg_methods).to eq([])
|
12
18
|
end
|
13
19
|
|
20
|
+
module SharedExampleGroup
|
21
|
+
describe Registry do
|
22
|
+
it "can safely be reset when there aren't any shared groups" do
|
23
|
+
expect { Registry.new.clear }.to_not raise_error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
before(:all) do
|
29
|
+
# this is a work around as SharedExampleGroup is not world safe
|
30
|
+
RandomTopLevelModule.setup!
|
31
|
+
end
|
32
|
+
|
14
33
|
%w[share_examples_for shared_examples_for shared_examples shared_context].each do |shared_method_name|
|
15
34
|
describe shared_method_name do
|
16
35
|
it "is exposed to the global namespace" do
|
@@ -30,13 +49,18 @@ module RSpec::Core
|
|
30
49
|
expect(warning).to include('some shared group', original_declaration, second_declaration)
|
31
50
|
end
|
32
51
|
|
52
|
+
it 'works with top level defined examples in modules' do
|
53
|
+
expect(RSpec::configuration.reporter).to_not receive(:deprecation)
|
54
|
+
group = ExampleGroup.describe('example group') { include_context 'top level in module' }
|
55
|
+
end
|
56
|
+
|
33
57
|
["name", :name, ExampleModule, ExampleClass].each do |object|
|
34
58
|
type = object.class.name.downcase
|
35
59
|
context "given a #{type}" do
|
36
60
|
it "captures the given #{type} and block in the collection of shared example groups" do
|
37
61
|
implementation = lambda {}
|
38
62
|
send(shared_method_name, object, &implementation)
|
39
|
-
expect(SharedExampleGroup
|
63
|
+
expect(SharedExampleGroup.registry.shared_example_groups[self][object]).to eq implementation
|
40
64
|
end
|
41
65
|
end
|
42
66
|
end
|
@@ -56,7 +80,7 @@ module RSpec::Core
|
|
56
80
|
it "captures the given string and block in the World's collection of shared example groups" do
|
57
81
|
implementation = lambda {}
|
58
82
|
send(shared_method_name, "name", :foo => :bar, &implementation)
|
59
|
-
expect(SharedExampleGroup
|
83
|
+
expect(SharedExampleGroup.registry.shared_example_groups[self]["name"]).to eq implementation
|
60
84
|
end
|
61
85
|
|
62
86
|
it "delegates extend on configuration" do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rspec-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 2.14.
|
5
|
+
version: 2.14.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Steven Baker
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -383,7 +383,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
383
383
|
version: '0'
|
384
384
|
segments:
|
385
385
|
- 0
|
386
|
-
hash:
|
386
|
+
hash: 2492327081030983877
|
387
387
|
none: false
|
388
388
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
389
389
|
requirements:
|
@@ -392,14 +392,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
392
392
|
version: '0'
|
393
393
|
segments:
|
394
394
|
- 0
|
395
|
-
hash:
|
395
|
+
hash: 2492327081030983877
|
396
396
|
none: false
|
397
397
|
requirements: []
|
398
398
|
rubyforge_project: rspec
|
399
399
|
rubygems_version: 1.8.24
|
400
400
|
signing_key:
|
401
401
|
specification_version: 3
|
402
|
-
summary: rspec-core-2.14.
|
402
|
+
summary: rspec-core-2.14.5
|
403
403
|
test_files:
|
404
404
|
- features/Autotest.md
|
405
405
|
- features/README.md
|