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,344 +0,0 @@
1
- Feature: around hooks
2
-
3
- Around hooks receive the example as a block argument, extended to behave like
4
- a proc. This lets you define code that should be executed before and after
5
- the example. Of course, you can do the same thing with before and after hooks,
6
- and it's often cleaner to do so.
7
-
8
- Where around hooks shine is when you want to run an example in a block. For
9
- example, if your database library offers a transaction method that receives
10
- a block, you can use an around hook as described in the first scenario:
11
-
12
- WARNING: around hooks do not share state with the example the way before and
13
- after hooks do. This means that you can not share instance variables between
14
- around hooks and examples.
15
-
16
- Also, mock frameworks are set up and torn down within the context of running
17
- the example, so you can not interact with them directly in around hooks.
18
-
19
- Scenario: use the example as a proc within the block passed to around()
20
- Given a file named "example_spec.rb" with:
21
- """ruby
22
- class Database
23
- def self.transaction
24
- puts "open transaction"
25
- yield
26
- puts "close transaction"
27
- end
28
- end
29
-
30
- describe "around filter" do
31
- around(:each) do |example|
32
- Database.transaction(&example)
33
- end
34
-
35
- it "gets run in order" do
36
- puts "run the example"
37
- end
38
- end
39
- """
40
- When I run `rspec example_spec.rb`
41
- Then the output should contain:
42
- """
43
- open transaction
44
- run the example
45
- close transaction
46
- """
47
-
48
- Scenario: invoke the example using run()
49
- Given a file named "example_spec.rb" with:
50
- """ruby
51
- describe "around hook" do
52
- around(:each) do |example|
53
- puts "around each before"
54
- example.run
55
- puts "around each after"
56
- end
57
-
58
- it "gets run in order" do
59
- puts "in the example"
60
- end
61
- end
62
- """
63
- When I run `rspec example_spec.rb`
64
- Then the output should contain:
65
- """
66
- around each before
67
- in the example
68
- around each after
69
- """
70
-
71
- Scenario: access the example metadata
72
- Given a file named "example_spec.rb" with:
73
- """ruby
74
- describe "something" do
75
- around(:each) do |example|
76
- puts example.metadata[:foo]
77
- example.run
78
- end
79
-
80
- it "does something", :foo => "this should show up in the output" do
81
- end
82
- end
83
- """
84
- When I run `rspec example_spec.rb`
85
- Then the output should contain "this should show up in the output"
86
-
87
- Scenario: define a global around hook
88
- Given a file named "example_spec.rb" with:
89
- """ruby
90
- RSpec.configure do |c|
91
- c.around(:each) do |example|
92
- puts "around each before"
93
- example.run
94
- puts "around each after"
95
- end
96
- end
97
-
98
- describe "around filter" do
99
- it "gets run in order" do
100
- puts "in the example"
101
- end
102
- end
103
- """
104
- When I run `rspec example_spec.rb`
105
- Then the output should contain:
106
- """
107
- around each before
108
- in the example
109
- around each after
110
- """
111
-
112
- Scenario: before/after(:each) hooks are wrapped by the around hook
113
- Given a file named "example_spec.rb" with:
114
- """ruby
115
- describe "around filter" do
116
- around(:each) do |example|
117
- puts "around each before"
118
- example.run
119
- puts "around each after"
120
- end
121
-
122
- before(:each) do
123
- puts "before each"
124
- end
125
-
126
- after(:each) do
127
- puts "after each"
128
- end
129
-
130
- it "gets run in order" do
131
- puts "in the example"
132
- end
133
- end
134
- """
135
- When I run `rspec example_spec.rb`
136
- Then the output should contain:
137
- """
138
- around each before
139
- before each
140
- in the example
141
- after each
142
- around each after
143
- """
144
-
145
- Scenario: before/after(:all) hooks are NOT wrapped by the around hook
146
- Given a file named "example_spec.rb" with:
147
- """ruby
148
- describe "around filter" do
149
- around(:each) do |example|
150
- puts "around each before"
151
- example.run
152
- puts "around each after"
153
- end
154
-
155
- before(:all) do
156
- puts "before all"
157
- end
158
-
159
- after(:all) do
160
- puts "after all"
161
- end
162
-
163
- it "gets run in order" do
164
- puts "in the example"
165
- end
166
- end
167
- """
168
- When I run `rspec --format progress example_spec.rb`
169
- Then the output should contain:
170
- """
171
- before all
172
- around each before
173
- in the example
174
- around each after
175
- .after all
176
- """
177
-
178
- Scenario: examples run by an around block are run in the configured context
179
- Given a file named "example_spec.rb" with:
180
- """ruby
181
- module IncludedInConfigureBlock
182
- def included_in_configure_block; true; end
183
- end
184
-
185
- RSpec.configure do |c|
186
- c.include IncludedInConfigureBlock
187
- end
188
-
189
- describe "around filter" do
190
- around(:each) do |example|
191
- example.run
192
- end
193
-
194
- it "runs the example in the correct context" do
195
- expect(included_in_configure_block).to be_truthy
196
- end
197
- end
198
- """
199
- When I run `rspec example_spec.rb`
200
- Then the output should contain "1 example, 0 failure"
201
-
202
- Scenario: implicitly pending examples are detected as Not yet implemented
203
- Given a file named "example_spec.rb" with:
204
- """ruby
205
- describe "implicit pending example" do
206
- around(:each) do |example|
207
- example.run
208
- end
209
-
210
- it "should be detected as Not yet implemented"
211
- end
212
- """
213
- When I run `rspec example_spec.rb`
214
- Then the output should contain "1 example, 0 failures, 1 pending"
215
- And the output should contain:
216
- """
217
- Pending:
218
- implicit pending example should be detected as Not yet implemented
219
- # Not yet implemented
220
- """
221
-
222
-
223
- Scenario: explicitly pending examples are detected as pending
224
- Given a file named "example_spec.rb" with:
225
- """ruby
226
- describe "explicit pending example" do
227
- around(:each) do |example|
228
- example.run
229
- end
230
-
231
- it "should be detected as pending" do
232
- pending
233
- fail
234
- end
235
- end
236
- """
237
- When I run `rspec example_spec.rb`
238
- Then the output should contain "1 example, 0 failures, 1 pending"
239
- And the output should contain:
240
- """
241
- explicit pending example should be detected as pending
242
- # No reason given
243
- """
244
-
245
- Scenario: multiple around hooks in the same scope
246
- Given a file named "example_spec.rb" with:
247
- """ruby
248
- describe "if there are multiple around hooks in the same scope" do
249
- around(:each) do |example|
250
- puts "first around hook before"
251
- example.run
252
- puts "first around hook after"
253
- end
254
-
255
- around(:each) do |example|
256
- puts "second around hook before"
257
- example.run
258
- puts "second around hook after"
259
- end
260
-
261
- it "they should all be run" do
262
- puts "in the example"
263
- expect(1).to eq(1)
264
- end
265
- end
266
- """
267
- When I run `rspec example_spec.rb`
268
- Then the output should contain "1 example, 0 failure"
269
- And the output should contain:
270
- """
271
- first around hook before
272
- second around hook before
273
- in the example
274
- second around hook after
275
- first around hook after
276
- """
277
-
278
- Scenario: around hooks in multiple scopes
279
- Given a file named "example_spec.rb" with:
280
- """ruby
281
- describe "if there are around hooks in an outer scope" do
282
- around(:each) do |example|
283
- puts "first outermost around hook before"
284
- example.run
285
- puts "first outermost around hook after"
286
- end
287
-
288
- around(:each) do |example|
289
- puts "second outermost around hook before"
290
- example.run
291
- puts "second outermost around hook after"
292
- end
293
-
294
- describe "outer scope" do
295
- around(:each) do |example|
296
- puts "first outer around hook before"
297
- example.run
298
- puts "first outer around hook after"
299
- end
300
-
301
- around(:each) do |example|
302
- puts "second outer around hook before"
303
- example.run
304
- puts "second outer around hook after"
305
- end
306
-
307
- describe "inner scope" do
308
- around(:each) do |example|
309
- puts "first inner around hook before"
310
- example.run
311
- puts "first inner around hook after"
312
- end
313
-
314
- around(:each) do |example|
315
- puts "second inner around hook before"
316
- example.run
317
- puts "second inner around hook after"
318
- end
319
-
320
- it "they should all be run" do
321
- puts "in the example"
322
- end
323
- end
324
- end
325
- end
326
- """
327
- When I run `rspec example_spec.rb`
328
- Then the output should contain "1 example, 0 failure"
329
- And the output should contain:
330
- """
331
- first outermost around hook before
332
- second outermost around hook before
333
- first outer around hook before
334
- second outer around hook before
335
- first inner around hook before
336
- second inner around hook before
337
- in the example
338
- second inner around hook after
339
- first inner around hook after
340
- second outer around hook after
341
- first outer around hook after
342
- second outermost around hook after
343
- first outermost around hook after
344
- """
@@ -1,427 +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
- Setting instance variables are not supported in `before(:suite)`.
25
-
26
- Mocks are only supported in `before(:each)`.
27
-
28
- Scenario: define before(:each) block
29
- Given a file named "before_each_spec.rb" with:
30
- """ruby
31
- require "rspec/expectations"
32
-
33
- class Thing
34
- def widgets
35
- @widgets ||= []
36
- end
37
- end
38
-
39
- describe Thing do
40
- before(:each) do
41
- @thing = Thing.new
42
- end
43
-
44
- describe "initialized in before(:each)" do
45
- it "has 0 widgets" do
46
- expect(@thing.widgets.count).to eq(0)
47
- end
48
-
49
- it "can accept new widgets" do
50
- @thing.widgets << Object.new
51
- end
52
-
53
- it "does not share state across examples" do
54
- expect(@thing.widgets.count).to eq(0)
55
- end
56
- end
57
- end
58
- """
59
- When I run `rspec before_each_spec.rb`
60
- Then the examples should all pass
61
-
62
- Scenario: define before(:all) block in example group
63
- Given a file named "before_all_spec.rb" with:
64
- """ruby
65
- require "rspec/expectations"
66
-
67
- class Thing
68
- def widgets
69
- @widgets ||= []
70
- end
71
- end
72
-
73
- describe Thing do
74
- before(:all) do
75
- @thing = Thing.new
76
- end
77
-
78
- describe "initialized in before(:all)" do
79
- it "has 0 widgets" do
80
- expect(@thing.widgets.count).to eq(0)
81
- end
82
-
83
- it "can accept new widgets" do
84
- @thing.widgets << Object.new
85
- end
86
-
87
- it "shares state across examples" do
88
- expect(@thing.widgets.count).to eq(1)
89
- end
90
- end
91
- end
92
- """
93
- When I run `rspec before_all_spec.rb`
94
- Then the examples should all pass
95
-
96
- When I run `rspec before_all_spec.rb:15`
97
- Then the examples should all pass
98
-
99
- Scenario: failure in before(:all) block
100
- Given a file named "before_all_spec.rb" with:
101
- """ruby
102
- describe "an error in before(:all)" do
103
- before(:all) do
104
- raise "oops"
105
- end
106
-
107
- it "fails this example" do
108
- end
109
-
110
- it "fails this example, too" do
111
- end
112
-
113
- after(:all) do
114
- puts "after all ran"
115
- end
116
-
117
- describe "nested group" do
118
- it "fails this third example" do
119
- end
120
-
121
- it "fails this fourth example" do
122
- end
123
-
124
- describe "yet another level deep" do
125
- it "fails this last example" do
126
- end
127
- end
128
- end
129
- end
130
- """
131
- When I run `rspec before_all_spec.rb --format documentation`
132
- Then the output should contain "5 examples, 5 failures"
133
- And the output should contain:
134
- """
135
- an error in before(:all)
136
- fails this example (FAILED - 1)
137
- fails this example, too (FAILED - 2)
138
- nested group
139
- fails this third example (FAILED - 3)
140
- fails this fourth example (FAILED - 4)
141
- yet another level deep
142
- fails this last example (FAILED - 5)
143
- after all ran
144
- """
145
-
146
- When I run `rspec before_all_spec.rb:9 --format documentation`
147
- Then the output should contain "1 example, 1 failure"
148
- And the output should contain:
149
- """
150
- an error in before(:all)
151
- fails this example, too (FAILED - 1)
152
- """
153
-
154
- Scenario: failure in after(:all) block
155
- Given a file named "after_all_spec.rb" with:
156
- """ruby
157
- describe "an error in after(:all)" do
158
- after(:all) do
159
- raise StandardError.new("Boom!")
160
- end
161
-
162
- it "passes this example" do
163
- end
164
-
165
- it "passes this example, too" do
166
- end
167
- end
168
- """
169
- When I run `rspec after_all_spec.rb`
170
- Then the examples should all pass
171
- And the output should contain:
172
- """
173
- An error occurred in an after(:all) hook.
174
- StandardError: Boom!
175
- """
176
-
177
- Scenario: define before and after blocks in configuration
178
- Given a file named "befores_in_configuration_spec.rb" with:
179
- """ruby
180
- require "rspec/expectations"
181
-
182
- RSpec.configure do |config|
183
- config.before(:each) do
184
- @before_each = "before each"
185
- end
186
- config.before(:all) do
187
- @before_all = "before all"
188
- end
189
- end
190
-
191
- describe "stuff in before blocks" do
192
- describe "with :all" do
193
- it "should be available in the example" do
194
- expect(@before_all).to eq("before all")
195
- end
196
- end
197
- describe "with :each" do
198
- it "should be available in the example" do
199
- expect(@before_each).to eq("before each")
200
- end
201
- end
202
- end
203
- """
204
- When I run `rspec befores_in_configuration_spec.rb`
205
- Then the examples should all pass
206
-
207
- Scenario: before/after blocks are run in order
208
- Given a file named "ensure_block_order_spec.rb" with:
209
- """ruby
210
- require "rspec/expectations"
211
-
212
- describe "before and after callbacks" do
213
- before(:all) do
214
- puts "before all"
215
- end
216
-
217
- before(:each) do
218
- puts "before each"
219
- end
220
-
221
- after(:each) do
222
- puts "after each"
223
- end
224
-
225
- after(:all) do
226
- puts "after all"
227
- end
228
-
229
- it "gets run in order" do
230
-
231
- end
232
- end
233
- """
234
- When I run `rspec --format progress ensure_block_order_spec.rb`
235
- Then the output should contain:
236
- """
237
- before all
238
- before each
239
- after each
240
- .after all
241
- """
242
-
243
- Scenario: before/after blocks defined in config are run in order
244
- Given a file named "configuration_spec.rb" with:
245
- """ruby
246
- require "rspec/expectations"
247
-
248
- RSpec.configure do |config|
249
- config.before(:suite) do
250
- puts "before suite"
251
- end
252
-
253
- config.before(:all) do
254
- puts "before all"
255
- end
256
-
257
- config.before(:each) do
258
- puts "before each"
259
- end
260
-
261
- config.after(:each) do
262
- puts "after each"
263
- end
264
-
265
- config.after(:all) do
266
- puts "after all"
267
- end
268
-
269
- config.after(:suite) do
270
- puts "after suite"
271
- end
272
- end
273
-
274
- describe "ignore" do
275
- example "ignore" do
276
- end
277
- end
278
- """
279
- When I run `rspec --format progress configuration_spec.rb`
280
- Then the output should contain:
281
- """
282
- before suite
283
- before all
284
- before each
285
- after each
286
- .after all
287
- after suite
288
- """
289
-
290
- Scenario: before/after all blocks are run once
291
- Given a file named "before_and_after_all_spec.rb" with:
292
- """ruby
293
- describe "before and after callbacks" do
294
- before(:all) do
295
- puts "outer before all"
296
- end
297
-
298
- example "in outer group" do
299
- end
300
-
301
- after(:all) do
302
- puts "outer after all"
303
- end
304
-
305
- describe "nested group" do
306
- before(:all) do
307
- puts "inner before all"
308
- end
309
-
310
- example "in nested group" do
311
- end
312
-
313
- after(:all) do
314
- puts "inner after all"
315
- end
316
- end
317
-
318
- end
319
- """
320
- When I run `rspec --format progress before_and_after_all_spec.rb`
321
- Then the examples should all pass
322
- And the output should contain:
323
- """
324
- outer before all
325
- .inner before all
326
- .inner after all
327
- outer after all
328
- """
329
-
330
- When I run `rspec --format progress before_and_after_all_spec.rb:14`
331
- Then the examples should all pass
332
- And the output should contain:
333
- """
334
- outer before all
335
- inner before all
336
- .inner after all
337
- outer after all
338
- """
339
-
340
- When I run `rspec --format progress before_and_after_all_spec.rb:6`
341
- Then the examples should all pass
342
- And the output should contain:
343
- """
344
- outer before all
345
- .outer after all
346
- """
347
-
348
- Scenario: nested examples have access to state set in outer before(:all)
349
- Given a file named "before_all_spec.rb" with:
350
- """ruby
351
- describe "something" do
352
- before :all do
353
- @value = 123
354
- end
355
-
356
- describe "nested" do
357
- it "access state set in before(:all)" do
358
- expect(@value).to eq(123)
359
- end
360
-
361
- describe "nested more deeply" do
362
- it "access state set in before(:all)" do
363
- expect(@value).to eq(123)
364
- end
365
- end
366
- end
367
-
368
- describe "nested in parallel" do
369
- it "access state set in before(:all)" do
370
- expect(@value).to eq(123)
371
- end
372
- end
373
- end
374
- """
375
- When I run `rspec before_all_spec.rb`
376
- Then the examples should all pass
377
-
378
- Scenario: before/after all blocks have access to state
379
- Given a file named "before_and_after_all_spec.rb" with:
380
- """ruby
381
- describe "before and after callbacks" do
382
- before(:all) do
383
- @outer_state = "set in outer before all"
384
- end
385
-
386
- example "in outer group" do
387
- expect(@outer_state).to eq("set in outer before all")
388
- end
389
-
390
- describe "nested group" do
391
- before(:all) do
392
- @inner_state = "set in inner before all"
393
- end
394
-
395
- example "in nested group" do
396
- expect(@outer_state).to eq("set in outer before all")
397
- expect(@inner_state).to eq("set in inner before all")
398
- end
399
-
400
- after(:all) do
401
- expect(@inner_state).to eq("set in inner before all")
402
- end
403
- end
404
-
405
- after(:all) do
406
- expect(@outer_state).to eq("set in outer before all")
407
- end
408
- end
409
- """
410
- When I run `rspec before_and_after_all_spec.rb`
411
- Then the examples should all pass
412
-
413
- Scenario: exception in before(:each) is captured and reported as failure
414
- Given a file named "error_in_before_each_spec.rb" with:
415
- """ruby
416
- describe "error in before(:each)" do
417
- before(:each) do
418
- raise "this error"
419
- end
420
-
421
- it "is reported as failure" do
422
- end
423
- end
424
- """
425
- When I run `rspec error_in_before_each_spec.rb`
426
- Then the output should contain "1 example, 1 failure"
427
- And the output should contain "this error"