rspec-core 2.8.0.rc1 → 2.8.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.
- data/License.txt +24 -0
- data/README.md +197 -37
- data/features/command_line/format_option.feature +3 -3
- data/features/command_line/init.feature +18 -0
- data/features/example_groups/shared_examples.feature +1 -1
- data/features/hooks/around_hooks.feature +4 -4
- data/features/pending/pending_examples.feature +5 -5
- data/features/support/env.rb +8 -1
- data/lib/autotest/rspec2.rb +2 -6
- data/lib/rspec/core.rb +48 -158
- data/lib/rspec/core/backward_compatibility.rb +2 -0
- data/lib/rspec/core/command_line.rb +4 -0
- data/lib/rspec/core/configuration.rb +201 -106
- data/lib/rspec/core/configuration_options.rb +2 -1
- data/lib/rspec/core/deprecation.rb +2 -3
- data/lib/rspec/core/drb_options.rb +69 -58
- data/lib/rspec/core/dsl.rb +12 -0
- data/lib/rspec/core/example.rb +53 -18
- data/lib/rspec/core/example_group.rb +144 -54
- data/lib/rspec/core/extensions.rb +4 -4
- data/lib/rspec/core/extensions/instance_eval_with_args.rb +5 -0
- data/lib/rspec/core/extensions/kernel.rb +1 -1
- data/lib/rspec/core/extensions/module_eval_with_args.rb +4 -0
- data/lib/rspec/core/extensions/ordered.rb +7 -2
- data/lib/rspec/core/filter_manager.rb +69 -36
- data/lib/rspec/core/formatters/base_text_formatter.rb +1 -1
- data/lib/rspec/core/formatters/html_formatter.rb +10 -4
- data/lib/rspec/core/hooks.rb +93 -34
- data/lib/rspec/core/let.rb +62 -61
- data/lib/rspec/core/metadata.rb +103 -80
- data/lib/rspec/core/metadata_hash_builder.rb +4 -0
- data/lib/rspec/core/option_parser.rb +42 -44
- data/lib/rspec/core/pending.rb +25 -3
- data/lib/rspec/core/project_initializer.rb +62 -0
- data/lib/rspec/core/rake_task.rb +7 -13
- data/lib/rspec/core/runner.rb +2 -2
- data/lib/rspec/core/shared_context.rb +1 -1
- data/lib/rspec/core/shared_example_group.rb +11 -5
- data/lib/rspec/core/subject.rb +3 -3
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/monkey.rb +1 -1
- data/lib/rspec/monkey/spork/test_framework/rspec.rb +2 -0
- data/spec/command_line/order_spec.rb +19 -13
- data/spec/rspec/core/command_line_spec.rb +1 -5
- data/spec/rspec/core/configuration_options_spec.rb +22 -27
- data/spec/rspec/core/configuration_spec.rb +32 -14
- data/spec/rspec/core/drb_command_line_spec.rb +20 -37
- data/spec/rspec/core/drb_options_spec.rb +51 -3
- data/spec/rspec/core/example_group_spec.rb +101 -84
- data/spec/rspec/core/example_spec.rb +14 -0
- data/spec/rspec/core/filter_manager_spec.rb +114 -33
- data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +17 -69
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +14 -4
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +14 -4
- data/spec/rspec/core/formatters/html_formatted-1.9.3.html +14 -4
- data/spec/rspec/core/formatters/html_formatter_spec.rb +1 -1
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +20 -72
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +24 -14
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +29 -19
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +29 -19
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +1 -2
- data/spec/rspec/core/metadata_spec.rb +77 -45
- data/spec/rspec/core/option_parser_spec.rb +5 -0
- data/spec/rspec/core/pending_example_spec.rb +44 -12
- data/spec/rspec/core/project_initializer_spec.rb +130 -0
- data/spec/rspec/core/rake_task_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/support/matchers.rb +2 -12
- metadata +18 -16
- data/features/command_line/configure.feature +0 -22
- data/lib/rspec/core/command_line_configuration.rb +0 -62
- data/lib/rspec/core/errors.rb +0 -13
- data/spec/rspec/core/command_line_configuration_spec.rb +0 -26
@@ -1,4 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require_rspec 'core/extensions/kernel'
|
2
|
+
require_rspec 'core/extensions/instance_eval_with_args'
|
3
|
+
require_rspec 'core/extensions/module_eval_with_args'
|
4
|
+
require_rspec 'core/extensions/ordered'
|
@@ -1,7 +1,12 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Core
|
3
3
|
module Extensions
|
4
|
+
# @private
|
4
5
|
module InstanceEvalWithArgs
|
6
|
+
# @private
|
7
|
+
#
|
8
|
+
# Used internally to support `instance_exec` in Ruby 1.8.6.
|
9
|
+
#
|
5
10
|
# based on Bounded Spec InstanceExec (Mauricio Fernandez)
|
6
11
|
# http://eigenclass.org/hiki/bounded+space+instance_exec
|
7
12
|
# - uses singleton_class instead of global InstanceExecHelper module
|
@@ -1,9 +1,13 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Core
|
3
3
|
module Extensions
|
4
|
+
# @private
|
4
5
|
module ModuleEvalWithArgs
|
5
6
|
include InstanceEvalWithArgs
|
6
7
|
|
8
|
+
# @private
|
9
|
+
#
|
10
|
+
# Used internally to support `module_exec` in Ruby 1.8.6.
|
7
11
|
def module_eval_with_args(*args, &block)
|
8
12
|
# ruby > 1.8.6
|
9
13
|
return module_exec(*args, &block) if respond_to?(:module_exec)
|
@@ -1,11 +1,16 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Core
|
3
|
+
# @private
|
3
4
|
module Extensions
|
5
|
+
# @private
|
6
|
+
# Used to extend lists of examples and groups to support ordering
|
7
|
+
# strategies like randomization.
|
4
8
|
module Ordered
|
9
|
+
# @private
|
5
10
|
def ordered
|
6
11
|
if RSpec.configuration.randomize?
|
7
|
-
srand RSpec.configuration.seed
|
8
|
-
sort_by { rand size }
|
12
|
+
Kernel.srand RSpec.configuration.seed
|
13
|
+
sort_by { Kernel.rand size }
|
9
14
|
else
|
10
15
|
self
|
11
16
|
end
|
@@ -61,6 +61,10 @@ module RSpec
|
|
61
61
|
# end
|
62
62
|
#
|
63
63
|
# These declarations can also be overridden from the command line.
|
64
|
+
#
|
65
|
+
# @see RSpec.configure
|
66
|
+
# @see Configuration#filter_run_including
|
67
|
+
# @see Configuration#filter_run_excluding
|
64
68
|
class FilterManager
|
65
69
|
DEFAULT_EXCLUSIONS = {
|
66
70
|
:if => lambda { |value, metadata| metadata.has_key?(:if) && !value },
|
@@ -83,20 +87,29 @@ module RSpec
|
|
83
87
|
end
|
84
88
|
|
85
89
|
module BackwardCompatibility
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
RSpec.warn_deprecation("\nDEPRECATION NOTICE: FilterManager#exclude(:unless => #{updates.last[:unless].inspect}) is deprecated with no replacement, and will be removed from rspec-3.0.")
|
91
|
-
@exclusions[:unless] = updates.last.delete(:unless)
|
92
|
-
end
|
93
|
-
if updates.last.has_key?(:if)
|
94
|
-
RSpec.warn_deprecation("\nDEPRECATION NOTICE: FilterManager#exclude(:if => #{updates.last[:if].inspect}) is deprecated with no replacement, and will be removed from rspec-3.0.")
|
95
|
-
@exclusions[:if] = updates.last.delete(:if)
|
96
|
-
end
|
90
|
+
def merge(orig, opposite, *updates)
|
91
|
+
_warn_deprecated_keys(updates.last)
|
92
|
+
super
|
93
|
+
end
|
97
94
|
|
95
|
+
def reverse_merge(orig, opposite, *updates)
|
96
|
+
_warn_deprecated_keys(updates.last)
|
98
97
|
super
|
99
98
|
end
|
99
|
+
|
100
|
+
# Supports a use case that probably doesn't exist: overriding the
|
101
|
+
# if/unless procs.
|
102
|
+
def _warn_deprecated_keys(updates)
|
103
|
+
_warn_deprecated_key(:unless, updates) if updates.has_key?(:unless)
|
104
|
+
_warn_deprecated_key(:if, updates) if updates.has_key?(:if)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Emits a deprecation warning for keys that will not be supported in
|
108
|
+
# the future.
|
109
|
+
def _warn_deprecated_key(key, updates)
|
110
|
+
RSpec.warn_deprecation("\nDEPRECATION NOTICE: FilterManager#exclude(#{key.inspect} => #{updates[key].inspect}) is deprecated with no replacement, and will be removed from rspec-3.0.")
|
111
|
+
@exclusions[key] = updates.delete(key)
|
112
|
+
end
|
100
113
|
end
|
101
114
|
|
102
115
|
attr_reader :exclusions, :inclusions
|
@@ -108,14 +121,13 @@ module RSpec
|
|
108
121
|
end
|
109
122
|
|
110
123
|
def add_location(file_path, line_numbers)
|
111
|
-
#
|
124
|
+
# locations is a hash of expanded paths to arrays of line
|
112
125
|
# numbers to match against. e.g.
|
113
126
|
# { "path/to/file.rb" => [37, 42] }
|
114
|
-
|
127
|
+
locations = @inclusions.delete(:locations) || Hash.new {|h,k| h[k] = []}
|
128
|
+
locations[File.expand_path(file_path)].push(*line_numbers)
|
129
|
+
@inclusions.replace(:locations => locations)
|
115
130
|
@exclusions.clear
|
116
|
-
@inclusions.clear
|
117
|
-
filter_locations[File.expand_path(file_path)].push(*line_numbers)
|
118
|
-
include :locations => filter_locations
|
119
131
|
end
|
120
132
|
|
121
133
|
def empty?
|
@@ -126,36 +138,57 @@ module RSpec
|
|
126
138
|
examples.select {|e| !exclude?(e) && include?(e)}
|
127
139
|
end
|
128
140
|
|
141
|
+
def exclude(*args)
|
142
|
+
merge(@exclusions, @inclusions, *args)
|
143
|
+
end
|
144
|
+
|
145
|
+
def exclude!(*args)
|
146
|
+
replace(@exclusions, @inclusions, *args)
|
147
|
+
end
|
148
|
+
|
149
|
+
def exclude_with_low_priority(*args)
|
150
|
+
reverse_merge(@exclusions, @inclusions, *args)
|
151
|
+
end
|
152
|
+
|
129
153
|
def exclude?(example)
|
130
154
|
@exclusions.empty? ? false : example.any_apply?(@exclusions)
|
131
155
|
end
|
132
156
|
|
157
|
+
def include(*args)
|
158
|
+
unless_standalone(*args) { merge(@inclusions, @exclusions, *args) }
|
159
|
+
end
|
160
|
+
|
161
|
+
def include!(*args)
|
162
|
+
unless_standalone(*args) { replace(@inclusions, @exclusions, *args) }
|
163
|
+
end
|
164
|
+
|
165
|
+
def include_with_low_priority(*args)
|
166
|
+
unless_standalone(*args) { reverse_merge(@inclusions, @exclusions, *args) }
|
167
|
+
end
|
168
|
+
|
133
169
|
def include?(example)
|
134
170
|
@inclusions.empty? ? true : example.any_apply?(@inclusions)
|
135
171
|
end
|
136
172
|
|
137
|
-
|
138
|
-
|
173
|
+
private
|
174
|
+
|
175
|
+
def unless_standalone(*args)
|
176
|
+
is_standalone_filter?(args.last) ? @inclusions.replace(args.last) : yield unless already_set_standalone_filter?
|
139
177
|
end
|
140
178
|
|
141
|
-
def
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
end
|
155
|
-
orig.replace(updated)
|
156
|
-
else
|
157
|
-
orig.merge!(updates.last).each_key {|k| opposite.delete(k)}
|
158
|
-
end
|
179
|
+
def merge(orig, opposite, *updates)
|
180
|
+
orig.merge!(updates.last).each_key {|k| opposite.delete(k)}
|
181
|
+
end
|
182
|
+
|
183
|
+
def replace(orig, opposite, *updates)
|
184
|
+
updates.last.each_key {|k| opposite.delete(k)}
|
185
|
+
orig.replace(updates.last)
|
186
|
+
end
|
187
|
+
|
188
|
+
def reverse_merge(orig, opposite, *updates)
|
189
|
+
updated = updates.last.merge(orig)
|
190
|
+
opposite.each_pair {|k,v| updated.delete(k) if updated[k] == v}
|
191
|
+
orig.replace(updated)
|
159
192
|
end
|
160
193
|
|
161
194
|
def already_set_standalone_filter?
|
@@ -159,7 +159,7 @@ module RSpec
|
|
159
159
|
end
|
160
160
|
|
161
161
|
def dump_pending_example_fixed(example, index)
|
162
|
-
if
|
162
|
+
if example.execution_result[:exception].pending_fixed?
|
163
163
|
output.puts "#{short_padding}#{index.next}) #{example.full_description} FIXED"
|
164
164
|
output.puts blue("#{long_padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised.")
|
165
165
|
true
|
@@ -67,7 +67,7 @@ module RSpec
|
|
67
67
|
|
68
68
|
def example_passed(example)
|
69
69
|
move_progress
|
70
|
-
@output.puts " <dd class=\"example passed\"><span class=\"passed_spec_name\">#{h(example.description)}</span></dd>"
|
70
|
+
@output.puts " <dd class=\"example passed\"><span class=\"passed_spec_name\">#{h(example.description)}</span><span class='duration'>#{sprintf("%.5f", example.execution_result[:run_time])}s</span></dd>"
|
71
71
|
@output.flush
|
72
72
|
end
|
73
73
|
|
@@ -75,15 +75,15 @@ module RSpec
|
|
75
75
|
super(example)
|
76
76
|
exception = example.metadata[:execution_result][:exception]
|
77
77
|
extra = extra_failure_content(exception)
|
78
|
-
failure_style = RSpec::Core::PendingExampleFixedError === exception ? 'pending_fixed' : 'failed'
|
79
78
|
@output.puts " <script type=\"text/javascript\">makeRed('rspec-header');</script>" unless @header_red
|
80
79
|
@header_red = true
|
81
80
|
@output.puts " <script type=\"text/javascript\">makeRed('div_group_#{example_group_number}');</script>" unless @example_group_red
|
82
81
|
@output.puts " <script type=\"text/javascript\">makeRed('example_group_#{example_group_number}');</script>" unless @example_group_red
|
83
82
|
@example_group_red = true
|
84
83
|
move_progress
|
85
|
-
@output.puts " <dd class=\"example #{
|
84
|
+
@output.puts " <dd class=\"example #{exception.pending_fixed? ? 'pending_fixed' : 'failed'}\">"
|
86
85
|
@output.puts " <span class=\"failed_spec_name\">#{h(example.description)}</span>"
|
86
|
+
@output.puts " <span class=\"duration\">#{sprintf('%.5f', example.execution_result[:run_time])}s</span>"
|
87
87
|
@output.puts " <div class=\"failure\" id=\"failure_#{@failed_examples.size}\">"
|
88
88
|
@output.puts " <div class=\"message\"><pre>#{h(exception.message)}</pre></div>" unless exception.nil?
|
89
89
|
@output.puts " <div class=\"backtrace\"><pre>#{format_backtrace(exception.backtrace, example).join("\n")}</pre></div>" if exception
|
@@ -142,7 +142,7 @@ module RSpec
|
|
142
142
|
totals << "#{failure_count} failure#{'s' unless failure_count == 1}"
|
143
143
|
totals << ", #{pending_count} pending" if pending_count > 0
|
144
144
|
end
|
145
|
-
@output.puts "<script type=\"text/javascript\">document.getElementById('duration').innerHTML = \"Finished in <strong>#{duration} seconds</strong>\";</script>"
|
145
|
+
@output.puts "<script type=\"text/javascript\">document.getElementById('duration').innerHTML = \"Finished in <strong>#{sprintf("%.5f", duration)} seconds</strong>\";</script>"
|
146
146
|
@output.puts "<script type=\"text/javascript\">document.getElementById('totals').innerHTML = \"#{totals}\";</script>"
|
147
147
|
@output.puts "</div>"
|
148
148
|
@output.puts "</div>"
|
@@ -354,6 +354,12 @@ dd {
|
|
354
354
|
padding: 3px 3px 3px 18px;
|
355
355
|
}
|
356
356
|
|
357
|
+
dd .duration {
|
358
|
+
padding-left: 5px;
|
359
|
+
text-align: right;
|
360
|
+
right: 0px;
|
361
|
+
float:right;
|
362
|
+
}
|
357
363
|
|
358
364
|
dd.example.passed {
|
359
365
|
border-left: 5px solid #65C400;
|
data/lib/rspec/core/hooks.rb
CHANGED
@@ -87,7 +87,7 @@ module RSpec
|
|
87
87
|
|
88
88
|
class AroundHooks < HookCollection; end
|
89
89
|
|
90
|
-
# @
|
90
|
+
# @private
|
91
91
|
def hooks
|
92
92
|
@hooks ||= {
|
93
93
|
:around => { :each => AroundHooks.new },
|
@@ -99,10 +99,15 @@ module RSpec
|
|
99
99
|
# @api public
|
100
100
|
# @overload before(&block)
|
101
101
|
# @overload before(scope, &block)
|
102
|
-
# @overload before(scope,
|
103
|
-
# @overload before(
|
102
|
+
# @overload before(scope, conditions, &block)
|
103
|
+
# @overload before(conditions, &block)
|
104
|
+
#
|
104
105
|
# @param [Symbol] scope `:each`, `:all`, or `:suite` (defaults to `:each`)
|
105
|
-
# @param [Hash]
|
106
|
+
# @param [Hash] conditions
|
107
|
+
# constrains this hook to examples matching these conditions e.g.
|
108
|
+
# `before(:each, :ui => true) { ... }` will only run with examples or
|
109
|
+
# groups declared with `:ui => true`.
|
110
|
+
#
|
106
111
|
# @see #after
|
107
112
|
# @see #around
|
108
113
|
# @see ExampleGroup
|
@@ -122,12 +127,6 @@ module RSpec
|
|
122
127
|
# Instance variables declared in `before(:each)` or `before(:all)` are
|
123
128
|
# accessible within each example.
|
124
129
|
#
|
125
|
-
# ### Exceptions
|
126
|
-
#
|
127
|
-
# When an exception is raised in a `before` block, RSpec skips any
|
128
|
-
# subsequent `before` blocks and the example, but runs all of the
|
129
|
-
# `after(:each)` and `after(:all)` hooks.
|
130
|
-
#
|
131
130
|
# ### Order
|
132
131
|
#
|
133
132
|
# `before` hooks are stored in three scopes, which are run in order:
|
@@ -135,16 +134,55 @@ module RSpec
|
|
135
134
|
# different places: `RSpec.configure`, a parent group, the current group.
|
136
135
|
# They are run in the following order:
|
137
136
|
#
|
138
|
-
# before(:
|
139
|
-
# before(:all) declared in
|
140
|
-
# before(:all) declared in
|
141
|
-
# before(:
|
142
|
-
# before(:each) declared in
|
143
|
-
# before(:each) declared in
|
137
|
+
# before(:suite) # declared in RSpec.configure
|
138
|
+
# before(:all) # declared in RSpec.configure
|
139
|
+
# before(:all) # declared in a parent group
|
140
|
+
# before(:all) # declared in the current group
|
141
|
+
# before(:each) # declared in RSpec.configure
|
142
|
+
# before(:each) # declared in a parent group
|
143
|
+
# before(:each) # declared in the current group
|
144
144
|
#
|
145
145
|
# If more than one `before` is declared within any one scope, they are run
|
146
146
|
# in the order in which they are declared.
|
147
147
|
#
|
148
|
+
# ### Conditions
|
149
|
+
#
|
150
|
+
# When you add a conditions hash to `before(:each)` or `before(:all)`,
|
151
|
+
# RSpec will only apply that hook to groups or examples that match the
|
152
|
+
# conditions. e.g.
|
153
|
+
#
|
154
|
+
# RSpec.configure do |config|
|
155
|
+
# config.before(:each, :authorized => true) do
|
156
|
+
# log_in_as :authorized_user
|
157
|
+
# end
|
158
|
+
# end
|
159
|
+
#
|
160
|
+
# describe Something, :authorized => true do
|
161
|
+
# # the before hook will run in before each example in this group
|
162
|
+
# end
|
163
|
+
#
|
164
|
+
# describe SomethingElse do
|
165
|
+
# it "does something", :authorized => true do
|
166
|
+
# # the before hook will run before this example
|
167
|
+
# end
|
168
|
+
#
|
169
|
+
# it "does something else" do
|
170
|
+
# # the hook will not run before this example
|
171
|
+
# end
|
172
|
+
# end
|
173
|
+
#
|
174
|
+
# ### Warning: `before(:suite, :with => :conditions)`
|
175
|
+
#
|
176
|
+
# The conditions hash is used to match against specific examples. Since
|
177
|
+
# `before(:suite)` is not run in relation to any specific example or
|
178
|
+
# group, conditions passed along with `:suite` are effectively ignored.
|
179
|
+
#
|
180
|
+
# ### Exceptions
|
181
|
+
#
|
182
|
+
# When an exception is raised in a `before` block, RSpec skips any
|
183
|
+
# subsequent `before` blocks and the example, but runs all of the
|
184
|
+
# `after(:each)` and `after(:all)` hooks.
|
185
|
+
#
|
148
186
|
# ### Warning: implicit before blocks
|
149
187
|
#
|
150
188
|
# `before` hooks can also be declared in shared contexts which get
|
@@ -203,8 +241,8 @@ module RSpec
|
|
203
241
|
# before(:all) do
|
204
242
|
# File.open(file_to_parse, 'w') do |f|
|
205
243
|
# f.write <<-CONTENT
|
206
|
-
#
|
207
|
-
#
|
244
|
+
# stuff in the file
|
245
|
+
# CONTENT
|
208
246
|
# end
|
209
247
|
# end
|
210
248
|
#
|
@@ -224,10 +262,15 @@ module RSpec
|
|
224
262
|
# @api public
|
225
263
|
# @overload after(&block)
|
226
264
|
# @overload after(scope, &block)
|
227
|
-
# @overload after(scope,
|
228
|
-
# @overload after(
|
265
|
+
# @overload after(scope, conditions, &block)
|
266
|
+
# @overload after(conditions, &block)
|
267
|
+
#
|
229
268
|
# @param [Symbol] scope `:each`, `:all`, or `:suite` (defaults to `:each`)
|
230
|
-
# @param [Hash]
|
269
|
+
# @param [Hash] conditions
|
270
|
+
# constrains this hook to examples matching these conditions e.g.
|
271
|
+
# `after(:each, :ui => true) { ... }` will only run with examples or
|
272
|
+
# groups declared with `:ui => true`.
|
273
|
+
#
|
231
274
|
# @see #before
|
232
275
|
# @see #around
|
233
276
|
# @see ExampleGroup
|
@@ -254,12 +297,12 @@ module RSpec
|
|
254
297
|
# different places: `RSpec.configure`, a parent group, the current group.
|
255
298
|
# They are run in the following order:
|
256
299
|
#
|
257
|
-
# after(:each) declared in the current group
|
258
|
-
# after(:each) declared in a parent group
|
259
|
-
# after(:each) declared in RSpec.configure
|
260
|
-
# after(:all) declared in the current group
|
261
|
-
# after(:all) declared in a parent group
|
262
|
-
# after(:all) declared in RSpec.configure
|
300
|
+
# after(:each) # declared in the current group
|
301
|
+
# after(:each) # declared in a parent group
|
302
|
+
# after(:each) # declared in RSpec.configure
|
303
|
+
# after(:all) # declared in the current group
|
304
|
+
# after(:all) # declared in a parent group
|
305
|
+
# after(:all) # declared in RSpec.configure
|
263
306
|
#
|
264
307
|
# This is the reverse of the order in which `before` hooks are run.
|
265
308
|
# Similarly, if more than one `after` is declared within any one scope,
|
@@ -272,12 +315,28 @@ module RSpec
|
|
272
315
|
# @api public
|
273
316
|
# @overload around(&block)
|
274
317
|
# @overload around(scope, &block)
|
275
|
-
# @overload around(scope,
|
276
|
-
# @overload around(
|
318
|
+
# @overload around(scope, conditions, &block)
|
319
|
+
# @overload around(conditions, &block)
|
320
|
+
#
|
277
321
|
# @param [Symbol] scope `:each` (defaults to `:each`)
|
278
|
-
#
|
322
|
+
# present for syntax parity with `before` and `after`, but `:each` is
|
323
|
+
# the only supported value.
|
324
|
+
#
|
325
|
+
# @param [Hash] conditions
|
326
|
+
# constrains this hook to examples matching these conditions e.g.
|
327
|
+
# `around(:each, :ui => true) { ... }` will only run with examples or
|
328
|
+
# groups declared with `:ui => true`.
|
329
|
+
#
|
279
330
|
# @yield [Example] the example to run
|
280
331
|
#
|
332
|
+
# @note the syntax of `around` is similar to that of `before` and `after`
|
333
|
+
# but the semantics are quite different. `before` and `after` hooks are
|
334
|
+
# run in the context of of the examples with which they are associated,
|
335
|
+
# whereas `around` hooks are actually responsible for running the
|
336
|
+
# examples. Consequently, `around` hooks do not have direct access to
|
337
|
+
# resources that are made available within the examples and their
|
338
|
+
# associated `before` and `after` hooks.
|
339
|
+
#
|
281
340
|
# @note `:each` is the only supported scope.
|
282
341
|
#
|
283
342
|
# Declare a block of code, parts of which will be run before and parts
|
@@ -302,26 +361,26 @@ module RSpec
|
|
302
361
|
hooks[:around][scope] << AroundHook.new(options, &block)
|
303
362
|
end
|
304
363
|
|
305
|
-
# @
|
364
|
+
# @private
|
306
365
|
# Runs all of the blocks stored with the hook in the context of the
|
307
366
|
# example. If no example is provided, just calls the hook directly.
|
308
367
|
def run_hook(hook, scope, example_group_instance=nil)
|
309
368
|
hooks[hook][scope].run_all(example_group_instance)
|
310
369
|
end
|
311
370
|
|
312
|
-
# @
|
371
|
+
# @private
|
313
372
|
# Just like run_hook, except it removes the blocks as it evalutes them,
|
314
373
|
# ensuring that they will only be run once.
|
315
374
|
def run_hook!(hook, scope, example_group_instance)
|
316
375
|
hooks[hook][scope].run_all!(example_group_instance)
|
317
376
|
end
|
318
377
|
|
319
|
-
# @
|
378
|
+
# @private
|
320
379
|
def run_hook_filtered(hook, scope, group, example_group_instance, example = nil)
|
321
380
|
find_hook(hook, scope, group, example).run_all(example_group_instance)
|
322
381
|
end
|
323
382
|
|
324
|
-
# @
|
383
|
+
# @private
|
325
384
|
def find_hook(hook, scope, example_group_class, example = nil)
|
326
385
|
found_hooks = hooks[hook][scope].find_hooks_for(example || example_group_class)
|
327
386
|
|