rspec-core 2.0.0.beta.22 → 2.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/.rspec +0 -1
- data/.travis.yml +9 -0
- data/Changelog.md +305 -0
- data/Gemfile +45 -20
- data/Guardfile +5 -0
- data/License.txt +2 -1
- data/{README.markdown → README.md} +23 -5
- data/Rakefile +63 -32
- data/bin/autospec +13 -0
- data/bin/rspec +24 -2
- data/cucumber.yml +1 -1
- data/features/.nav +57 -0
- data/features/Autotest.md +38 -0
- data/features/README.md +17 -0
- data/features/Upgrade.md +320 -0
- data/features/command_line/README.md +28 -0
- data/features/command_line/configure.feature +18 -15
- data/features/command_line/example_name_option.feature +37 -23
- data/features/command_line/exit_status.feature +16 -31
- data/features/command_line/format_option.feature +73 -0
- data/features/command_line/line_number_appended_to_path.feature +25 -27
- data/features/command_line/line_number_option.feature +11 -10
- data/features/command_line/rake_task.feature +68 -0
- data/features/command_line/tag.feature +90 -0
- data/features/configuration/alias_example_to.feature +48 -0
- data/features/configuration/custom_settings.feature +8 -10
- data/features/configuration/fail_fast.feature +77 -0
- data/features/configuration/read_options_from_file.feature +42 -26
- data/features/example_groups/basic_structure.feature +55 -0
- data/features/example_groups/shared_context.feature +74 -0
- data/features/example_groups/shared_example_group.feature +56 -41
- data/features/expectation_framework_integration/configure_expectation_framework.feature +73 -0
- data/features/filtering/exclusion_filters.feature +69 -9
- data/features/filtering/if_and_unless.feature +168 -0
- data/features/filtering/inclusion_filters.feature +58 -26
- data/features/filtering/run_all_when_everything_filtered.feature +46 -0
- data/features/formatters/custom_formatter.feature +17 -13
- data/features/formatters/text_formatter.feature +43 -0
- data/features/helper_methods/arbitrary_methods.feature +40 -0
- data/features/helper_methods/let.feature +50 -0
- data/features/helper_methods/modules.feature +149 -0
- data/features/hooks/around_hooks.feature +99 -69
- data/features/hooks/before_and_after_hooks.feature +74 -40
- data/features/hooks/filtering.feature +227 -0
- data/features/metadata/current_example.feature +17 -0
- data/features/metadata/described_class.feature +17 -0
- data/features/metadata/user_defined.feature +111 -0
- data/features/mock_framework_integration/use_any_framework.feature +106 -0
- data/features/mock_framework_integration/use_flexmock.feature +84 -11
- data/features/mock_framework_integration/use_mocha.feature +85 -11
- data/features/mock_framework_integration/use_rr.feature +86 -11
- data/features/mock_framework_integration/use_rspec.feature +85 -11
- data/features/pending/pending_examples.feature +143 -5
- data/features/spec_files/arbitrary_file_suffix.feature +2 -2
- data/features/step_definitions/additional_cli_steps.rb +30 -0
- data/features/subject/attribute_of_subject.feature +93 -15
- data/features/subject/explicit_subject.feature +28 -17
- data/features/subject/implicit_receiver.feature +29 -0
- data/features/subject/implicit_subject.feature +9 -10
- data/features/support/env.rb +6 -1
- data/lib/autotest/discover.rb +1 -0
- data/lib/autotest/rspec2.rb +15 -11
- data/lib/rspec/autorun.rb +2 -0
- data/lib/rspec/core/backward_compatibility.rb +32 -3
- data/lib/rspec/core/command_line.rb +4 -28
- data/lib/rspec/core/command_line_configuration.rb +16 -16
- data/lib/rspec/core/configuration.rb +286 -89
- data/lib/rspec/core/configuration_options.rb +74 -40
- data/lib/rspec/core/deprecation.rb +1 -1
- data/lib/rspec/core/drb_command_line.rb +5 -11
- data/lib/rspec/core/dsl.rb +11 -0
- data/lib/rspec/core/example.rb +63 -39
- data/lib/rspec/core/example_group.rb +109 -59
- data/lib/rspec/core/expecting/with_rspec.rb +9 -0
- data/lib/rspec/core/expecting/with_stdlib.rb +9 -0
- data/lib/rspec/core/extensions/kernel.rb +1 -1
- data/lib/rspec/core/extensions.rb +0 -1
- data/lib/rspec/core/formatters/base_formatter.rb +30 -15
- data/lib/rspec/core/formatters/base_text_formatter.rb +68 -40
- data/lib/rspec/core/formatters/documentation_formatter.rb +4 -2
- data/lib/rspec/core/formatters/helpers.rb +0 -4
- data/lib/rspec/core/formatters/html_formatter.rb +146 -41
- data/lib/rspec/core/formatters/progress_formatter.rb +1 -0
- data/lib/rspec/core/formatters/snippet_extractor.rb +1 -1
- data/lib/rspec/core/formatters/text_mate_formatter.rb +3 -1
- data/lib/rspec/core/hooks.rb +56 -17
- data/lib/rspec/core/metadata.rb +75 -64
- data/lib/rspec/core/metadata_hash_builder.rb +93 -0
- data/lib/rspec/core/mocking/with_flexmock.rb +2 -0
- data/lib/rspec/core/mocking/with_mocha.rb +2 -0
- data/lib/rspec/core/mocking/with_rr.rb +2 -0
- data/lib/rspec/core/mocking/with_rspec.rb +3 -1
- data/lib/rspec/core/option_parser.rb +49 -7
- data/lib/rspec/core/pending.rb +22 -4
- data/lib/rspec/core/rake_task.rb +64 -28
- data/lib/rspec/core/reporter.rb +6 -5
- data/lib/rspec/core/ruby_project.rb +2 -2
- data/lib/rspec/core/runner.rb +50 -6
- data/lib/rspec/core/shared_context.rb +16 -0
- data/lib/rspec/core/shared_example_group.rb +19 -4
- data/lib/rspec/core/subject.rb +92 -65
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/world.rb +85 -27
- data/lib/rspec/core.rb +55 -24
- data/lib/rspec/monkey/spork/test_framework/rspec.rb +1 -0
- data/rspec-core.gemspec +4 -25
- data/script/FullBuildRakeFile +63 -0
- data/script/cucumber +1 -0
- data/script/full_build +1 -0
- data/script/spec +1 -0
- data/spec/autotest/discover_spec.rb +19 -0
- data/spec/autotest/failed_results_re_spec.rb +25 -9
- data/spec/autotest/rspec_spec.rb +32 -41
- data/spec/rspec/core/command_line_spec.rb +62 -7
- data/spec/rspec/core/configuration_options_spec.rb +216 -148
- data/spec/rspec/core/configuration_spec.rb +419 -108
- data/spec/rspec/core/deprecations_spec.rb +38 -1
- data/spec/rspec/core/drb_command_line_spec.rb +21 -56
- data/spec/rspec/core/example_group_spec.rb +366 -127
- data/spec/rspec/core/example_spec.rb +125 -45
- data/spec/rspec/core/formatters/base_formatter_spec.rb +61 -1
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +134 -97
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +7 -6
- data/spec/rspec/core/formatters/helpers_spec.rb +1 -1
- data/spec/rspec/core/formatters/html_formatted-1.8.6.html +199 -81
- data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +195 -83
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +199 -81
- data/spec/rspec/core/formatters/html_formatted-1.9.1.html +206 -81
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +206 -61
- data/spec/rspec/core/formatters/html_formatter_spec.rb +17 -9
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +1 -1
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +199 -81
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +195 -81
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +199 -81
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +206 -81
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +206 -81
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +22 -7
- data/spec/rspec/core/hooks_filtering_spec.rb +128 -5
- data/spec/rspec/core/hooks_spec.rb +90 -4
- data/spec/rspec/core/metadata_spec.rb +176 -163
- data/spec/rspec/core/option_parser_spec.rb +73 -6
- data/spec/rspec/core/pending_example_spec.rb +137 -35
- data/spec/rspec/core/rake_task_spec.rb +62 -29
- data/spec/rspec/core/reporter_spec.rb +20 -4
- data/spec/rspec/core/resources/formatter_specs.rb +25 -1
- data/spec/rspec/core/rspec_matchers_spec.rb +45 -0
- data/spec/rspec/core/runner_spec.rb +60 -10
- data/spec/rspec/core/shared_context_spec.rb +30 -0
- data/spec/rspec/core/shared_example_group_spec.rb +59 -23
- data/spec/rspec/core/subject_spec.rb +136 -0
- data/spec/rspec/core/world_spec.rb +211 -68
- data/spec/rspec/core_spec.rb +28 -0
- data/spec/spec_helper.rb +41 -24
- data/spec/support/matchers.rb +44 -13
- data/spec/support/shared_example_groups.rb +41 -0
- data/spec/support/spec_files.rb +44 -0
- data/spec.txt +1126 -0
- metadata +100 -170
- data/.treasure_map.rb +0 -23
- data/History.md +0 -30
- data/Upgrade.markdown +0 -150
- data/autotest/discover.rb +0 -2
- data/features/README.markdown +0 -12
- data/features/example_groups/describe_aliases.feature +0 -25
- data/features/example_groups/nested_groups.feature +0 -44
- data/features/hooks/described_class.feature +0 -14
- data/features/hooks/halt.feature +0 -26
- data/lib/rspec/core/around_proxy.rb +0 -14
- data/lib/rspec/core/extensions/object.rb +0 -15
- data/lib/rspec/core/formatters.rb +0 -8
- data/spec/ruby_forker.rb +0 -13
- data/specs.watchr +0 -59
|
@@ -1,52 +1,66 @@
|
|
|
1
1
|
Feature: around hooks
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
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:
|
|
9
21
|
"""
|
|
22
|
+
class Database
|
|
23
|
+
def self.transaction
|
|
24
|
+
puts "open transaction"
|
|
25
|
+
yield
|
|
26
|
+
puts "close transaction"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
10
30
|
describe "around filter" do
|
|
11
31
|
around(:each) do |example|
|
|
12
|
-
|
|
13
|
-
example.run
|
|
14
|
-
puts "around each after"
|
|
32
|
+
Database.transaction(&example)
|
|
15
33
|
end
|
|
16
34
|
|
|
17
35
|
it "gets run in order" do
|
|
18
|
-
puts "
|
|
36
|
+
puts "run the example"
|
|
19
37
|
end
|
|
20
38
|
end
|
|
21
39
|
"""
|
|
22
|
-
When I run
|
|
40
|
+
When I run `rspec example_spec.rb`
|
|
23
41
|
Then the output should contain:
|
|
24
42
|
"""
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
43
|
+
open transaction
|
|
44
|
+
run the example
|
|
45
|
+
close transaction
|
|
28
46
|
"""
|
|
29
47
|
|
|
30
|
-
Scenario:
|
|
31
|
-
Given a file named "
|
|
48
|
+
Scenario: invoke the example using run()
|
|
49
|
+
Given a file named "example_spec.rb" with:
|
|
32
50
|
"""
|
|
33
|
-
describe "around
|
|
34
|
-
|
|
51
|
+
describe "around hook" do
|
|
52
|
+
around(:each) do |example|
|
|
35
53
|
puts "around each before"
|
|
36
|
-
|
|
54
|
+
example.run
|
|
37
55
|
puts "around each after"
|
|
38
56
|
end
|
|
39
57
|
|
|
40
|
-
around(:each) do |example|
|
|
41
|
-
perform_around(&example)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
58
|
it "gets run in order" do
|
|
45
59
|
puts "in the example"
|
|
46
60
|
end
|
|
47
61
|
end
|
|
48
62
|
"""
|
|
49
|
-
When I run
|
|
63
|
+
When I run `rspec example_spec.rb`
|
|
50
64
|
Then the output should contain:
|
|
51
65
|
"""
|
|
52
66
|
around each before
|
|
@@ -54,8 +68,24 @@ Feature: around hooks
|
|
|
54
68
|
around each after
|
|
55
69
|
"""
|
|
56
70
|
|
|
57
|
-
Scenario:
|
|
58
|
-
Given a file named "
|
|
71
|
+
Scenario: access the example metadata
|
|
72
|
+
Given a file named "example_spec.rb" with:
|
|
73
|
+
"""
|
|
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:
|
|
59
89
|
"""
|
|
60
90
|
RSpec.configure do |c|
|
|
61
91
|
c.around(:each) do |example|
|
|
@@ -71,7 +101,7 @@ Feature: around hooks
|
|
|
71
101
|
end
|
|
72
102
|
end
|
|
73
103
|
"""
|
|
74
|
-
When I run
|
|
104
|
+
When I run `rspec example_spec.rb`
|
|
75
105
|
Then the output should contain:
|
|
76
106
|
"""
|
|
77
107
|
around each before
|
|
@@ -80,7 +110,7 @@ Feature: around hooks
|
|
|
80
110
|
"""
|
|
81
111
|
|
|
82
112
|
Scenario: before/after(:each) hooks are wrapped by the around hook
|
|
83
|
-
Given a file named "
|
|
113
|
+
Given a file named "example_spec.rb" with:
|
|
84
114
|
"""
|
|
85
115
|
describe "around filter" do
|
|
86
116
|
around(:each) do |example|
|
|
@@ -102,7 +132,7 @@ Feature: around hooks
|
|
|
102
132
|
end
|
|
103
133
|
end
|
|
104
134
|
"""
|
|
105
|
-
When I run
|
|
135
|
+
When I run `rspec example_spec.rb`
|
|
106
136
|
Then the output should contain:
|
|
107
137
|
"""
|
|
108
138
|
around each before
|
|
@@ -113,7 +143,7 @@ Feature: around hooks
|
|
|
113
143
|
"""
|
|
114
144
|
|
|
115
145
|
Scenario: before/after(:all) hooks are NOT wrapped by the around hook
|
|
116
|
-
Given a file named "
|
|
146
|
+
Given a file named "example_spec.rb" with:
|
|
117
147
|
"""
|
|
118
148
|
describe "around filter" do
|
|
119
149
|
around(:each) do |example|
|
|
@@ -135,7 +165,7 @@ Feature: around hooks
|
|
|
135
165
|
end
|
|
136
166
|
end
|
|
137
167
|
"""
|
|
138
|
-
When I run
|
|
168
|
+
When I run `rspec example_spec.rb`
|
|
139
169
|
Then the output should contain:
|
|
140
170
|
"""
|
|
141
171
|
before all
|
|
@@ -145,8 +175,8 @@ Feature: around hooks
|
|
|
145
175
|
.after all
|
|
146
176
|
"""
|
|
147
177
|
|
|
148
|
-
Scenario: examples run by an around block
|
|
149
|
-
Given a file named "
|
|
178
|
+
Scenario: examples run by an around block are run in the configured context
|
|
179
|
+
Given a file named "example_spec.rb" with:
|
|
150
180
|
"""
|
|
151
181
|
module IncludedInConfigureBlock
|
|
152
182
|
def included_in_configure_block; true; end
|
|
@@ -166,11 +196,11 @@ Feature: around hooks
|
|
|
166
196
|
end
|
|
167
197
|
end
|
|
168
198
|
"""
|
|
169
|
-
When I run
|
|
199
|
+
When I run `rspec example_spec.rb`
|
|
170
200
|
Then the output should contain "1 example, 0 failure"
|
|
171
201
|
|
|
172
|
-
Scenario: implicitly pending examples
|
|
173
|
-
Given a file named "
|
|
202
|
+
Scenario: implicitly pending examples are detected as Not Yet Implemented
|
|
203
|
+
Given a file named "example_spec.rb" with:
|
|
174
204
|
"""
|
|
175
205
|
describe "implicit pending example" do
|
|
176
206
|
around(:each) do |example|
|
|
@@ -180,7 +210,7 @@ Feature: around hooks
|
|
|
180
210
|
it "should be detected as Not Yet Implemented"
|
|
181
211
|
end
|
|
182
212
|
"""
|
|
183
|
-
When I run
|
|
213
|
+
When I run `rspec example_spec.rb`
|
|
184
214
|
Then the output should contain "1 example, 0 failures, 1 pending"
|
|
185
215
|
And the output should contain:
|
|
186
216
|
"""
|
|
@@ -190,8 +220,8 @@ Feature: around hooks
|
|
|
190
220
|
"""
|
|
191
221
|
|
|
192
222
|
|
|
193
|
-
Scenario: explicitly pending examples
|
|
194
|
-
Given a file named "
|
|
223
|
+
Scenario: explicitly pending examples are detected as pending
|
|
224
|
+
Given a file named "example_spec.rb" with:
|
|
195
225
|
"""
|
|
196
226
|
describe "explicit pending example" do
|
|
197
227
|
around(:each) do |example|
|
|
@@ -203,7 +233,7 @@ Feature: around hooks
|
|
|
203
233
|
end
|
|
204
234
|
end
|
|
205
235
|
"""
|
|
206
|
-
When I run
|
|
236
|
+
When I run `rspec example_spec.rb`
|
|
207
237
|
Then the output should contain "1 example, 0 failures, 1 pending"
|
|
208
238
|
And the output should contain:
|
|
209
239
|
"""
|
|
@@ -211,41 +241,41 @@ Feature: around hooks
|
|
|
211
241
|
# No reason given
|
|
212
242
|
"""
|
|
213
243
|
|
|
214
|
-
Scenario: multiple around hooks in the same scope
|
|
215
|
-
Given a file named "
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
244
|
+
Scenario: multiple around hooks in the same scope
|
|
245
|
+
Given a file named "example_spec.rb" with:
|
|
246
|
+
"""
|
|
247
|
+
describe "if there are multiple around hooks in the same scope" do
|
|
248
|
+
around(:each) do |example|
|
|
249
|
+
puts "first around hook before"
|
|
250
|
+
example.run
|
|
251
|
+
puts "first around hook after"
|
|
252
|
+
end
|
|
223
253
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
254
|
+
around(:each) do |example|
|
|
255
|
+
puts "second around hook before"
|
|
256
|
+
example.run
|
|
257
|
+
puts "second around hook after"
|
|
258
|
+
end
|
|
229
259
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
260
|
+
it "they should all be run" do
|
|
261
|
+
puts "in the example"
|
|
262
|
+
1.should == 1
|
|
263
|
+
end
|
|
233
264
|
end
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
When I run "rspec ./around_hooks_in_same_scope.rb"
|
|
265
|
+
"""
|
|
266
|
+
When I run `rspec example_spec.rb`
|
|
237
267
|
Then the output should contain "1 example, 0 failure"
|
|
238
268
|
And the output should contain:
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
269
|
+
"""
|
|
270
|
+
first around hook before
|
|
271
|
+
second around hook before
|
|
272
|
+
in the example
|
|
273
|
+
second around hook after
|
|
274
|
+
first around hook after
|
|
275
|
+
"""
|
|
246
276
|
|
|
247
|
-
Scenario: around hooks in
|
|
248
|
-
Given a file named "
|
|
277
|
+
Scenario: around hooks in multiple scopes
|
|
278
|
+
Given a file named "example_spec.rb" with:
|
|
249
279
|
"""
|
|
250
280
|
describe "if there are around hooks in an outer scope" do
|
|
251
281
|
around(:each) do |example|
|
|
@@ -293,7 +323,7 @@ Feature: around hooks
|
|
|
293
323
|
end
|
|
294
324
|
end
|
|
295
325
|
"""
|
|
296
|
-
When I run
|
|
326
|
+
When I run `rspec example_spec.rb`
|
|
297
327
|
Then the output should contain "1 example, 0 failure"
|
|
298
328
|
And the output should contain:
|
|
299
329
|
"""
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
Feature: before and after hooks
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
So that I can control the environment in which it is run
|
|
3
|
+
Use `before` and `after` hooks to execute arbitrary code before and/or
|
|
4
|
+
after the body of an example is run:
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
before(:each) # run before each example
|
|
7
|
+
before(:all) # run one time only, before all of the examples in a group
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
after(:each) # run after each example
|
|
10
|
+
after(:all) # run one time only, after all of the examples in a group
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
after(:all) blocks are run once after all of the examples in a group
|
|
12
|
+
Before and after blocks are called in the following order:
|
|
15
13
|
|
|
16
|
-
Before and after blocks are called in the following order:
|
|
17
14
|
before suite
|
|
18
15
|
before all
|
|
19
16
|
before each
|
|
@@ -21,10 +18,8 @@ Feature: before and after hooks
|
|
|
21
18
|
after all
|
|
22
19
|
after suite
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
applied to all groups or subsets of all groups defined by example group
|
|
27
|
-
types.
|
|
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.
|
|
28
23
|
|
|
29
24
|
Scenario: define before(:each) block
|
|
30
25
|
Given a file named "before_each_spec.rb" with:
|
|
@@ -57,8 +52,8 @@ Feature: before and after hooks
|
|
|
57
52
|
end
|
|
58
53
|
end
|
|
59
54
|
"""
|
|
60
|
-
When I run
|
|
61
|
-
Then the
|
|
55
|
+
When I run `rspec before_each_spec.rb`
|
|
56
|
+
Then the examples should all pass
|
|
62
57
|
|
|
63
58
|
Scenario: define before(:all) block in example group
|
|
64
59
|
Given a file named "before_all_spec.rb" with:
|
|
@@ -91,11 +86,11 @@ Feature: before and after hooks
|
|
|
91
86
|
end
|
|
92
87
|
end
|
|
93
88
|
"""
|
|
94
|
-
When I run
|
|
95
|
-
Then the
|
|
89
|
+
When I run `rspec before_all_spec.rb`
|
|
90
|
+
Then the examples should all pass
|
|
96
91
|
|
|
97
|
-
When I run
|
|
98
|
-
Then the
|
|
92
|
+
When I run `rspec before_all_spec.rb:15`
|
|
93
|
+
Then the examples should all pass
|
|
99
94
|
|
|
100
95
|
Scenario: failure in before(:all) block
|
|
101
96
|
Given a file named "before_all_spec.rb" with:
|
|
@@ -114,25 +109,65 @@ Feature: before and after hooks
|
|
|
114
109
|
after(:all) do
|
|
115
110
|
puts "after all ran"
|
|
116
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
|
|
117
125
|
end
|
|
118
126
|
"""
|
|
119
|
-
When I run
|
|
120
|
-
Then the output should contain "
|
|
127
|
+
When I run `rspec before_all_spec.rb --format documentation`
|
|
128
|
+
Then the output should contain "5 examples, 5 failures"
|
|
121
129
|
And the output should contain:
|
|
122
130
|
"""
|
|
123
131
|
an error in before(:all)
|
|
124
132
|
fails this example (FAILED - 1)
|
|
125
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)
|
|
126
139
|
after all ran
|
|
127
140
|
"""
|
|
128
141
|
|
|
129
|
-
When I run
|
|
142
|
+
When I run `rspec before_all_spec.rb:9 --format documentation`
|
|
130
143
|
Then the output should contain "1 example, 1 failure"
|
|
131
144
|
And the output should contain:
|
|
132
145
|
"""
|
|
133
146
|
an error in before(:all)
|
|
134
147
|
fails this example, too (FAILED - 1)
|
|
135
|
-
|
|
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!
|
|
136
171
|
"""
|
|
137
172
|
|
|
138
173
|
Scenario: define before and after blocks in configuration
|
|
@@ -162,8 +197,8 @@ Feature: before and after hooks
|
|
|
162
197
|
end
|
|
163
198
|
end
|
|
164
199
|
"""
|
|
165
|
-
When I run
|
|
166
|
-
Then the
|
|
200
|
+
When I run `rspec befores_in_configuration_spec.rb`
|
|
201
|
+
Then the examples should all pass
|
|
167
202
|
|
|
168
203
|
Scenario: before/after blocks are run in order
|
|
169
204
|
Given a file named "ensure_block_order_spec.rb" with:
|
|
@@ -192,7 +227,7 @@ Feature: before and after hooks
|
|
|
192
227
|
end
|
|
193
228
|
end
|
|
194
229
|
"""
|
|
195
|
-
When I run
|
|
230
|
+
When I run `rspec ensure_block_order_spec.rb`
|
|
196
231
|
Then the output should contain:
|
|
197
232
|
"""
|
|
198
233
|
before all
|
|
@@ -237,7 +272,7 @@ Feature: before and after hooks
|
|
|
237
272
|
end
|
|
238
273
|
end
|
|
239
274
|
"""
|
|
240
|
-
When I run
|
|
275
|
+
When I run `rspec configuration_spec.rb`
|
|
241
276
|
Then the output should contain:
|
|
242
277
|
"""
|
|
243
278
|
before suite
|
|
@@ -278,8 +313,8 @@ Feature: before and after hooks
|
|
|
278
313
|
|
|
279
314
|
end
|
|
280
315
|
"""
|
|
281
|
-
When I run
|
|
282
|
-
Then the
|
|
316
|
+
When I run `rspec before_and_after_all_spec.rb`
|
|
317
|
+
Then the examples should all pass
|
|
283
318
|
And the output should contain:
|
|
284
319
|
"""
|
|
285
320
|
outer before all
|
|
@@ -288,8 +323,8 @@ Feature: before and after hooks
|
|
|
288
323
|
outer after all
|
|
289
324
|
"""
|
|
290
325
|
|
|
291
|
-
When I run
|
|
292
|
-
Then the
|
|
326
|
+
When I run `rspec before_and_after_all_spec.rb:14`
|
|
327
|
+
Then the examples should all pass
|
|
293
328
|
And the output should contain:
|
|
294
329
|
"""
|
|
295
330
|
outer before all
|
|
@@ -298,8 +333,8 @@ Feature: before and after hooks
|
|
|
298
333
|
outer after all
|
|
299
334
|
"""
|
|
300
335
|
|
|
301
|
-
When I run
|
|
302
|
-
Then the
|
|
336
|
+
When I run `rspec before_and_after_all_spec.rb:6`
|
|
337
|
+
Then the examples should all pass
|
|
303
338
|
And the output should contain:
|
|
304
339
|
"""
|
|
305
340
|
outer before all
|
|
@@ -333,8 +368,8 @@ Feature: before and after hooks
|
|
|
333
368
|
end
|
|
334
369
|
end
|
|
335
370
|
"""
|
|
336
|
-
When I run
|
|
337
|
-
Then the
|
|
371
|
+
When I run `rspec before_all_spec.rb`
|
|
372
|
+
Then the examples should all pass
|
|
338
373
|
|
|
339
374
|
Scenario: before/after all blocks have access to state
|
|
340
375
|
Given a file named "before_and_after_all_spec.rb" with:
|
|
@@ -364,13 +399,12 @@ Feature: before and after hooks
|
|
|
364
399
|
end
|
|
365
400
|
|
|
366
401
|
after(:all) do
|
|
367
|
-
# p @outer_state.nil?
|
|
368
402
|
@outer_state.should eq("set in outer before all")
|
|
369
403
|
end
|
|
370
404
|
end
|
|
371
405
|
"""
|
|
372
|
-
When I run
|
|
373
|
-
Then the
|
|
406
|
+
When I run `rspec before_and_after_all_spec.rb`
|
|
407
|
+
Then the examples should all pass
|
|
374
408
|
|
|
375
409
|
Scenario: exception in before(:each) is captured and reported as failure
|
|
376
410
|
Given a file named "error_in_before_each_spec.rb" with:
|
|
@@ -384,6 +418,6 @@ Feature: before and after hooks
|
|
|
384
418
|
end
|
|
385
419
|
end
|
|
386
420
|
"""
|
|
387
|
-
When I run
|
|
421
|
+
When I run `rspec error_in_before_each_spec.rb`
|
|
388
422
|
Then the output should contain "1 example, 1 failure"
|
|
389
423
|
And the output should contain "this error"
|