rspec-core 2.11.1 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +1 -1
  4. data/.yardopts +3 -1
  5. data/Changelog.md +1814 -29
  6. data/{License.txt → LICENSE.md} +6 -4
  7. data/README.md +197 -48
  8. data/exe/rspec +2 -23
  9. data/lib/rspec/autorun.rb +1 -0
  10. data/lib/rspec/core/backtrace_formatter.rb +65 -0
  11. data/lib/rspec/core/bisect/coordinator.rb +62 -0
  12. data/lib/rspec/core/bisect/example_minimizer.rb +173 -0
  13. data/lib/rspec/core/bisect/fork_runner.rb +138 -0
  14. data/lib/rspec/core/bisect/server.rb +61 -0
  15. data/lib/rspec/core/bisect/shell_command.rb +126 -0
  16. data/lib/rspec/core/bisect/shell_runner.rb +73 -0
  17. data/lib/rspec/core/bisect/utilities.rb +69 -0
  18. data/lib/rspec/core/configuration.rb +1846 -407
  19. data/lib/rspec/core/configuration_options.rb +154 -50
  20. data/lib/rspec/core/did_you_mean.rb +46 -0
  21. data/lib/rspec/core/drb.rb +120 -0
  22. data/lib/rspec/core/dsl.rb +90 -18
  23. data/lib/rspec/core/example.rb +488 -152
  24. data/lib/rspec/core/example_group.rb +733 -294
  25. data/lib/rspec/core/example_status_persister.rb +235 -0
  26. data/lib/rspec/core/filter_manager.rb +175 -147
  27. data/lib/rspec/core/flat_map.rb +20 -0
  28. data/lib/rspec/core/formatters/base_bisect_formatter.rb +45 -0
  29. data/lib/rspec/core/formatters/base_formatter.rb +32 -130
  30. data/lib/rspec/core/formatters/base_text_formatter.rb +62 -190
  31. data/lib/rspec/core/formatters/bisect_drb_formatter.rb +29 -0
  32. data/lib/rspec/core/formatters/bisect_progress_formatter.rb +157 -0
  33. data/lib/rspec/core/formatters/console_codes.rb +76 -0
  34. data/lib/rspec/core/formatters/deprecation_formatter.rb +223 -0
  35. data/lib/rspec/core/formatters/documentation_formatter.rb +62 -27
  36. data/lib/rspec/core/formatters/exception_presenter.rb +521 -0
  37. data/lib/rspec/core/formatters/failure_list_formatter.rb +23 -0
  38. data/lib/rspec/core/formatters/fallback_message_formatter.rb +28 -0
  39. data/lib/rspec/core/formatters/helpers.rb +93 -14
  40. data/lib/rspec/core/formatters/html_formatter.rb +104 -415
  41. data/lib/rspec/core/formatters/html_printer.rb +414 -0
  42. data/lib/rspec/core/formatters/html_snippet_extractor.rb +120 -0
  43. data/lib/rspec/core/formatters/json_formatter.rb +102 -0
  44. data/lib/rspec/core/formatters/profile_formatter.rb +68 -0
  45. data/lib/rspec/core/formatters/progress_formatter.rb +12 -15
  46. data/lib/rspec/core/formatters/protocol.rb +182 -0
  47. data/lib/rspec/core/formatters/snippet_extractor.rb +115 -39
  48. data/lib/rspec/core/formatters/syntax_highlighter.rb +91 -0
  49. data/lib/rspec/core/formatters.rb +279 -0
  50. data/lib/rspec/core/hooks.rb +451 -300
  51. data/lib/rspec/core/invocations.rb +87 -0
  52. data/lib/rspec/core/memoized_helpers.rb +580 -0
  53. data/lib/rspec/core/metadata.rb +395 -173
  54. data/lib/rspec/core/metadata_filter.rb +255 -0
  55. data/lib/rspec/core/minitest_assertions_adapter.rb +31 -0
  56. data/lib/rspec/core/mocking_adapters/flexmock.rb +31 -0
  57. data/lib/rspec/core/mocking_adapters/mocha.rb +57 -0
  58. data/lib/rspec/core/mocking_adapters/null.rb +14 -0
  59. data/lib/rspec/core/mocking_adapters/rr.rb +31 -0
  60. data/lib/rspec/core/mocking_adapters/rspec.rb +32 -0
  61. data/lib/rspec/core/notifications.rb +521 -0
  62. data/lib/rspec/core/option_parser.rb +208 -64
  63. data/lib/rspec/core/ordering.rb +169 -0
  64. data/lib/rspec/core/output_wrapper.rb +29 -0
  65. data/lib/rspec/core/pending.rb +115 -59
  66. data/lib/rspec/core/profiler.rb +34 -0
  67. data/lib/rspec/core/project_initializer/.rspec +1 -0
  68. data/lib/rspec/core/project_initializer/spec/spec_helper.rb +98 -0
  69. data/lib/rspec/core/project_initializer.rb +26 -65
  70. data/lib/rspec/core/rake_task.rb +140 -131
  71. data/lib/rspec/core/reporter.rb +207 -44
  72. data/lib/rspec/core/ruby_project.rb +15 -6
  73. data/lib/rspec/core/runner.rb +180 -44
  74. data/lib/rspec/core/sandbox.rb +37 -0
  75. data/lib/rspec/core/set.rb +54 -0
  76. data/lib/rspec/core/shared_context.rb +25 -19
  77. data/lib/rspec/core/shared_example_group.rb +229 -54
  78. data/lib/rspec/core/shell_escape.rb +49 -0
  79. data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
  80. data/lib/rspec/core/version.rb +3 -1
  81. data/lib/rspec/core/warnings.rb +40 -0
  82. data/lib/rspec/core/world.rb +208 -49
  83. data/lib/rspec/core.rb +166 -80
  84. data.tar.gz.sig +0 -0
  85. metadata +230 -445
  86. metadata.gz.sig +0 -0
  87. data/exe/autospec +0 -13
  88. data/features/Autotest.md +0 -38
  89. data/features/README.md +0 -17
  90. data/features/Upgrade.md +0 -364
  91. data/features/command_line/README.md +0 -28
  92. data/features/command_line/example_name_option.feature +0 -101
  93. data/features/command_line/exit_status.feature +0 -83
  94. data/features/command_line/format_option.feature +0 -81
  95. data/features/command_line/init.feature +0 -18
  96. data/features/command_line/line_number_appended_to_path.feature +0 -140
  97. data/features/command_line/line_number_option.feature +0 -58
  98. data/features/command_line/order.feature +0 -29
  99. data/features/command_line/pattern_option.feature +0 -31
  100. data/features/command_line/rake_task.feature +0 -68
  101. data/features/command_line/ruby.feature +0 -22
  102. data/features/command_line/tag.feature +0 -91
  103. data/features/configuration/alias_example_to.feature +0 -48
  104. data/features/configuration/custom_settings.feature +0 -84
  105. data/features/configuration/default_path.feature +0 -38
  106. data/features/configuration/fail_fast.feature +0 -77
  107. data/features/configuration/read_options_from_file.feature +0 -87
  108. data/features/example_groups/basic_structure.feature +0 -55
  109. data/features/example_groups/shared_context.feature +0 -74
  110. data/features/example_groups/shared_examples.feature +0 -204
  111. data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
  112. data/features/filtering/exclusion_filters.feature +0 -139
  113. data/features/filtering/if_and_unless.feature +0 -168
  114. data/features/filtering/inclusion_filters.feature +0 -105
  115. data/features/filtering/run_all_when_everything_filtered.feature +0 -46
  116. data/features/formatters/custom_formatter.feature +0 -36
  117. data/features/formatters/text_formatter.feature +0 -46
  118. data/features/helper_methods/arbitrary_methods.feature +0 -40
  119. data/features/helper_methods/let.feature +0 -50
  120. data/features/helper_methods/modules.feature +0 -149
  121. data/features/hooks/around_hooks.feature +0 -343
  122. data/features/hooks/before_and_after_hooks.feature +0 -423
  123. data/features/hooks/filtering.feature +0 -234
  124. data/features/metadata/current_example.feature +0 -17
  125. data/features/metadata/described_class.feature +0 -17
  126. data/features/metadata/user_defined.feature +0 -113
  127. data/features/mock_framework_integration/use_any_framework.feature +0 -106
  128. data/features/mock_framework_integration/use_flexmock.feature +0 -96
  129. data/features/mock_framework_integration/use_mocha.feature +0 -97
  130. data/features/mock_framework_integration/use_rr.feature +0 -98
  131. data/features/mock_framework_integration/use_rspec.feature +0 -97
  132. data/features/pending/pending_examples.feature +0 -229
  133. data/features/spec_files/arbitrary_file_suffix.feature +0 -13
  134. data/features/step_definitions/additional_cli_steps.rb +0 -30
  135. data/features/subject/attribute_of_subject.feature +0 -124
  136. data/features/subject/explicit_subject.feature +0 -82
  137. data/features/subject/implicit_receiver.feature +0 -29
  138. data/features/subject/implicit_subject.feature +0 -63
  139. data/features/support/env.rb +0 -12
  140. data/lib/autotest/discover.rb +0 -1
  141. data/lib/autotest/rspec2.rb +0 -73
  142. data/lib/rspec/core/backward_compatibility.rb +0 -65
  143. data/lib/rspec/core/command_line.rb +0 -36
  144. data/lib/rspec/core/deprecation.rb +0 -36
  145. data/lib/rspec/core/drb_command_line.rb +0 -26
  146. data/lib/rspec/core/drb_options.rb +0 -87
  147. data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
  148. data/lib/rspec/core/extensions/kernel.rb +0 -9
  149. data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
  150. data/lib/rspec/core/extensions/ordered.rb +0 -21
  151. data/lib/rspec/core/extensions.rb +0 -4
  152. data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
  153. data/lib/rspec/core/let.rb +0 -110
  154. data/lib/rspec/core/load_path.rb +0 -3
  155. data/lib/rspec/core/metadata_hash_builder.rb +0 -97
  156. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
  157. data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
  158. data/lib/rspec/core/mocking/with_mocha.rb +0 -29
  159. data/lib/rspec/core/mocking/with_rr.rb +0 -27
  160. data/lib/rspec/core/mocking/with_rspec.rb +0 -23
  161. data/lib/rspec/core/subject.rb +0 -219
  162. data/spec/autotest/discover_spec.rb +0 -19
  163. data/spec/autotest/failed_results_re_spec.rb +0 -45
  164. data/spec/autotest/rspec_spec.rb +0 -123
  165. data/spec/command_line/order_spec.rb +0 -137
  166. data/spec/rspec/core/command_line_spec.rb +0 -108
  167. data/spec/rspec/core/command_line_spec_output.txt +0 -0
  168. data/spec/rspec/core/configuration_options_spec.rb +0 -377
  169. data/spec/rspec/core/configuration_spec.rb +0 -1196
  170. data/spec/rspec/core/deprecations_spec.rb +0 -66
  171. data/spec/rspec/core/drb_command_line_spec.rb +0 -108
  172. data/spec/rspec/core/drb_options_spec.rb +0 -180
  173. data/spec/rspec/core/dsl_spec.rb +0 -17
  174. data/spec/rspec/core/example_group_spec.rb +0 -1098
  175. data/spec/rspec/core/example_spec.rb +0 -370
  176. data/spec/rspec/core/filter_manager_spec.rb +0 -256
  177. data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -80
  178. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -363
  179. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -88
  180. data/spec/rspec/core/formatters/helpers_spec.rb +0 -66
  181. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +0 -410
  182. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +0 -409
  183. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +0 -416
  184. data/spec/rspec/core/formatters/html_formatted-1.9.3.html +0 -416
  185. data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -82
  186. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
  187. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -18
  188. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +0 -410
  189. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +0 -409
  190. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +0 -416
  191. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +0 -416
  192. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -83
  193. data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
  194. data/spec/rspec/core/hooks_spec.rb +0 -250
  195. data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
  196. data/spec/rspec/core/let_spec.rb +0 -55
  197. data/spec/rspec/core/metadata_spec.rb +0 -447
  198. data/spec/rspec/core/option_parser_spec.rb +0 -166
  199. data/spec/rspec/core/pending_example_spec.rb +0 -220
  200. data/spec/rspec/core/project_initializer_spec.rb +0 -130
  201. data/spec/rspec/core/rake_task_spec.rb +0 -138
  202. data/spec/rspec/core/reporter_spec.rb +0 -103
  203. data/spec/rspec/core/resources/a_bar.rb +0 -0
  204. data/spec/rspec/core/resources/a_foo.rb +0 -0
  205. data/spec/rspec/core/resources/a_spec.rb +0 -1
  206. data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
  207. data/spec/rspec/core/resources/formatter_specs.rb +0 -60
  208. data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
  209. data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
  210. data/spec/rspec/core/ruby_project_spec.rb +0 -24
  211. data/spec/rspec/core/runner_spec.rb +0 -81
  212. data/spec/rspec/core/shared_context_spec.rb +0 -67
  213. data/spec/rspec/core/shared_example_group_spec.rb +0 -84
  214. data/spec/rspec/core/subject_spec.rb +0 -244
  215. data/spec/rspec/core/world_spec.rb +0 -144
  216. data/spec/rspec/core_spec.rb +0 -35
  217. data/spec/spec_helper.rb +0 -98
  218. data/spec/support/config_options_helper.rb +0 -24
  219. data/spec/support/helper_methods.rb +0 -5
  220. data/spec/support/matchers.rb +0 -65
  221. data/spec/support/shared_example_groups.rb +0 -41
  222. data/spec/support/spec_files.rb +0 -44
@@ -1,423 +0,0 @@
1
- Feature: before and after hooks
2
-
3
- Use `before` and `after` hooks to execute arbitrary code before and/or
4
- after the body of an example is run:
5
-
6
- before(:each) # run before each example
7
- before(:all) # run one time only, before all of the examples in a group
8
-
9
- after(:each) # run after each example
10
- after(:all) # run one time only, after all of the examples in a group
11
-
12
- Before and after blocks are called in the following order:
13
-
14
- before suite
15
- before all
16
- before each
17
- after each
18
- after all
19
- after suite
20
-
21
- `before` and `after` hooks can be defined directly in the example groups they
22
- should run in, or in a global RSpec.configure block.
23
-
24
- Scenario: define before(:each) block
25
- Given a file named "before_each_spec.rb" with:
26
- """
27
- require "rspec/expectations"
28
-
29
- class Thing
30
- def widgets
31
- @widgets ||= []
32
- end
33
- end
34
-
35
- describe Thing do
36
- before(:each) do
37
- @thing = Thing.new
38
- end
39
-
40
- describe "initialized in before(:each)" do
41
- it "has 0 widgets" do
42
- @thing.should have(0).widgets
43
- end
44
-
45
- it "can get accept new widgets" do
46
- @thing.widgets << Object.new
47
- end
48
-
49
- it "does not share state across examples" do
50
- @thing.should have(0).widgets
51
- end
52
- end
53
- end
54
- """
55
- When I run `rspec before_each_spec.rb`
56
- Then the examples should all pass
57
-
58
- Scenario: define before(:all) block in example group
59
- Given a file named "before_all_spec.rb" with:
60
- """
61
- require "rspec/expectations"
62
-
63
- class Thing
64
- def widgets
65
- @widgets ||= []
66
- end
67
- end
68
-
69
- describe Thing do
70
- before(:all) do
71
- @thing = Thing.new
72
- end
73
-
74
- describe "initialized in before(:all)" do
75
- it "has 0 widgets" do
76
- @thing.should have(0).widgets
77
- end
78
-
79
- it "can get accept new widgets" do
80
- @thing.widgets << Object.new
81
- end
82
-
83
- it "shares state across examples" do
84
- @thing.should have(1).widgets
85
- end
86
- end
87
- end
88
- """
89
- When I run `rspec before_all_spec.rb`
90
- Then the examples should all pass
91
-
92
- When I run `rspec before_all_spec.rb:15`
93
- Then the examples should all pass
94
-
95
- Scenario: failure in before(:all) block
96
- Given a file named "before_all_spec.rb" with:
97
- """
98
- describe "an error in before(:all)" do
99
- before(:all) do
100
- raise "oops"
101
- end
102
-
103
- it "fails this example" do
104
- end
105
-
106
- it "fails this example, too" do
107
- end
108
-
109
- after(:all) do
110
- puts "after all ran"
111
- end
112
-
113
- describe "nested group" do
114
- it "fails this third example" do
115
- end
116
-
117
- it "fails this fourth example" do
118
- end
119
-
120
- describe "yet another level deep" do
121
- it "fails this last example" do
122
- end
123
- end
124
- end
125
- end
126
- """
127
- When I run `rspec before_all_spec.rb --format documentation`
128
- Then the output should contain "5 examples, 5 failures"
129
- And the output should contain:
130
- """
131
- an error in before(:all)
132
- fails this example (FAILED - 1)
133
- fails this example, too (FAILED - 2)
134
- nested group
135
- fails this third example (FAILED - 3)
136
- fails this fourth example (FAILED - 4)
137
- yet another level deep
138
- fails this last example (FAILED - 5)
139
- after all ran
140
- """
141
-
142
- When I run `rspec before_all_spec.rb:9 --format documentation`
143
- Then the output should contain "1 example, 1 failure"
144
- And the output should contain:
145
- """
146
- an error in before(:all)
147
- fails this example, too (FAILED - 1)
148
- """
149
-
150
- Scenario: failure in after(:all) block
151
- Given a file named "after_all_spec.rb" with:
152
- """
153
- describe "an error in after(:all)" do
154
- after(:all) do
155
- raise StandardError.new("Boom!")
156
- end
157
-
158
- it "passes this example" do
159
- end
160
-
161
- it "passes this example, too" do
162
- end
163
- end
164
- """
165
- When I run `rspec after_all_spec.rb`
166
- Then the examples should all pass
167
- And the output should contain:
168
- """
169
- An error occurred in an after(:all) hook.
170
- StandardError: Boom!
171
- """
172
-
173
- Scenario: define before and after blocks in configuration
174
- Given a file named "befores_in_configuration_spec.rb" with:
175
- """
176
- require "rspec/expectations"
177
-
178
- RSpec.configure do |config|
179
- config.before(:each) do
180
- @before_each = "before each"
181
- end
182
- config.before(:all) do
183
- @before_all = "before all"
184
- end
185
- end
186
-
187
- describe "stuff in before blocks" do
188
- describe "with :all" do
189
- it "should be available in the example" do
190
- @before_all.should eq("before all")
191
- end
192
- end
193
- describe "with :each" do
194
- it "should be available in the example" do
195
- @before_each.should eq("before each")
196
- end
197
- end
198
- end
199
- """
200
- When I run `rspec befores_in_configuration_spec.rb`
201
- Then the examples should all pass
202
-
203
- Scenario: before/after blocks are run in order
204
- Given a file named "ensure_block_order_spec.rb" with:
205
- """
206
- require "rspec/expectations"
207
-
208
- describe "before and after callbacks" do
209
- before(:all) do
210
- puts "before all"
211
- end
212
-
213
- before(:each) do
214
- puts "before each"
215
- end
216
-
217
- after(:each) do
218
- puts "after each"
219
- end
220
-
221
- after(:all) do
222
- puts "after all"
223
- end
224
-
225
- it "gets run in order" do
226
-
227
- end
228
- end
229
- """
230
- When I run `rspec --format progress ensure_block_order_spec.rb`
231
- Then the output should contain:
232
- """
233
- before all
234
- before each
235
- after each
236
- .after all
237
- """
238
-
239
- Scenario: before/after blocks defined in config are run in order
240
- Given a file named "configuration_spec.rb" with:
241
- """
242
- require "rspec/expectations"
243
-
244
- RSpec.configure do |config|
245
- config.before(:suite) do
246
- puts "before suite"
247
- end
248
-
249
- config.before(:all) do
250
- puts "before all"
251
- end
252
-
253
- config.before(:each) do
254
- puts "before each"
255
- end
256
-
257
- config.after(:each) do
258
- puts "after each"
259
- end
260
-
261
- config.after(:all) do
262
- puts "after all"
263
- end
264
-
265
- config.after(:suite) do
266
- puts "after suite"
267
- end
268
- end
269
-
270
- describe "ignore" do
271
- example "ignore" do
272
- end
273
- end
274
- """
275
- When I run `rspec --format progress configuration_spec.rb`
276
- Then the output should contain:
277
- """
278
- before suite
279
- before all
280
- before each
281
- after each
282
- .after all
283
- after suite
284
- """
285
-
286
- Scenario: before/after all blocks are run once
287
- Given a file named "before_and_after_all_spec.rb" with:
288
- """
289
- describe "before and after callbacks" do
290
- before(:all) do
291
- puts "outer before all"
292
- end
293
-
294
- example "in outer group" do
295
- end
296
-
297
- after(:all) do
298
- puts "outer after all"
299
- end
300
-
301
- describe "nested group" do
302
- before(:all) do
303
- puts "inner before all"
304
- end
305
-
306
- example "in nested group" do
307
- end
308
-
309
- after(:all) do
310
- puts "inner after all"
311
- end
312
- end
313
-
314
- end
315
- """
316
- When I run `rspec --format progress before_and_after_all_spec.rb`
317
- Then the examples should all pass
318
- And the output should contain:
319
- """
320
- outer before all
321
- .inner before all
322
- .inner after all
323
- outer after all
324
- """
325
-
326
- When I run `rspec --format progress before_and_after_all_spec.rb:14`
327
- Then the examples should all pass
328
- And the output should contain:
329
- """
330
- outer before all
331
- inner before all
332
- .inner after all
333
- outer after all
334
- """
335
-
336
- When I run `rspec --format progress before_and_after_all_spec.rb:6`
337
- Then the examples should all pass
338
- And the output should contain:
339
- """
340
- outer before all
341
- .outer after all
342
- """
343
-
344
- Scenario: nested examples have access to state set in outer before(:all)
345
- Given a file named "before_all_spec.rb" with:
346
- """
347
- describe "something" do
348
- before :all do
349
- @value = 123
350
- end
351
-
352
- describe "nested" do
353
- it "access state set in before(:all)" do
354
- @value.should eq(123)
355
- end
356
-
357
- describe "nested more deeply" do
358
- it "access state set in before(:all)" do
359
- @value.should eq(123)
360
- end
361
- end
362
- end
363
-
364
- describe "nested in parallel" do
365
- it "access state set in before(:all)" do
366
- @value.should eq(123)
367
- end
368
- end
369
- end
370
- """
371
- When I run `rspec before_all_spec.rb`
372
- Then the examples should all pass
373
-
374
- Scenario: before/after all blocks have access to state
375
- Given a file named "before_and_after_all_spec.rb" with:
376
- """
377
- describe "before and after callbacks" do
378
- before(:all) do
379
- @outer_state = "set in outer before all"
380
- end
381
-
382
- example "in outer group" do
383
- @outer_state.should eq("set in outer before all")
384
- end
385
-
386
- describe "nested group" do
387
- before(:all) do
388
- @inner_state = "set in inner before all"
389
- end
390
-
391
- example "in nested group" do
392
- @outer_state.should eq("set in outer before all")
393
- @inner_state.should eq("set in inner before all")
394
- end
395
-
396
- after(:all) do
397
- @inner_state.should eq("set in inner before all")
398
- end
399
- end
400
-
401
- after(:all) do
402
- @outer_state.should eq("set in outer before all")
403
- end
404
- end
405
- """
406
- When I run `rspec before_and_after_all_spec.rb`
407
- Then the examples should all pass
408
-
409
- Scenario: exception in before(:each) is captured and reported as failure
410
- Given a file named "error_in_before_each_spec.rb" with:
411
- """
412
- describe "error in before(:each)" do
413
- before(:each) do
414
- raise "this error"
415
- end
416
-
417
- it "is reported as failure" do
418
- end
419
- end
420
- """
421
- When I run `rspec error_in_before_each_spec.rb`
422
- Then the output should contain "1 example, 1 failure"
423
- And the output should contain "this error"
@@ -1,234 +0,0 @@
1
- Feature: filters
2
-
3
- `before`, `after`, and `around` hooks defined in the block passed to
4
- `RSpec.configure` can be constrained to specific examples and/or groups using
5
- metadata as a filter.
6
-
7
- RSpec.configure do |c|
8
- c.before(:each, :type => :model) do
9
- end
10
- end
11
-
12
- describe "something", :type => :model do
13
- end
14
-
15
- You can specify metadata using only symbols if you set the
16
- `treat_symbols_as_metadata_keys_with_true_values` config option to `true`.
17
-
18
- Scenario: filter `before(:each)` hooks using arbitrary metadata
19
- Given a file named "filter_before_each_hooks_spec.rb" with:
20
- """
21
- RSpec.configure do |config|
22
- config.before(:each, :foo => :bar) do
23
- invoked_hooks << :before_each_foo_bar
24
- end
25
- end
26
-
27
- describe "a filtered before :each hook" do
28
- let(:invoked_hooks) { [] }
29
-
30
- describe "group without matching metadata" do
31
- it "does not run the hook" do
32
- invoked_hooks.should be_empty
33
- end
34
-
35
- it "runs the hook for an example with matching metadata", :foo => :bar do
36
- invoked_hooks.should == [:before_each_foo_bar]
37
- end
38
- end
39
-
40
- describe "group with matching metadata", :foo => :bar do
41
- it "runs the hook" do
42
- invoked_hooks.should == [:before_each_foo_bar]
43
- end
44
- end
45
- end
46
- """
47
- When I run `rspec filter_before_each_hooks_spec.rb`
48
- Then the examples should all pass
49
-
50
- Scenario: filter `after(:each)` hooks using arbitrary metadata
51
- Given a file named "filter_after_each_hooks_spec.rb" with:
52
- """
53
- RSpec.configure do |config|
54
- config.after(:each, :foo => :bar) do
55
- raise "boom!"
56
- end
57
- end
58
-
59
- describe "a filtered after :each hook" do
60
- describe "group without matching metadata" do
61
- it "does not run the hook" do
62
- # should pass
63
- end
64
-
65
- it "runs the hook for an example with matching metadata", :foo => :bar do
66
- # should fail
67
- end
68
- end
69
-
70
- describe "group with matching metadata", :foo => :bar do
71
- it "runs the hook" do
72
- # should fail
73
- end
74
- end
75
- end
76
- """
77
- When I run `rspec filter_after_each_hooks_spec.rb`
78
- Then the output should contain "3 examples, 2 failures"
79
-
80
- Scenario: filter around(:each) hooks using arbitrary metadata
81
- Given a file named "filter_around_each_hooks_spec.rb" with:
82
- """
83
- RSpec.configure do |config|
84
- config.around(:each, :foo => :bar) do |example|
85
- order << :before_around_each_foo_bar
86
- example.run
87
- order.should == [:before_around_each_foo_bar, :example]
88
- end
89
- end
90
-
91
- describe "a filtered around(:each) hook" do
92
- let(:order) { [] }
93
-
94
- describe "a group without matching metadata" do
95
- it "does not run the hook" do
96
- order.should be_empty
97
- end
98
-
99
- it "runs the hook for an example with matching metadata", :foo => :bar do
100
- order.should == [:before_around_each_foo_bar]
101
- order << :example
102
- end
103
- end
104
-
105
- describe "a group with matching metadata", :foo => :bar do
106
- it "runs the hook for an example with matching metadata", :foo => :bar do
107
- order.should == [:before_around_each_foo_bar]
108
- order << :example
109
- end
110
- end
111
- end
112
- """
113
- When I run `rspec filter_around_each_hooks_spec.rb`
114
- Then the examples should all pass
115
-
116
- Scenario: filter before(:all) hooks using arbitrary metadata
117
- Given a file named "filter_before_all_hooks_spec.rb" with:
118
- """
119
- RSpec.configure do |config|
120
- config.before(:all, :foo => :bar) { @hook = :before_all_foo_bar }
121
- end
122
-
123
- describe "a filtered before(:all) hook" do
124
- describe "a group without matching metadata" do
125
- it "does not run the hook" do
126
- @hook.should be_nil
127
- end
128
-
129
- describe "a nested subgroup with matching metadata", :foo => :bar do
130
- it "runs the hook" do
131
- @hook.should == :before_all_foo_bar
132
- end
133
- end
134
- end
135
-
136
- describe "a group with matching metadata", :foo => :bar do
137
- it "runs the hook" do
138
- @hook.should == :before_all_foo_bar
139
- end
140
-
141
- describe "a nested subgroup" do
142
- it "runs the hook" do
143
- @hook.should == :before_all_foo_bar
144
- end
145
- end
146
- end
147
- end
148
- """
149
- When I run `rspec filter_before_all_hooks_spec.rb`
150
- Then the examples should all pass
151
-
152
- Scenario: filter after(:all) hooks using arbitrary metadata
153
- Given a file named "filter_after_all_hooks_spec.rb" with:
154
- """
155
- example_msgs = []
156
-
157
- RSpec.configure do |config|
158
- config.after(:all, :foo => :bar) do
159
- puts "after :all"
160
- end
161
- end
162
-
163
- describe "a filtered after(:all) hook" do
164
- describe "a group without matching metadata" do
165
- it "does not run the hook" do
166
- puts "unfiltered"
167
- end
168
- end
169
-
170
- describe "a group with matching metadata", :foo => :bar do
171
- it "runs the hook" do
172
- puts "filtered 1"
173
- end
174
- end
175
-
176
- describe "another group without matching metadata" do
177
- describe "a nested subgroup with matching metadata", :foo => :bar do
178
- it "runs the hook" do
179
- puts "filtered 2"
180
- end
181
- end
182
- end
183
- end
184
- """
185
- When I run `rspec --format progress filter_after_all_hooks_spec.rb`
186
- Then the examples should all pass
187
- And the output should contain:
188
- """
189
- unfiltered
190
- .filtered 1
191
- .after :all
192
- filtered 2
193
- .after :all
194
- """
195
-
196
- Scenario: Use symbols as metadata
197
- Given a file named "less_verbose_metadata_filter.rb" with:
198
- """
199
- RSpec.configure do |c|
200
- c.treat_symbols_as_metadata_keys_with_true_values = true
201
- c.before(:each, :before_each) { puts "before each" }
202
- c.after(:each, :after_each) { puts "after each" }
203
- c.around(:each, :around_each) do |example|
204
- puts "around each (before)"
205
- example.run
206
- puts "around each (after)"
207
- end
208
- c.before(:all, :before_all) { puts "before all" }
209
- c.after(:all, :after_all) { puts "after all" }
210
- end
211
-
212
- describe "group 1", :before_all, :after_all do
213
- it("") { puts "example 1" }
214
- it("", :before_each) { puts "example 2" }
215
- it("", :after_each) { puts "example 3" }
216
- it("", :around_each) { puts "example 4" }
217
- end
218
- """
219
- When I run `rspec --format progress less_verbose_metadata_filter.rb`
220
- Then the examples should all pass
221
- And the output should contain:
222
- """
223
- before all
224
- example 1
225
- .before each
226
- example 2
227
- .example 3
228
- after each
229
- .around each (before)
230
- example 4
231
- around each (after)
232
- .after all
233
- """
234
-
@@ -1,17 +0,0 @@
1
- Feature: current example
2
-
3
- You can reference the example object, and access its metadata, using
4
- the `example` method within an example.
5
-
6
- Scenario: access the example object from within an example
7
- Given a file named "spec/example_spec.rb" with:
8
- """
9
- describe "an example" do
10
- it "knows itself as example" do
11
- example.description.should eq("knows itself as example")
12
- end
13
- end
14
- """
15
- When I run `rspec spec/example_spec.rb`
16
- Then the example should pass
17
-
@@ -1,17 +0,0 @@
1
- Feature: described class
2
-
3
- If the first argument to the outermost example group is a class, the class is
4
- exposed to each example via the described_class() method.
5
-
6
- Scenario: access the described class from the example
7
- Given a file named "spec/example_spec.rb" with:
8
- """
9
- describe Fixnum do
10
- it "is available as described_class" do
11
- described_class.should eq(Fixnum)
12
- end
13
- end
14
- """
15
- When I run `rspec spec/example_spec.rb`
16
- Then the example should pass
17
-