rspec-core 3.0.0.beta2 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.yardopts +1 -0
  5. data/Changelog.md +297 -57
  6. data/README.md +16 -13
  7. data/lib/rspec/core.rb +55 -84
  8. data/lib/rspec/core/backport_random.rb +35 -3
  9. data/lib/rspec/core/backtrace_formatter.rb +4 -13
  10. data/lib/rspec/core/configuration.rb +330 -114
  11. data/lib/rspec/core/configuration_options.rb +38 -22
  12. data/lib/rspec/core/drb.rb +111 -0
  13. data/lib/rspec/core/dsl.rb +8 -2
  14. data/lib/rspec/core/example.rb +203 -94
  15. data/lib/rspec/core/example_group.rb +344 -316
  16. data/lib/rspec/core/filter_manager.rb +135 -90
  17. data/lib/rspec/core/flat_map.rb +1 -0
  18. data/lib/rspec/core/formatters.rb +50 -14
  19. data/lib/rspec/core/formatters/base_formatter.rb +32 -138
  20. data/lib/rspec/core/formatters/base_text_formatter.rb +32 -253
  21. data/lib/rspec/core/formatters/console_codes.rb +65 -0
  22. data/lib/rspec/core/formatters/deprecation_formatter.rb +24 -15
  23. data/lib/rspec/core/formatters/documentation_formatter.rb +7 -10
  24. data/lib/rspec/core/formatters/helpers.rb +15 -9
  25. data/lib/rspec/core/formatters/html_formatter.rb +17 -16
  26. data/lib/rspec/core/formatters/html_printer.rb +1 -0
  27. data/lib/rspec/core/formatters/json_formatter.rb +18 -20
  28. data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
  29. data/lib/rspec/core/formatters/progress_formatter.rb +6 -7
  30. data/lib/rspec/core/formatters/snippet_extractor.rb +8 -6
  31. data/lib/rspec/core/hooks.rb +131 -125
  32. data/lib/rspec/core/memoized_helpers.rb +31 -26
  33. data/lib/rspec/core/metadata.rb +277 -184
  34. data/lib/rspec/core/metadata_filter.rb +86 -0
  35. data/lib/rspec/core/minitest_assertions_adapter.rb +28 -0
  36. data/lib/rspec/core/mocking_adapters/flexmock.rb +1 -1
  37. data/lib/rspec/core/mocking_adapters/mocha.rb +1 -1
  38. data/lib/rspec/core/mocking_adapters/null.rb +1 -1
  39. data/lib/rspec/core/mocking_adapters/rr.rb +2 -1
  40. data/lib/rspec/core/mocking_adapters/rspec.rb +1 -1
  41. data/lib/rspec/core/notifications.rb +435 -24
  42. data/lib/rspec/core/option_parser.rb +16 -25
  43. data/lib/rspec/core/ordering.rb +3 -1
  44. data/lib/rspec/core/pending.rb +57 -33
  45. data/lib/rspec/core/project_initializer.rb +2 -0
  46. data/lib/rspec/core/project_initializer/spec_helper.rb +5 -4
  47. data/lib/rspec/core/rake_task.rb +45 -20
  48. data/lib/rspec/core/reporter.rb +50 -22
  49. data/lib/rspec/core/ruby_project.rb +1 -0
  50. data/lib/rspec/core/runner.rb +93 -39
  51. data/lib/rspec/core/shared_context.rb +7 -5
  52. data/lib/rspec/core/shared_example_group.rb +85 -77
  53. data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
  54. data/lib/rspec/core/version.rb +3 -1
  55. data/lib/rspec/core/warnings.rb +35 -17
  56. data/lib/rspec/core/world.rb +57 -5
  57. metadata +56 -369
  58. metadata.gz.sig +3 -3
  59. data/features/README.md +0 -13
  60. data/features/Upgrade.md +0 -352
  61. data/features/command_line/README.md +0 -25
  62. data/features/command_line/dry_run.feature +0 -29
  63. data/features/command_line/example_name_option.feature +0 -97
  64. data/features/command_line/exit_status.feature +0 -82
  65. data/features/command_line/fail_fast.feature +0 -26
  66. data/features/command_line/format_option.feature +0 -75
  67. data/features/command_line/init.feature +0 -57
  68. data/features/command_line/line_number_appended_to_path.feature +0 -140
  69. data/features/command_line/line_number_option.feature +0 -58
  70. data/features/command_line/order.feature +0 -25
  71. data/features/command_line/pattern_option.feature +0 -49
  72. data/features/command_line/rake_task.feature +0 -122
  73. data/features/command_line/randomization.feature +0 -63
  74. data/features/command_line/require_option.feature +0 -43
  75. data/features/command_line/ruby.feature +0 -23
  76. data/features/command_line/tag.feature +0 -98
  77. data/features/command_line/warnings_option.feature +0 -29
  78. data/features/configuration/alias_example_to.feature +0 -39
  79. data/features/configuration/backtrace_exclusion_patterns.feature +0 -105
  80. data/features/configuration/custom_settings.feature +0 -84
  81. data/features/configuration/default_path.feature +0 -38
  82. data/features/configuration/deprecation_stream.feature +0 -58
  83. data/features/configuration/enable_global_dsl.feature +0 -54
  84. data/features/configuration/fail_fast.feature +0 -77
  85. data/features/configuration/failure_exit_code.feature +0 -36
  86. data/features/configuration/order_and_seed.feature +0 -3
  87. data/features/configuration/output_stream.feature +0 -24
  88. data/features/configuration/overriding_global_ordering.feature +0 -93
  89. data/features/configuration/pattern.feature +0 -38
  90. data/features/configuration/profile.feature +0 -220
  91. data/features/configuration/read_options_from_file.feature +0 -90
  92. data/features/configuration/run_all_when_everything_filtered.feature +0 -76
  93. data/features/example_groups/aliasing.feature +0 -48
  94. data/features/example_groups/basic_structure.feature +0 -55
  95. data/features/example_groups/shared_context.feature +0 -74
  96. data/features/example_groups/shared_examples.feature +0 -286
  97. data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
  98. data/features/filtering/exclusion_filters.feature +0 -135
  99. data/features/filtering/if_and_unless.feature +0 -138
  100. data/features/filtering/inclusion_filters.feature +0 -101
  101. data/features/formatters/configurable_colors.feature +0 -31
  102. data/features/formatters/custom_formatter.feature +0 -68
  103. data/features/formatters/json_formatter.feature +0 -30
  104. data/features/formatters/regression_tests.feature +0 -95
  105. data/features/formatters/text_formatter.feature +0 -46
  106. data/features/helper_methods/arbitrary_methods.feature +0 -40
  107. data/features/helper_methods/let.feature +0 -50
  108. data/features/helper_methods/modules.feature +0 -146
  109. data/features/hooks/around_hooks.feature +0 -344
  110. data/features/hooks/before_and_after_hooks.feature +0 -427
  111. data/features/hooks/filtering.feature +0 -232
  112. data/features/metadata/current_example.feature +0 -56
  113. data/features/metadata/described_class.feature +0 -17
  114. data/features/metadata/user_defined.feature +0 -100
  115. data/features/mock_framework_integration/use_any_framework.feature +0 -106
  116. data/features/mock_framework_integration/use_flexmock.feature +0 -94
  117. data/features/mock_framework_integration/use_mocha.feature +0 -95
  118. data/features/mock_framework_integration/use_rr.feature +0 -96
  119. data/features/mock_framework_integration/use_rspec.feature +0 -95
  120. data/features/pending_and_skipped_examples/README.md +0 -3
  121. data/features/pending_and_skipped_examples/pending_examples.feature +0 -118
  122. data/features/pending_and_skipped_examples/skipped_examples.feature +0 -106
  123. data/features/spec_files/arbitrary_file_suffix.feature +0 -13
  124. data/features/step_definitions/additional_cli_steps.rb +0 -83
  125. data/features/subject/explicit_subject.feature +0 -101
  126. data/features/subject/implicit_subject.feature +0 -63
  127. data/features/subject/one_liner_syntax.feature +0 -71
  128. data/features/support/env.rb +0 -21
  129. data/features/support/require_expect_syntax_in_aruba_specs.rb +0 -16
  130. data/features/support/rubinius.rb +0 -6
  131. data/lib/rspec/core/command_line.rb +0 -35
  132. data/lib/rspec/core/drb_command_line.rb +0 -26
  133. data/lib/rspec/core/drb_options.rb +0 -87
  134. data/lib/rspec/core/formatters/legacy_formatter.rb +0 -227
  135. data/lib/rspec/core/shared_example_group/collection.rb +0 -27
  136. data/spec/command_line/order_spec.rb +0 -211
  137. data/spec/rspec/core/backtrace_formatter_spec.rb +0 -230
  138. data/spec/rspec/core/command_line_spec.rb +0 -112
  139. data/spec/rspec/core/command_line_spec_output.txt +0 -0
  140. data/spec/rspec/core/configuration_options_spec.rb +0 -409
  141. data/spec/rspec/core/configuration_spec.rb +0 -1479
  142. data/spec/rspec/core/drb_command_line_spec.rb +0 -102
  143. data/spec/rspec/core/drb_options_spec.rb +0 -193
  144. data/spec/rspec/core/dsl_spec.rb +0 -88
  145. data/spec/rspec/core/example_group_spec.rb +0 -1533
  146. data/spec/rspec/core/example_spec.rb +0 -642
  147. data/spec/rspec/core/filter_manager_spec.rb +0 -229
  148. data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -64
  149. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -303
  150. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -208
  151. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -75
  152. data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
  153. data/spec/rspec/core/formatters/html_formatted-2.1.0.html +0 -392
  154. data/spec/rspec/core/formatters/html_formatted.html +0 -397
  155. data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -122
  156. data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -206
  157. data/spec/rspec/core/formatters/legacy_formatter_spec.rb +0 -137
  158. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -43
  159. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
  160. data/spec/rspec/core/formatters_spec.rb +0 -120
  161. data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
  162. data/spec/rspec/core/hooks_spec.rb +0 -294
  163. data/spec/rspec/core/memoized_helpers_spec.rb +0 -495
  164. data/spec/rspec/core/metadata_spec.rb +0 -491
  165. data/spec/rspec/core/option_parser_spec.rb +0 -262
  166. data/spec/rspec/core/ordering_spec.rb +0 -102
  167. data/spec/rspec/core/pending_example_spec.rb +0 -117
  168. data/spec/rspec/core/pending_spec.rb +0 -8
  169. data/spec/rspec/core/project_initializer_spec.rb +0 -73
  170. data/spec/rspec/core/rake_task_spec.rb +0 -146
  171. data/spec/rspec/core/random_spec.rb +0 -47
  172. data/spec/rspec/core/reporter_spec.rb +0 -155
  173. data/spec/rspec/core/resources/a_bar.rb +0 -0
  174. data/spec/rspec/core/resources/a_foo.rb +0 -0
  175. data/spec/rspec/core/resources/a_spec.rb +0 -1
  176. data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
  177. data/spec/rspec/core/resources/formatter_specs.rb +0 -58
  178. data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
  179. data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
  180. data/spec/rspec/core/ruby_project_spec.rb +0 -26
  181. data/spec/rspec/core/runner_spec.rb +0 -151
  182. data/spec/rspec/core/shared_context_spec.rb +0 -102
  183. data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -57
  184. data/spec/rspec/core/shared_example_group_spec.rb +0 -114
  185. data/spec/rspec/core/warnings_spec.rb +0 -29
  186. data/spec/rspec/core/world_spec.rb +0 -142
  187. data/spec/rspec/core_spec.rb +0 -91
  188. data/spec/spec_helper.rb +0 -160
  189. data/spec/support/config_options_helper.rb +0 -13
  190. data/spec/support/formatter_support.rb +0 -83
  191. data/spec/support/helper_methods.rb +0 -26
  192. data/spec/support/isolate_load_path_mutation.rb +0 -5
  193. data/spec/support/isolated_directory.rb +0 -10
  194. data/spec/support/isolated_home_directory.rb +0 -16
  195. data/spec/support/legacy_formatter_using_sub_classing_example.rb +0 -87
  196. data/spec/support/matchers.rb +0 -85
  197. data/spec/support/mathn_integration_support.rb +0 -12
  198. data/spec/support/old_style_formatter_example.rb +0 -69
  199. data/spec/support/shared_example_groups.rb +0 -13
  200. data/spec/support/spec_files.rb +0 -44
  201. data/spec/support/stderr_splitter.rb +0 -36
@@ -1,17 +1,28 @@
1
1
  module RSpec
2
2
  module Core
3
+ # Provides `before`, `after` and `around` hooks as a means of
4
+ # supporting common setup and teardown. This module is extended
5
+ # onto {ExampleGroup}, making the methods available from any `describe`
6
+ # or `context` block and included in {Configuration}, making them
7
+ # available off of the configuration object to define global setup
8
+ # or teardown logic.
3
9
  module Hooks
4
10
  # @api public
11
+ #
5
12
  # @overload before(&block)
6
13
  # @overload before(scope, &block)
14
+ # @param scope [Symbol] `:example`, `:context`, or `:suite` (defaults to `:example`)
7
15
  # @overload before(scope, conditions, &block)
16
+ # @param scope [Symbol] `:example`, `:context`, or `:suite` (defaults to `:example`)
17
+ # @param conditions [Hash]
18
+ # constrains this hook to examples matching these conditions e.g.
19
+ # `before(:example, :ui => true) { ... }` will only run with examples or
20
+ # groups declared with `:ui => true`.
8
21
  # @overload before(conditions, &block)
9
- #
10
- # @param [Symbol] scope `:each`, `:all`, or `:suite` (defaults to `:each`)
11
- # @param [Hash] conditions
12
- # constrains this hook to examples matching these conditions e.g.
13
- # `before(:each, :ui => true) { ... }` will only run with examples or
14
- # groups declared with `:ui => true`.
22
+ # @param conditions [Hash]
23
+ # constrains this hook to examples matching these conditions e.g.
24
+ # `before(:example, :ui => true) { ... }` will only run with examples or
25
+ # groups declared with `:ui => true`.
15
26
  #
16
27
  # @see #after
17
28
  # @see #around
@@ -20,43 +31,43 @@ module RSpec
20
31
  # @see SharedExampleGroup
21
32
  # @see Configuration
22
33
  #
23
- # Declare a block of code to be run before each example (using `:each`)
24
- # or once before any example (using `:all`). These are usually declared
34
+ # Declare a block of code to be run before each example (using `:example`)
35
+ # or once before any example (using `:context`). These are usually declared
25
36
  # directly in the {ExampleGroup} to which they apply, but they can also
26
37
  # be shared across multiple groups.
27
38
  #
28
39
  # You can also use `before(:suite)` to run a block of code before any
29
40
  # example groups are run. This should be declared in {RSpec.configure}
30
41
  #
31
- # Instance variables declared in `before(:each)` or `before(:all)` are
42
+ # Instance variables declared in `before(:example)` or `before(:context)` are
32
43
  # accessible within each example.
33
44
  #
34
45
  # ### Order
35
46
  #
36
47
  # `before` hooks are stored in three scopes, which are run in order:
37
- # `:suite`, `:all`, and `:each`. They can also be declared in several
48
+ # `:suite`, `:context`, and `:example`. They can also be declared in several
38
49
  # different places: `RSpec.configure`, a parent group, the current group.
39
50
  # They are run in the following order:
40
51
  #
41
- # before(:suite) # declared in RSpec.configure
42
- # before(:all) # declared in RSpec.configure
43
- # before(:all) # declared in a parent group
44
- # before(:all) # declared in the current group
45
- # before(:each) # declared in RSpec.configure
46
- # before(:each) # declared in a parent group
47
- # before(:each) # declared in the current group
52
+ # before(:suite) # declared in RSpec.configure
53
+ # before(:context) # declared in RSpec.configure
54
+ # before(:context) # declared in a parent group
55
+ # before(:context) # declared in the current group
56
+ # before(:example) # declared in RSpec.configure
57
+ # before(:example) # declared in a parent group
58
+ # before(:example) # declared in the current group
48
59
  #
49
60
  # If more than one `before` is declared within any one scope, they are run
50
61
  # in the order in which they are declared.
51
62
  #
52
63
  # ### Conditions
53
64
  #
54
- # When you add a conditions hash to `before(:each)` or `before(:all)`,
65
+ # When you add a conditions hash to `before(:example)` or `before(:context)`,
55
66
  # RSpec will only apply that hook to groups or examples that match the
56
67
  # conditions. e.g.
57
68
  #
58
69
  # RSpec.configure do |config|
59
- # config.before(:each, :authorized => true) do
70
+ # config.before(:example, :authorized => true) do
60
71
  # log_in_as :authorized_user
61
72
  # end
62
73
  # end
@@ -85,7 +96,7 @@ module RSpec
85
96
  #
86
97
  # When an exception is raised in a `before` block, RSpec skips any
87
98
  # subsequent `before` blocks and the example, but runs all of the
88
- # `after(:each)` and `after(:all)` hooks.
99
+ # `after(:example)` and `after(:context)` hooks.
89
100
  #
90
101
  # ### Warning: implicit before blocks
91
102
  #
@@ -96,20 +107,20 @@ module RSpec
96
107
  # before block depends on state that is prepared in another before block
97
108
  # that gets run later.
98
109
  #
99
- # ### Warning: `before(:all)`
110
+ # ### Warning: `before(:context)`
100
111
  #
101
- # It is very tempting to use `before(:all)` to speed things up, but we
112
+ # It is very tempting to use `before(:context)` to speed things up, but we
102
113
  # recommend that you avoid this as there are a number of gotchas, as well
103
114
  # as things that simply don't work.
104
115
  #
105
116
  # #### context
106
117
  #
107
- # `before(:all)` is run in an example that is generated to provide group
118
+ # `before(:context)` is run in an example that is generated to provide group
108
119
  # context for the block.
109
120
  #
110
121
  # #### instance variables
111
122
  #
112
- # Instance variables declared in `before(:all)` are shared across all the
123
+ # Instance variables declared in `before(:context)` are shared across all the
113
124
  # examples in the group. This means that each example can change the
114
125
  # state of a shared object, resulting in an ordering dependency that can
115
126
  # make it difficult to reason about failures.
@@ -117,7 +128,7 @@ module RSpec
117
128
  # #### unsupported rspec constructs
118
129
  #
119
130
  # RSpec has several constructs that reset state between each example
120
- # automatically. These are not intended for use from within `before(:all)`:
131
+ # automatically. These are not intended for use from within `before(:context)`:
121
132
  #
122
133
  # * `let` declarations
123
134
  # * `subject` declarations
@@ -129,17 +140,17 @@ module RSpec
129
140
  # ActiveRecord) are typically designed around the idea of setting up
130
141
  # before an example, running that one example, and then tearing down.
131
142
  # This means that mocks and stubs can (sometimes) be declared in
132
- # `before(:all)`, but get torn down before the first real example is ever
143
+ # `before(:context)`, but get torn down before the first real example is ever
133
144
  # run.
134
145
  #
135
- # You _can_ create database-backed model objects in a `before(:all)` in
146
+ # You _can_ create database-backed model objects in a `before(:context)` in
136
147
  # rspec-rails, but it will not be wrapped in a transaction for you, so
137
- # you are on your own to clean up in an `after(:all)` block.
148
+ # you are on your own to clean up in an `after(:context)` block.
138
149
  #
139
- # @example before(:each) declared in an {ExampleGroup}
150
+ # @example before(:example) declared in an {ExampleGroup}
140
151
  #
141
152
  # describe Thing do
142
- # before(:each) do
153
+ # before(:example) do
143
154
  # @thing = Thing.new
144
155
  # end
145
156
  #
@@ -148,10 +159,10 @@ module RSpec
148
159
  # end
149
160
  # end
150
161
  #
151
- # @example before(:all) declared in an {ExampleGroup}
162
+ # @example before(:context) declared in an {ExampleGroup}
152
163
  #
153
164
  # describe Parser do
154
- # before(:all) do
165
+ # before(:context) do
155
166
  # File.open(file_to_parse, 'w') do |f|
156
167
  # f.write <<-CONTENT
157
168
  # stuff in the file
@@ -163,10 +174,13 @@ module RSpec
163
174
  # Parser.parse(file_to_parse)
164
175
  # end
165
176
  #
166
- # after(:all) do
177
+ # after(:context) do
167
178
  # File.delete(file_to_parse)
168
179
  # end
169
180
  # end
181
+ #
182
+ # @note The `:example` and `:context` scopes are also available as
183
+ # `:each` and `:all`, respectively. Use whichever you prefer.
170
184
  def before(*args, &block)
171
185
  hooks.register :append, :before, *args, &block
172
186
  end
@@ -174,9 +188,9 @@ module RSpec
174
188
  alias_method :append_before, :before
175
189
 
176
190
  # Adds `block` to the front of the list of `before` blocks in the same
177
- # scope (`:each`, `:all`, or `:suite`).
191
+ # scope (`:example`, `:context`, or `:suite`).
178
192
  #
179
- # See #before for scoping semantics.
193
+ # See {#before} for scoping semantics.
180
194
  def prepend_before(*args, &block)
181
195
  hooks.register :prepend, :before, *args, &block
182
196
  end
@@ -184,14 +198,18 @@ module RSpec
184
198
  # @api public
185
199
  # @overload after(&block)
186
200
  # @overload after(scope, &block)
201
+ # @param scope [Symbol] `:example`, `:context`, or `:suite` (defaults to `:example`)
187
202
  # @overload after(scope, conditions, &block)
203
+ # @param scope [Symbol] `:example`, `:context`, or `:suite` (defaults to `:example`)
204
+ # @param conditions [Hash]
205
+ # constrains this hook to examples matching these conditions e.g.
206
+ # `after(:example, :ui => true) { ... }` will only run with examples or
207
+ # groups declared with `:ui => true`.
188
208
  # @overload after(conditions, &block)
189
- #
190
- # @param [Symbol] scope `:each`, `:all`, or `:suite` (defaults to `:each`)
191
- # @param [Hash] conditions
192
- # constrains this hook to examples matching these conditions e.g.
193
- # `after(:each, :ui => true) { ... }` will only run with examples or
194
- # groups declared with `:ui => true`.
209
+ # @param conditions [Hash]
210
+ # constrains this hook to examples matching these conditions e.g.
211
+ # `after(:example, :ui => true) { ... }` will only run with examples or
212
+ # groups declared with `:ui => true`.
195
213
  #
196
214
  # @see #before
197
215
  # @see #around
@@ -200,10 +218,9 @@ module RSpec
200
218
  # @see SharedExampleGroup
201
219
  # @see Configuration
202
220
  #
203
- # Declare a block of code to be run after each example (using `:each`) or
204
- # once after all examples (using `:all`). See
205
- # [#before](Hooks#before-instance_method) for more information about
206
- # ordering.
221
+ # Declare a block of code to be run after each example (using `:example`) or
222
+ # once after all examples n the context (using `:context`). See {#before} for
223
+ # more information about ordering.
207
224
  #
208
225
  # ### Exceptions
209
226
  #
@@ -215,20 +232,24 @@ module RSpec
215
232
  # ### Order
216
233
  #
217
234
  # `after` hooks are stored in three scopes, which are run in order:
218
- # `:each`, `:all`, and `:suite`. They can also be declared in several
235
+ # `:example`, `:context`, and `:suite`. They can also be declared in several
219
236
  # different places: `RSpec.configure`, a parent group, the current group.
220
237
  # They are run in the following order:
221
238
  #
222
- # after(:each) # declared in the current group
223
- # after(:each) # declared in a parent group
224
- # after(:each) # declared in RSpec.configure
225
- # after(:all) # declared in the current group
226
- # after(:all) # declared in a parent group
227
- # after(:all) # declared in RSpec.configure
239
+ # after(:example) # declared in the current group
240
+ # after(:example) # declared in a parent group
241
+ # after(:example) # declared in RSpec.configure
242
+ # after(:context) # declared in the current group
243
+ # after(:context) # declared in a parent group
244
+ # after(:context) # declared in RSpec.configure
245
+ # after(:suite) # declared in RSpec.configure
228
246
  #
229
247
  # This is the reverse of the order in which `before` hooks are run.
230
248
  # Similarly, if more than one `after` is declared within any one scope,
231
249
  # they are run in reverse order of that in which they are declared.
250
+ #
251
+ # @note The `:example` and `:context` scopes are also available as
252
+ # `:each` and `:all`, respectively. Use whichever you prefer.
232
253
  def after(*args, &block)
233
254
  hooks.register :prepend, :after, *args, &block
234
255
  end
@@ -236,9 +257,9 @@ module RSpec
236
257
  alias_method :prepend_after, :after
237
258
 
238
259
  # Adds `block` to the back of the list of `after` blocks in the same
239
- # scope (`:each`, `:all`, or `:suite`).
260
+ # scope (`:example`, `:context`, or `:suite`).
240
261
  #
241
- # See #after for scoping semantics.
262
+ # See {#after} for scoping semantics.
242
263
  def append_after(*args, &block)
243
264
  hooks.register :append, :after, *args, &block
244
265
  end
@@ -246,17 +267,22 @@ module RSpec
246
267
  # @api public
247
268
  # @overload around(&block)
248
269
  # @overload around(scope, &block)
270
+ # @param scope [Symbol] `:example` (defaults to `:example`)
271
+ # present for syntax parity with `before` and `after`, but
272
+ # `:example`/`:each` is the only supported value.
249
273
  # @overload around(scope, conditions, &block)
274
+ # @param scope [Symbol] `:example` (defaults to `:example`)
275
+ # present for syntax parity with `before` and `after`, but
276
+ # `:example`/`:each` is the only supported value.
277
+ # @param conditions [Hash]
278
+ # constrains this hook to examples matching these conditions e.g.
279
+ # `around(:example, :ui => true) { ... }` will only run with examples or
280
+ # groups declared with `:ui => true`.
250
281
  # @overload around(conditions, &block)
251
- #
252
- # @param [Symbol] scope `:each` (defaults to `:each`)
253
- # present for syntax parity with `before` and `after`, but `:each` is
254
- # the only supported value.
255
- #
256
- # @param [Hash] conditions
257
- # constrains this hook to examples matching these conditions e.g.
258
- # `around(:each, :ui => true) { ... }` will only run with examples or
259
- # groups declared with `:ui => true`.
282
+ # @param conditions [Hash]
283
+ # constrains this hook to examples matching these conditions e.g.
284
+ # `around(:example, :ui => true) { ... }` will only run with examples or
285
+ # groups declared with `:ui => true`.
260
286
  #
261
287
  # @yield [Example] the example to run
262
288
  #
@@ -268,12 +294,12 @@ module RSpec
268
294
  # resources that are made available within the examples and their
269
295
  # associated `before` and `after` hooks.
270
296
  #
271
- # @note `:each` is the only supported scope.
297
+ # @note `:example`/`:each` is the only supported scope.
272
298
  #
273
299
  # Declare a block of code, parts of which will be run before and parts
274
300
  # after the example. It is your responsibility to run the example:
275
301
  #
276
- # around(:each) do |ex|
302
+ # around(:example) do |ex|
277
303
  # # do some stuff before
278
304
  # ex.run
279
305
  # # do some stuff after
@@ -284,20 +310,20 @@ module RSpec
284
310
  # that manage their own setup and teardown using a block or proc syntax,
285
311
  # e.g.
286
312
  #
287
- # around(:each) {|ex| Database.transaction(&ex)}
288
- # around(:each) {|ex| FakeFS(&ex)}
313
+ # around(:example) {|ex| Database.transaction(&ex)}
314
+ # around(:example) {|ex| FakeFS(&ex)}
289
315
  #
290
316
  def around(*args, &block)
291
317
  hooks.register :prepend, :around, *args, &block
292
318
  end
293
319
 
294
- # @api private
320
+ # @private
295
321
  # Holds the various registered hooks.
296
322
  def hooks
297
323
  @hooks ||= HookCollections.new(self,
298
- :around => { :each => AroundHookCollection.new },
299
- :before => { :each => HookCollection.new, :all => HookCollection.new, :suite => HookCollection.new },
300
- :after => { :each => HookCollection.new, :all => HookCollection.new, :suite => HookCollection.new }
324
+ :around => { :example => AroundHookCollection.new },
325
+ :before => { :example => HookCollection.new, :context => HookCollection.new, :suite => HookCollection.new },
326
+ :after => { :example => HookCollection.new, :context => HookCollection.new, :suite => HookCollection.new }
301
327
  )
302
328
  end
303
329
 
@@ -322,10 +348,6 @@ module RSpec
322
348
  def run(example)
323
349
  example.instance_exec(example, &block)
324
350
  end
325
-
326
- def display_name
327
- "before hook"
328
- end
329
351
  end
330
352
 
331
353
  # @private
@@ -333,38 +355,26 @@ module RSpec
333
355
  def run(example)
334
356
  example.instance_exec_with_rescue("in an after hook", &block)
335
357
  end
336
-
337
- def display_name
338
- "after hook"
339
- end
340
358
  end
341
359
 
342
360
  # @private
343
- class AfterAllHook < Hook
361
+ class AfterContextHook < Hook
344
362
  def run(example)
345
363
  example.instance_exec(example, &block)
346
364
  rescue Exception => e
347
365
  # TODO: come up with a better solution for this.
348
366
  RSpec.configuration.reporter.message <<-EOS
349
367
 
350
- An error occurred in an after(:all) hook.
368
+ An error occurred in an `after(:context)` hook.
351
369
  #{e.class}: #{e.message}
352
370
  occurred at #{e.backtrace.first}
353
371
 
354
372
  EOS
355
373
  end
356
-
357
- def display_name
358
- "after(:all) hook"
359
- end
360
374
  end
361
375
 
362
376
  # @private
363
- class AroundHook < Hook
364
- def display_name
365
- "around hook"
366
- end
367
- end
377
+ AroundHook = Hook
368
378
 
369
379
  # @private
370
380
  class BaseHookCollection
@@ -447,17 +457,17 @@ EOS
447
457
  end
448
458
 
449
459
  def register_globals(host, globals)
450
- process(host, globals, :before, :each)
451
- process(host, globals, :after, :each)
452
- process(host, globals, :around, :each)
460
+ process(host, globals, :before, :example)
461
+ process(host, globals, :after, :example)
462
+ process(host, globals, :around, :example)
453
463
 
454
- process(host, globals, :before, :all)
455
- process(host, globals, :after, :all)
464
+ process(host, globals, :before, :context)
465
+ process(host, globals, :after, :context)
456
466
  end
457
467
 
458
- def around_each_hooks_for(example, initial_procsy=nil)
468
+ def around_example_hooks_for(example, initial_procsy=nil)
459
469
  AroundHookCollection.new(FlatMap.flat_map(@owner.parent_groups) do |a|
460
- a.hooks[:around][:each]
470
+ a.hooks[:around][:example]
461
471
  end).for(example, initial_procsy)
462
472
  end
463
473
 
@@ -470,18 +480,14 @@ EOS
470
480
  #
471
481
  # Runs all of the blocks stored with the hook in the context of the
472
482
  # example. If no example is provided, just calls the hook directly.
473
- def run(hook, scope, example_or_group=ExampleGroup.new, initial_procsy=nil)
483
+ def run(hook, scope, example_or_group, initial_procsy=nil)
474
484
  return if RSpec.configuration.dry_run?
475
-
476
485
  find_hook(hook, scope, example_or_group, initial_procsy).run
477
486
  end
478
487
 
479
- SCOPES = [:each, :all, :suite]
488
+ SCOPES = [:example, :context, :suite]
480
489
 
481
- SCOPE_ALIASES = {
482
- :example => :each,
483
- :context => :all,
484
- }
490
+ SCOPE_ALIASES = { :each => :example, :all => :context }
485
491
 
486
492
  HOOK_TYPES = {
487
493
  :before => Hash.new { BeforeHook },
@@ -489,13 +495,13 @@ EOS
489
495
  :around => Hash.new { AroundHook }
490
496
  }
491
497
 
492
- HOOK_TYPES[:after][:all] = AfterAllHook
498
+ HOOK_TYPES[:after][:context] = AfterContextHook
493
499
 
494
500
  private
495
501
 
496
502
  def process(host, globals, position, scope)
497
503
  globals[position][scope].each do |hook|
498
- next unless scope == :each || hook.options_apply?(host)
504
+ next unless scope == :example || hook.options_apply?(host)
499
505
  next if host.parent_groups.any? {|a| a.hooks[position][scope].include?(hook)}
500
506
  self[position][scope] << hook
501
507
  end
@@ -512,7 +518,7 @@ EOS
512
518
  error_message = "You must explicitly give a scope (#{SCOPES.join(", ")}) or scope alias (#{SCOPE_ALIASES.keys.join(", ")}) when using symbols as metadata for a hook."
513
519
  raise ArgumentError.new error_message
514
520
  else
515
- :each
521
+ :example
516
522
  end
517
523
  end
518
524
 
@@ -528,38 +534,38 @@ EOS
528
534
 
529
535
  def find_hook(hook, scope, example_or_group, initial_procsy)
530
536
  case [hook, scope]
531
- when [:before, :all]
532
- before_all_hooks_for(example_or_group)
533
- when [:after, :all]
534
- after_all_hooks_for(example_or_group)
535
- when [:around, :each]
536
- around_each_hooks_for(example_or_group, initial_procsy)
537
- when [:before, :each]
538
- before_each_hooks_for(example_or_group)
539
- when [:after, :each]
540
- after_each_hooks_for(example_or_group)
537
+ when [:before, :context]
538
+ before_context_hooks_for(example_or_group)
539
+ when [:after, :context]
540
+ after_context_hooks_for(example_or_group)
541
+ when [:around, :example]
542
+ around_example_hooks_for(example_or_group, initial_procsy)
543
+ when [:before, :example]
544
+ before_example_hooks_for(example_or_group)
545
+ when [:after, :example]
546
+ after_example_hooks_for(example_or_group)
541
547
  when [:before, :suite], [:after, :suite]
542
548
  self[hook][:suite].with(example_or_group)
543
549
  end
544
550
  end
545
551
 
546
- def before_all_hooks_for(group)
547
- GroupHookCollection.new(self[:before][:all]).for(group)
552
+ def before_context_hooks_for(group)
553
+ GroupHookCollection.new(self[:before][:context]).for(group)
548
554
  end
549
555
 
550
- def after_all_hooks_for(group)
551
- GroupHookCollection.new(self[:after][:all]).for(group)
556
+ def after_context_hooks_for(group)
557
+ GroupHookCollection.new(self[:after][:context]).for(group)
552
558
  end
553
559
 
554
- def before_each_hooks_for(example)
560
+ def before_example_hooks_for(example)
555
561
  HookCollection.new(FlatMap.flat_map(@owner.parent_groups.reverse) do |a|
556
- a.hooks[:before][:each]
562
+ a.hooks[:before][:example]
557
563
  end).for(example)
558
564
  end
559
565
 
560
- def after_each_hooks_for(example)
566
+ def after_example_hooks_for(example)
561
567
  HookCollection.new(FlatMap.flat_map(@owner.parent_groups) do |a|
562
- a.hooks[:after][:each]
568
+ a.hooks[:after][:example]
563
569
  end).for(example)
564
570
  end
565
571
  end