rspec-core 2.0.0.a5 → 2.0.0.a6
Sign up to get free protection for your applications and to get access to all the features.
- data/example_specs/failing/diffing_spec.rb +3 -1
- data/example_specs/spec_helper.rb +1 -1
- data/features/configuration/spec_opts.feature +7 -7
- data/features/example_groups/describe_aliases.feature +1 -1
- data/features/example_groups/nested_groups.feature +3 -6
- data/features/{before_and_after_blocks/around.feature → hooks/around_hook.feature} +1 -1
- data/features/{before_and_after_blocks/before_and_after_blocks.feature → hooks/before_and_after_hooks.feature} +3 -3
- data/features/hooks/halt.feature +27 -0
- data/features/mock_framework_integration/use_flexmock.feature +1 -1
- data/features/mock_framework_integration/use_mocha.feature +1 -1
- data/features/mock_framework_integration/use_rr.feature +1 -1
- data/features/mock_framework_integration/use_rspec.feature +1 -1
- data/features/mocks/block_local_expectations.feature +2 -2
- data/features/mocks/mix_stubs_and_mocks.feature +1 -1
- data/lib/rspec/core.rb +6 -0
- data/lib/rspec/core/around_proxy.rb +14 -0
- data/lib/rspec/core/deprecation.rb +25 -26
- data/lib/rspec/core/example.rb +11 -21
- data/lib/rspec/core/example_group.rb +27 -22
- data/lib/rspec/core/runner.rb +12 -12
- data/lib/rspec/core/version.rb +1 -1
- data/rspec-core.gemspec +13 -11
- data/spec/rspec/core/configuration_spec.rb +2 -4
- data/spec/rspec/core/example_group_spec.rb +263 -292
- data/spec/rspec/core/example_group_subject_spec.rb +26 -31
- data/spec/rspec/core/mocha_spec.rb +8 -10
- data/spec/rspec/core/pending_example_spec.rb +1 -1
- data/spec/rspec/core/runner_spec.rb +2 -2
- data/spec/rspec/core/shared_example_group_spec.rb +120 -129
- data/spec/rspec/core/world_spec.rb +111 -116
- data/spec/rspec/core_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -23
- metadata +9 -7
@@ -1,3 +1,5 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
1
3
|
describe "Running specs with --diff" do
|
2
4
|
it "should print diff of different strings" do
|
3
5
|
uk = <<-EOF
|
@@ -31,6 +33,6 @@ species=#{@species}
|
|
31
33
|
it "should print diff of different objects' pretty representation" do
|
32
34
|
expected = Animal.new "bob", "giraffe"
|
33
35
|
actual = Animal.new "bob", "tortoise"
|
34
|
-
expected.should
|
36
|
+
expected.should eq(actual)
|
35
37
|
end
|
36
38
|
end
|
@@ -5,15 +5,15 @@ Feature: spec/spec.opts
|
|
5
5
|
automatically.
|
6
6
|
|
7
7
|
Options declared in spec/spec.opts will override configuration
|
8
|
-
set up in Rspec
|
8
|
+
set up in Rspec.configure blocks.
|
9
9
|
|
10
10
|
Background:
|
11
11
|
Given a directory named "spec"
|
12
12
|
|
13
|
-
Scenario: color set in Rspec
|
13
|
+
Scenario: color set in Rspec.configure
|
14
14
|
Given a file named "spec/spec_helper.rb" with:
|
15
15
|
"""
|
16
|
-
Rspec
|
16
|
+
Rspec.configure do |c|
|
17
17
|
c.color_enabled = true
|
18
18
|
end
|
19
19
|
"""
|
@@ -21,7 +21,7 @@ Feature: spec/spec.opts
|
|
21
21
|
"""
|
22
22
|
require "spec_helper"
|
23
23
|
describe "color_enabled" do
|
24
|
-
context "when set with Rspec
|
24
|
+
context "when set with Rspec.configure" do
|
25
25
|
it "is true" do
|
26
26
|
Rspec::Core.configuration.color_enabled?.should be_true
|
27
27
|
end
|
@@ -39,7 +39,7 @@ Feature: spec/spec.opts
|
|
39
39
|
And a file named "spec/example_spec.rb" with:
|
40
40
|
"""
|
41
41
|
describe "color_enabled" do
|
42
|
-
context "when set with Rspec
|
42
|
+
context "when set with Rspec.configure" do
|
43
43
|
it "is true" do
|
44
44
|
Rspec::Core.configuration.color_enabled?.should be_true
|
45
45
|
end
|
@@ -57,14 +57,14 @@ Feature: spec/spec.opts
|
|
57
57
|
|
58
58
|
And a file named "spec/spec_helper.rb" with:
|
59
59
|
"""
|
60
|
-
Rspec
|
60
|
+
Rspec.configure do |c|
|
61
61
|
c.formatter = 'pretty'
|
62
62
|
end
|
63
63
|
"""
|
64
64
|
And a file named "spec/example_spec.rb" with:
|
65
65
|
"""
|
66
66
|
describe "formatter" do
|
67
|
-
context "when set with Rspec
|
67
|
+
context "when set with Rspec.configure and in spec.opts" do
|
68
68
|
it "takes the value set in spec.opts" do
|
69
69
|
Rspec::Core.configuration.formatter.should be_an(Rspec::Core::Formatters::DocumentationFormatter)
|
70
70
|
end
|
@@ -4,7 +4,7 @@ Feature: Nested example groups
|
|
4
4
|
I want to use alternate names for describe
|
5
5
|
So that I can better organize my examples
|
6
6
|
|
7
|
-
Scenario
|
7
|
+
Scenario: Using context
|
8
8
|
Given a file named "context_instead_of_describe_spec.rb" with:
|
9
9
|
"""
|
10
10
|
context "Using context" do
|
@@ -4,13 +4,10 @@ Feature: Nested example groups
|
|
4
4
|
I want to nest examples groups
|
5
5
|
So that I can better organize my examples
|
6
6
|
|
7
|
-
|
7
|
+
@wip
|
8
|
+
Scenario: Nested example groups
|
8
9
|
Given a file named "nested_example_groups.rb" with:
|
9
10
|
"""
|
10
|
-
require 'rspec/autorun'
|
11
|
-
require 'rspec/expectations'
|
12
|
-
Rspec::Core::ExampleGroup.send(:include, Rspec::Matchers)
|
13
|
-
|
14
11
|
describe "Some Object" do
|
15
12
|
describe "with some more context" do
|
16
13
|
it "should do this" do
|
@@ -24,7 +21,7 @@ Feature: Nested example groups
|
|
24
21
|
end
|
25
22
|
end
|
26
23
|
"""
|
27
|
-
When I run "rspec nested_example_groups.rb -
|
24
|
+
When I run "rspec nested_example_groups.rb -fdoc"
|
28
25
|
Then the stdout should match /^Some Object/
|
29
26
|
And the stdout should match /^\s+with some more context/
|
30
27
|
And the stdout should match /^\s+with some other context/
|
@@ -1,4 +1,4 @@
|
|
1
|
-
Feature: before and after
|
1
|
+
Feature: before and after hooks
|
2
2
|
|
3
3
|
As a developer using RSpec
|
4
4
|
I want to execute arbitrary code before and after each example
|
@@ -96,7 +96,7 @@ Feature: before and after blocks
|
|
96
96
|
Scenario: define before and after blocks in configuration
|
97
97
|
Given a file named "befores_in_configuration_spec.rb" with:
|
98
98
|
"""
|
99
|
-
Rspec
|
99
|
+
Rspec.configure do |config|
|
100
100
|
config.before(:suite) do
|
101
101
|
$before_suite = "before suite"
|
102
102
|
end
|
@@ -133,7 +133,7 @@ Feature: before and after blocks
|
|
133
133
|
Scenario: before/after blocks are run in order
|
134
134
|
Given a file named "ensure_block_order_spec.rb" with:
|
135
135
|
"""
|
136
|
-
Rspec
|
136
|
+
Rspec.configure do |config|
|
137
137
|
config.before(:suite) do
|
138
138
|
puts "before suite"
|
139
139
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: halt
|
2
|
+
|
3
|
+
In an example, before hook, after hook, or around hook, you can
|
4
|
+
halt the current example, group, or suite based on arbitrary
|
5
|
+
criteria.
|
6
|
+
|
7
|
+
@wip
|
8
|
+
Scenario: halt group on failure
|
9
|
+
Given a directory named "spec"
|
10
|
+
And a file named "spec/example_spec.rb" with:
|
11
|
+
"""
|
12
|
+
Rspec.configure do |c|
|
13
|
+
c.after(:each) do
|
14
|
+
running_example.halt(:group, :status => 'failed')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe "something" do
|
18
|
+
it "fails" do
|
19
|
+
fail
|
20
|
+
end
|
21
|
+
|
22
|
+
it "does not run this example" do
|
23
|
+
end
|
24
|
+
end
|
25
|
+
"""
|
26
|
+
When I run "rspec spec/example_spec.rb"
|
27
|
+
Then the stdout should match "1 example, 1 failure"
|
@@ -22,7 +22,7 @@ Feature: block local expectations
|
|
22
22
|
"""
|
23
23
|
require 'account'
|
24
24
|
|
25
|
-
Rspec
|
25
|
+
Rspec.configure do |config|
|
26
26
|
config.mock_framework = :rspec
|
27
27
|
end
|
28
28
|
|
@@ -47,7 +47,7 @@ Feature: block local expectations
|
|
47
47
|
"""
|
48
48
|
require 'account'
|
49
49
|
|
50
|
-
Rspec
|
50
|
+
Rspec.configure do |config|
|
51
51
|
config.mock_framework = :rspec
|
52
52
|
end
|
53
53
|
|
data/lib/rspec/core.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rspec/core/load_path'
|
2
2
|
require 'rspec/core/deprecation'
|
3
3
|
require 'rspec/core/mocking/with_absolutely_nothing'
|
4
|
+
require 'rspec/core/around_proxy'
|
4
5
|
require 'rspec/core/world'
|
5
6
|
require 'rspec/core/configuration'
|
6
7
|
require 'rspec/core/command_line_options'
|
@@ -27,6 +28,7 @@ module Rspec
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def self.configure
|
31
|
+
Rspec.deprecate('Rspec::Core.configure', 'Rspec.configure', '2.0.0')
|
30
32
|
yield configuration if block_given?
|
31
33
|
end
|
32
34
|
|
@@ -35,4 +37,8 @@ module Rspec
|
|
35
37
|
end
|
36
38
|
|
37
39
|
end
|
40
|
+
|
41
|
+
def self.configure
|
42
|
+
yield Core.configuration if block_given?
|
43
|
+
end
|
38
44
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Rspec
|
2
|
+
module Core
|
3
|
+
class AroundProxy
|
4
|
+
def initialize(example_group_instance, &example_block)
|
5
|
+
@example_group_instance, @example_block = example_group_instance, example_block
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
@example_group_instance.instance_eval(&@example_block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -1,47 +1,46 @@
|
|
1
1
|
module Rspec
|
2
|
-
module Core
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
class << self
|
4
|
+
def deprecate(method, alternate_method=nil, version=nil)
|
5
|
+
version_string = version ? "rspec-#{version}" : "a future version of Rspec"
|
6
|
+
|
7
|
+
message = <<-NOTICE
|
7
8
|
|
8
9
|
*****************************************************************
|
9
10
|
DEPRECATION WARNING: you are using deprecated behaviour that will
|
10
|
-
be removed from
|
11
|
+
be removed from #{version_string}.
|
11
12
|
|
12
13
|
#{caller(0)[2]}
|
13
14
|
|
14
15
|
* #{method} is deprecated.
|
15
16
|
NOTICE
|
16
|
-
|
17
|
-
|
17
|
+
if alternate_method
|
18
|
+
message << <<-ADDITIONAL
|
18
19
|
* please use #{alternate_method} instead.
|
19
20
|
ADDITIONAL
|
20
|
-
end
|
21
|
-
|
22
|
-
message << "*****************************************************************"
|
23
|
-
warn(message)
|
24
21
|
end
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
message << "*****************************************************************"
|
24
|
+
warn(message)
|
25
|
+
end
|
29
26
|
|
27
|
+
def warn(message)
|
28
|
+
Kernel.warn(message)
|
30
29
|
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
31
|
+
end
|
32
|
+
|
33
|
+
class HashWithDeprecationNotice < Hash
|
34
|
+
|
35
|
+
def initialize(method, alternate_method=nil, &block)
|
36
|
+
@method, @alternate_method = method, alternate_method
|
37
|
+
end
|
38
|
+
|
39
|
+
def []=(k,v)
|
40
|
+
Rspec.deprecate(@method, @alternate_method)
|
41
|
+
super
|
43
42
|
end
|
44
43
|
|
45
44
|
end
|
46
45
|
|
47
|
-
end
|
46
|
+
end
|
data/lib/rspec/core/example.rb
CHANGED
@@ -35,23 +35,23 @@ module Rspec
|
|
35
35
|
record_results :started_at => Time.now
|
36
36
|
end
|
37
37
|
|
38
|
-
def run_passed
|
39
|
-
run_finished 'passed'
|
38
|
+
def run_passed(reporter=nil)
|
39
|
+
run_finished reporter, 'passed'
|
40
40
|
end
|
41
41
|
|
42
|
-
def run_pending(message='Not yet implemented')
|
43
|
-
run_finished 'pending', :pending_message => message
|
42
|
+
def run_pending(reporter=nil, message='Not yet implemented')
|
43
|
+
run_finished reporter, 'pending', :pending_message => message
|
44
44
|
end
|
45
45
|
|
46
|
-
def run_failed(exception)
|
47
|
-
run_finished 'failed', :exception_encountered => exception
|
46
|
+
def run_failed(reporter, exception)
|
47
|
+
run_finished reporter, 'failed', :exception_encountered => exception
|
48
48
|
end
|
49
49
|
|
50
|
-
def run_finished(status, results={})
|
50
|
+
def run_finished(reporter, status, results={})
|
51
51
|
record_results results.update(:status => status)
|
52
52
|
finish_time = Time.now
|
53
53
|
record_results :finished_at => finish_time, :run_time => (finish_time - execution_result[:started_at])
|
54
|
-
|
54
|
+
reporter.example_finished(self)
|
55
55
|
end
|
56
56
|
|
57
57
|
def run_before_each
|
@@ -73,21 +73,11 @@ module Rspec
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
class AroundProxy
|
77
|
-
def initialize(example_group_instance, &example_block)
|
78
|
-
@example_group_instance, @example_block = example_group_instance, example_block
|
79
|
-
end
|
80
|
-
|
81
|
-
def run
|
82
|
-
@example_group_instance.instance_eval(&@example_block)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
76
|
def runnable?
|
87
77
|
!metadata[:pending]
|
88
78
|
end
|
89
79
|
|
90
|
-
def run(example_group_instance)
|
80
|
+
def run(example_group_instance, reporter)
|
91
81
|
@example_group_instance = example_group_instance
|
92
82
|
@example_group_instance.running_example = self
|
93
83
|
|
@@ -120,9 +110,9 @@ module Rspec
|
|
120
110
|
end
|
121
111
|
|
122
112
|
if exception_encountered
|
123
|
-
run_failed(exception_encountered)
|
113
|
+
run_failed(reporter, exception_encountered)
|
124
114
|
else
|
125
|
-
runnable? ? run_passed : run_pending
|
115
|
+
runnable? ? run_passed(reporter) : run_pending(reporter)
|
126
116
|
end
|
127
117
|
|
128
118
|
all_systems_nominal
|
@@ -8,7 +8,7 @@ module Rspec
|
|
8
8
|
extend Advice
|
9
9
|
include ExampleGroupSubject
|
10
10
|
|
11
|
-
attr_accessor :running_example
|
11
|
+
attr_accessor :running_example
|
12
12
|
|
13
13
|
def self.inherited(klass)
|
14
14
|
super
|
@@ -58,8 +58,12 @@ module Rspec
|
|
58
58
|
@_examples_to_run ||= []
|
59
59
|
end
|
60
60
|
|
61
|
+
def self.superclass_metadata
|
62
|
+
self.superclass.respond_to?(:metadata) ? self.superclass.metadata : nil
|
63
|
+
end
|
64
|
+
|
61
65
|
def self.set_it_up(*args)
|
62
|
-
@metadata = Rspec::Core::Metadata.process(
|
66
|
+
@metadata = Rspec::Core::Metadata.process(superclass_metadata, *args)
|
63
67
|
|
64
68
|
Rspec::Core.configuration.find_modules(self).each do |include_or_extend, mod, opts|
|
65
69
|
if include_or_extend == :extend
|
@@ -97,15 +101,24 @@ module Rspec
|
|
97
101
|
def self.describe(*args, &example_group_block)
|
98
102
|
raise(ArgumentError, "No arguments given. You must a least supply a type or description") if args.empty?
|
99
103
|
raise(ArgumentError, "You must supply a block when calling describe") if example_group_block.nil?
|
104
|
+
@_subclass_count ||= 0
|
105
|
+
@_subclass_count += 1
|
106
|
+
const_set(
|
107
|
+
"NestedLevel_#{@_subclass_count}",
|
108
|
+
_build(Class.new(self), caller, args, &example_group_block)
|
109
|
+
)
|
110
|
+
end
|
100
111
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
112
|
+
def self.create(*args, &example_group_block)
|
113
|
+
_build(dup, caller, args, &example_group_block)
|
114
|
+
end
|
115
|
+
|
116
|
+
def self._build(klass, given_caller, args, &example_group_block)
|
117
|
+
args << {} unless args.last.is_a?(Hash)
|
118
|
+
args.last.update(:example_group_block => example_group_block, :caller => given_caller)
|
119
|
+
klass.set_it_up(*args)
|
120
|
+
klass.module_eval(&example_group_block) if example_group_block
|
121
|
+
klass
|
109
122
|
end
|
110
123
|
|
111
124
|
class << self
|
@@ -137,7 +150,9 @@ module Rspec
|
|
137
150
|
end
|
138
151
|
|
139
152
|
def self.eval_before_alls(running_example)
|
140
|
-
superclass.before_all_ivars
|
153
|
+
if superclass.respond_to?(:before_all_ivars)
|
154
|
+
superclass.before_all_ivars.each { |ivar, val| running_example.instance_variable_set(ivar, val) }
|
155
|
+
end
|
141
156
|
Rspec::Core.configuration.find_advice(:before, :all, self).each { |blk| running_example.instance_eval(&blk) }
|
142
157
|
|
143
158
|
before_alls.each { |blk| running_example.instance_eval(&blk) }
|
@@ -173,23 +188,13 @@ module Rspec
|
|
173
188
|
# Runs all examples, returning true only if all of them pass
|
174
189
|
def self.run_examples(example_world, reporter)
|
175
190
|
examples_to_run.map do |ex|
|
176
|
-
result = ex.run(example_world)
|
191
|
+
result = ex.run(example_world, reporter)
|
177
192
|
example_world.__reset__
|
178
193
|
before_all_ivars.each { |k, v| example_world.instance_variable_set(k, v) }
|
179
194
|
result
|
180
195
|
end.all?
|
181
196
|
end
|
182
197
|
|
183
|
-
def self.subclass(base_name, &body) # :nodoc:
|
184
|
-
@_subclass_count ||= 0
|
185
|
-
@_subclass_count += 1
|
186
|
-
klass = Class.new(self)
|
187
|
-
class_name = "#{base_name}_#{@_subclass_count}"
|
188
|
-
const_set(class_name, klass)
|
189
|
-
klass.instance_eval(&body)
|
190
|
-
klass
|
191
|
-
end
|
192
|
-
|
193
198
|
def self.to_s
|
194
199
|
self == Rspec::Core::ExampleGroup ? 'Rspec::Core::ExampleGroup' : name
|
195
200
|
end
|