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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.yardopts +1 -0
- data/Changelog.md +297 -57
- data/README.md +16 -13
- data/lib/rspec/core.rb +55 -84
- data/lib/rspec/core/backport_random.rb +35 -3
- data/lib/rspec/core/backtrace_formatter.rb +4 -13
- data/lib/rspec/core/configuration.rb +330 -114
- data/lib/rspec/core/configuration_options.rb +38 -22
- data/lib/rspec/core/drb.rb +111 -0
- data/lib/rspec/core/dsl.rb +8 -2
- data/lib/rspec/core/example.rb +203 -94
- data/lib/rspec/core/example_group.rb +344 -316
- data/lib/rspec/core/filter_manager.rb +135 -90
- data/lib/rspec/core/flat_map.rb +1 -0
- data/lib/rspec/core/formatters.rb +50 -14
- data/lib/rspec/core/formatters/base_formatter.rb +32 -138
- data/lib/rspec/core/formatters/base_text_formatter.rb +32 -253
- data/lib/rspec/core/formatters/console_codes.rb +65 -0
- data/lib/rspec/core/formatters/deprecation_formatter.rb +24 -15
- data/lib/rspec/core/formatters/documentation_formatter.rb +7 -10
- data/lib/rspec/core/formatters/helpers.rb +15 -9
- data/lib/rspec/core/formatters/html_formatter.rb +17 -16
- data/lib/rspec/core/formatters/html_printer.rb +1 -0
- data/lib/rspec/core/formatters/json_formatter.rb +18 -20
- data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
- data/lib/rspec/core/formatters/progress_formatter.rb +6 -7
- data/lib/rspec/core/formatters/snippet_extractor.rb +8 -6
- data/lib/rspec/core/hooks.rb +131 -125
- data/lib/rspec/core/memoized_helpers.rb +31 -26
- data/lib/rspec/core/metadata.rb +277 -184
- data/lib/rspec/core/metadata_filter.rb +86 -0
- data/lib/rspec/core/minitest_assertions_adapter.rb +28 -0
- data/lib/rspec/core/mocking_adapters/flexmock.rb +1 -1
- data/lib/rspec/core/mocking_adapters/mocha.rb +1 -1
- data/lib/rspec/core/mocking_adapters/null.rb +1 -1
- data/lib/rspec/core/mocking_adapters/rr.rb +2 -1
- data/lib/rspec/core/mocking_adapters/rspec.rb +1 -1
- data/lib/rspec/core/notifications.rb +435 -24
- data/lib/rspec/core/option_parser.rb +16 -25
- data/lib/rspec/core/ordering.rb +3 -1
- data/lib/rspec/core/pending.rb +57 -33
- data/lib/rspec/core/project_initializer.rb +2 -0
- data/lib/rspec/core/project_initializer/spec_helper.rb +5 -4
- data/lib/rspec/core/rake_task.rb +45 -20
- data/lib/rspec/core/reporter.rb +50 -22
- data/lib/rspec/core/ruby_project.rb +1 -0
- data/lib/rspec/core/runner.rb +93 -39
- data/lib/rspec/core/shared_context.rb +7 -5
- data/lib/rspec/core/shared_example_group.rb +85 -77
- data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
- data/lib/rspec/core/version.rb +3 -1
- data/lib/rspec/core/warnings.rb +35 -17
- data/lib/rspec/core/world.rb +57 -5
- metadata +56 -369
- metadata.gz.sig +3 -3
- data/features/README.md +0 -13
- data/features/Upgrade.md +0 -352
- data/features/command_line/README.md +0 -25
- data/features/command_line/dry_run.feature +0 -29
- data/features/command_line/example_name_option.feature +0 -97
- data/features/command_line/exit_status.feature +0 -82
- data/features/command_line/fail_fast.feature +0 -26
- data/features/command_line/format_option.feature +0 -75
- data/features/command_line/init.feature +0 -57
- data/features/command_line/line_number_appended_to_path.feature +0 -140
- data/features/command_line/line_number_option.feature +0 -58
- data/features/command_line/order.feature +0 -25
- data/features/command_line/pattern_option.feature +0 -49
- data/features/command_line/rake_task.feature +0 -122
- data/features/command_line/randomization.feature +0 -63
- data/features/command_line/require_option.feature +0 -43
- data/features/command_line/ruby.feature +0 -23
- data/features/command_line/tag.feature +0 -98
- data/features/command_line/warnings_option.feature +0 -29
- data/features/configuration/alias_example_to.feature +0 -39
- data/features/configuration/backtrace_exclusion_patterns.feature +0 -105
- data/features/configuration/custom_settings.feature +0 -84
- data/features/configuration/default_path.feature +0 -38
- data/features/configuration/deprecation_stream.feature +0 -58
- data/features/configuration/enable_global_dsl.feature +0 -54
- data/features/configuration/fail_fast.feature +0 -77
- data/features/configuration/failure_exit_code.feature +0 -36
- data/features/configuration/order_and_seed.feature +0 -3
- data/features/configuration/output_stream.feature +0 -24
- data/features/configuration/overriding_global_ordering.feature +0 -93
- data/features/configuration/pattern.feature +0 -38
- data/features/configuration/profile.feature +0 -220
- data/features/configuration/read_options_from_file.feature +0 -90
- data/features/configuration/run_all_when_everything_filtered.feature +0 -76
- data/features/example_groups/aliasing.feature +0 -48
- data/features/example_groups/basic_structure.feature +0 -55
- data/features/example_groups/shared_context.feature +0 -74
- data/features/example_groups/shared_examples.feature +0 -286
- data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
- data/features/filtering/exclusion_filters.feature +0 -135
- data/features/filtering/if_and_unless.feature +0 -138
- data/features/filtering/inclusion_filters.feature +0 -101
- data/features/formatters/configurable_colors.feature +0 -31
- data/features/formatters/custom_formatter.feature +0 -68
- data/features/formatters/json_formatter.feature +0 -30
- data/features/formatters/regression_tests.feature +0 -95
- data/features/formatters/text_formatter.feature +0 -46
- data/features/helper_methods/arbitrary_methods.feature +0 -40
- data/features/helper_methods/let.feature +0 -50
- data/features/helper_methods/modules.feature +0 -146
- data/features/hooks/around_hooks.feature +0 -344
- data/features/hooks/before_and_after_hooks.feature +0 -427
- data/features/hooks/filtering.feature +0 -232
- data/features/metadata/current_example.feature +0 -56
- data/features/metadata/described_class.feature +0 -17
- data/features/metadata/user_defined.feature +0 -100
- data/features/mock_framework_integration/use_any_framework.feature +0 -106
- data/features/mock_framework_integration/use_flexmock.feature +0 -94
- data/features/mock_framework_integration/use_mocha.feature +0 -95
- data/features/mock_framework_integration/use_rr.feature +0 -96
- data/features/mock_framework_integration/use_rspec.feature +0 -95
- data/features/pending_and_skipped_examples/README.md +0 -3
- data/features/pending_and_skipped_examples/pending_examples.feature +0 -118
- data/features/pending_and_skipped_examples/skipped_examples.feature +0 -106
- data/features/spec_files/arbitrary_file_suffix.feature +0 -13
- data/features/step_definitions/additional_cli_steps.rb +0 -83
- data/features/subject/explicit_subject.feature +0 -101
- data/features/subject/implicit_subject.feature +0 -63
- data/features/subject/one_liner_syntax.feature +0 -71
- data/features/support/env.rb +0 -21
- data/features/support/require_expect_syntax_in_aruba_specs.rb +0 -16
- data/features/support/rubinius.rb +0 -6
- data/lib/rspec/core/command_line.rb +0 -35
- data/lib/rspec/core/drb_command_line.rb +0 -26
- data/lib/rspec/core/drb_options.rb +0 -87
- data/lib/rspec/core/formatters/legacy_formatter.rb +0 -227
- data/lib/rspec/core/shared_example_group/collection.rb +0 -27
- data/spec/command_line/order_spec.rb +0 -211
- data/spec/rspec/core/backtrace_formatter_spec.rb +0 -230
- data/spec/rspec/core/command_line_spec.rb +0 -112
- data/spec/rspec/core/command_line_spec_output.txt +0 -0
- data/spec/rspec/core/configuration_options_spec.rb +0 -409
- data/spec/rspec/core/configuration_spec.rb +0 -1479
- data/spec/rspec/core/drb_command_line_spec.rb +0 -102
- data/spec/rspec/core/drb_options_spec.rb +0 -193
- data/spec/rspec/core/dsl_spec.rb +0 -88
- data/spec/rspec/core/example_group_spec.rb +0 -1533
- data/spec/rspec/core/example_spec.rb +0 -642
- data/spec/rspec/core/filter_manager_spec.rb +0 -229
- data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -64
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -303
- data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -208
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -75
- data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
- data/spec/rspec/core/formatters/html_formatted-2.1.0.html +0 -392
- data/spec/rspec/core/formatters/html_formatted.html +0 -397
- data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -122
- data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -206
- data/spec/rspec/core/formatters/legacy_formatter_spec.rb +0 -137
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -43
- data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
- data/spec/rspec/core/formatters_spec.rb +0 -120
- data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
- data/spec/rspec/core/hooks_spec.rb +0 -294
- data/spec/rspec/core/memoized_helpers_spec.rb +0 -495
- data/spec/rspec/core/metadata_spec.rb +0 -491
- data/spec/rspec/core/option_parser_spec.rb +0 -262
- data/spec/rspec/core/ordering_spec.rb +0 -102
- data/spec/rspec/core/pending_example_spec.rb +0 -117
- data/spec/rspec/core/pending_spec.rb +0 -8
- data/spec/rspec/core/project_initializer_spec.rb +0 -73
- data/spec/rspec/core/rake_task_spec.rb +0 -146
- data/spec/rspec/core/random_spec.rb +0 -47
- data/spec/rspec/core/reporter_spec.rb +0 -155
- data/spec/rspec/core/resources/a_bar.rb +0 -0
- data/spec/rspec/core/resources/a_foo.rb +0 -0
- data/spec/rspec/core/resources/a_spec.rb +0 -1
- data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
- data/spec/rspec/core/resources/formatter_specs.rb +0 -58
- data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
- data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
- data/spec/rspec/core/ruby_project_spec.rb +0 -26
- data/spec/rspec/core/runner_spec.rb +0 -151
- data/spec/rspec/core/shared_context_spec.rb +0 -102
- data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -57
- data/spec/rspec/core/shared_example_group_spec.rb +0 -114
- data/spec/rspec/core/warnings_spec.rb +0 -29
- data/spec/rspec/core/world_spec.rb +0 -142
- data/spec/rspec/core_spec.rb +0 -91
- data/spec/spec_helper.rb +0 -160
- data/spec/support/config_options_helper.rb +0 -13
- data/spec/support/formatter_support.rb +0 -83
- data/spec/support/helper_methods.rb +0 -26
- data/spec/support/isolate_load_path_mutation.rb +0 -5
- data/spec/support/isolated_directory.rb +0 -10
- data/spec/support/isolated_home_directory.rb +0 -16
- data/spec/support/legacy_formatter_using_sub_classing_example.rb +0 -87
- data/spec/support/matchers.rb +0 -85
- data/spec/support/mathn_integration_support.rb +0 -12
- data/spec/support/old_style_formatter_example.rb +0 -69
- data/spec/support/shared_example_groups.rb +0 -13
- data/spec/support/spec_files.rb +0 -44
- data/spec/support/stderr_splitter.rb +0 -36
@@ -1,642 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pp'
|
3
|
-
require 'stringio'
|
4
|
-
|
5
|
-
RSpec.describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
6
|
-
let(:example_group) do
|
7
|
-
RSpec::Core::ExampleGroup.describe('group description')
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:example_instance) do
|
11
|
-
example_group.example('example description') { }
|
12
|
-
end
|
13
|
-
|
14
|
-
it_behaves_like "metadata hash builder" do
|
15
|
-
def metadata_hash(*args)
|
16
|
-
example = example_group.example('example description', *args)
|
17
|
-
example.metadata
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def capture_stdout
|
22
|
-
orig_stdout = $stdout
|
23
|
-
$stdout = StringIO.new
|
24
|
-
yield
|
25
|
-
$stdout.string
|
26
|
-
ensure
|
27
|
-
$stdout = orig_stdout
|
28
|
-
end
|
29
|
-
|
30
|
-
it "can be pretty printed" do
|
31
|
-
output = ignoring_warnings { capture_stdout { pp example_instance } }
|
32
|
-
expect(output).to include("RSpec::Core::Example")
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#exception" do
|
36
|
-
it "supplies the first exception raised, if any" do
|
37
|
-
RSpec.configuration.output_stream = StringIO.new
|
38
|
-
|
39
|
-
example = example_group.example { raise "first" }
|
40
|
-
example_group.after { raise "second" }
|
41
|
-
example_group.run
|
42
|
-
expect(example.exception.message).to eq("first")
|
43
|
-
end
|
44
|
-
|
45
|
-
it "returns nil if there is no exception" do
|
46
|
-
example = example_group.example('example') { }
|
47
|
-
example_group.run
|
48
|
-
expect(example.exception).to be_nil
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "when there is an explicit description" do
|
53
|
-
context "when RSpec.configuration.format_docstrings is set to a block" do
|
54
|
-
it "formats the description using the block" do
|
55
|
-
RSpec.configuration.format_docstrings { |s| s.strip }
|
56
|
-
example = example_group.example(' an example with whitespace ') {}
|
57
|
-
example_group.run
|
58
|
-
expect(example.description).to eql('an example with whitespace')
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "when there is no explicit description" do
|
64
|
-
def expect_with(*frameworks)
|
65
|
-
allow(RSpec.configuration).to receive(:expecting_with_rspec?).and_return(frameworks.include?(:rspec))
|
66
|
-
|
67
|
-
if frameworks.include?(:stdlib)
|
68
|
-
example_group.class_eval do
|
69
|
-
def assert(val)
|
70
|
-
raise "Expected #{val} to be true" unless val
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context "when RSpec.configuration.format_docstrings is set to a block" do
|
77
|
-
it "formats the description using the block" do
|
78
|
-
RSpec.configuration.format_docstrings { |s| s.upcase }
|
79
|
-
example_group.example { expect(5).to eq(5) }
|
80
|
-
example_group.run
|
81
|
-
pattern = /EXAMPLE AT #{relative_path(__FILE__).upcase}:#{__LINE__ - 2}/
|
82
|
-
expect(example_group.examples.first.description).to match(pattern)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "when `expect_with :rspec` is configured" do
|
87
|
-
before(:each) { expect_with :rspec }
|
88
|
-
|
89
|
-
it "uses the matcher-generated description" do
|
90
|
-
example_group.example { expect(5).to eq(5) }
|
91
|
-
example_group.run
|
92
|
-
expect(example_group.examples.first.description).to eq("should eq 5")
|
93
|
-
end
|
94
|
-
|
95
|
-
it "uses the matcher-generated description in the full description" do
|
96
|
-
example_group.example { expect(5).to eq(5) }
|
97
|
-
example_group.run
|
98
|
-
expect(example_group.examples.first.full_description).to eq("group description should eq 5")
|
99
|
-
end
|
100
|
-
|
101
|
-
it "uses the file and line number if there is no matcher-generated description" do
|
102
|
-
example = example_group.example {}
|
103
|
-
example_group.run
|
104
|
-
expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "uses the file and line number if there is an error before the matcher" do
|
108
|
-
example = example_group.example { expect(5).to eq(5) }
|
109
|
-
example_group.before { raise }
|
110
|
-
example_group.run
|
111
|
-
expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 3}/)
|
112
|
-
end
|
113
|
-
|
114
|
-
context "if the example is pending" do
|
115
|
-
it "still uses the matcher-generated description if a matcher ran" do
|
116
|
-
example = example_group.example { pending; expect(4).to eq(5) }
|
117
|
-
example_group.run
|
118
|
-
expect(example.description).to eq("should eq 5")
|
119
|
-
end
|
120
|
-
|
121
|
-
it "uses the file and line number of the example if no matcher ran" do
|
122
|
-
example = example_group.example { pending; fail }
|
123
|
-
example_group.run
|
124
|
-
expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context "when `expect_with :rspec, :stdlib` is configured" do
|
130
|
-
before(:each) { expect_with :rspec, :stdlib }
|
131
|
-
|
132
|
-
it "uses the matcher-generated description" do
|
133
|
-
example_group.example { expect(5).to eq(5) }
|
134
|
-
example_group.run
|
135
|
-
expect(example_group.examples.first.description).to eq("should eq 5")
|
136
|
-
end
|
137
|
-
|
138
|
-
it "uses the file and line number if there is no matcher-generated description" do
|
139
|
-
example = example_group.example {}
|
140
|
-
example_group.run
|
141
|
-
expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "uses the file and line number if there is an error before the matcher" do
|
145
|
-
example = example_group.example { expect(5).to eq(5) }
|
146
|
-
example_group.before { raise }
|
147
|
-
example_group.run
|
148
|
-
expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 3}/)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context "when `expect_with :stdlib` is configured" do
|
153
|
-
before(:each) { expect_with :stdlib }
|
154
|
-
|
155
|
-
it "does not attempt to get the generated description from RSpec::Matchers" do
|
156
|
-
expect(RSpec::Matchers).not_to receive(:generated_description)
|
157
|
-
example_group.example { assert 5 == 5 }
|
158
|
-
example_group.run
|
159
|
-
end
|
160
|
-
|
161
|
-
it "uses the file and line number" do
|
162
|
-
example = example_group.example { assert 5 == 5 }
|
163
|
-
example_group.run
|
164
|
-
expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
describe "#described_class" do
|
170
|
-
it "returns the class (if any) of the outermost example group" do
|
171
|
-
expect(described_class).to eq(RSpec::Core::Example)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
describe "accessing metadata within a running example" do
|
176
|
-
it "has a reference to itself when running" do |ex|
|
177
|
-
expect(ex.description).to eq("has a reference to itself when running")
|
178
|
-
end
|
179
|
-
|
180
|
-
it "can access the example group's top level metadata as if it were its own" do |ex|
|
181
|
-
expect(ex.example_group.metadata).to include(:parent_metadata => 'sample')
|
182
|
-
expect(ex.metadata).to include(:parent_metadata => 'sample')
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
describe "accessing options within a running example" do
|
187
|
-
it "can look up option values by key", :demo => :data do |ex|
|
188
|
-
expect(ex.metadata[:demo]).to eq(:data)
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
describe "#run" do
|
193
|
-
it "sets its reference to the example group instance to nil" do
|
194
|
-
group = RSpec::Core::ExampleGroup.describe do
|
195
|
-
example('example') { expect(1).to eq(1) }
|
196
|
-
end
|
197
|
-
group.run
|
198
|
-
expect(group.examples.first.instance_variable_get("@example_group_instance")).to be_nil
|
199
|
-
end
|
200
|
-
|
201
|
-
it "runs after(:each) when the example passes" do
|
202
|
-
after_run = false
|
203
|
-
group = RSpec::Core::ExampleGroup.describe do
|
204
|
-
after(:each) { after_run = true }
|
205
|
-
example('example') { expect(1).to eq(1) }
|
206
|
-
end
|
207
|
-
group.run
|
208
|
-
expect(after_run).to be_truthy, "expected after(:each) to be run"
|
209
|
-
end
|
210
|
-
|
211
|
-
it "runs after(:each) when the example fails" do
|
212
|
-
after_run = false
|
213
|
-
group = RSpec::Core::ExampleGroup.describe do
|
214
|
-
after(:each) { after_run = true }
|
215
|
-
example('example') { expect(1).to eq(2) }
|
216
|
-
end
|
217
|
-
group.run
|
218
|
-
expect(after_run).to be_truthy, "expected after(:each) to be run"
|
219
|
-
end
|
220
|
-
|
221
|
-
it "runs after(:each) when the example raises an Exception" do
|
222
|
-
after_run = false
|
223
|
-
group = RSpec::Core::ExampleGroup.describe do
|
224
|
-
after(:each) { after_run = true }
|
225
|
-
example('example') { raise "this error" }
|
226
|
-
end
|
227
|
-
group.run
|
228
|
-
expect(after_run).to be_truthy, "expected after(:each) to be run"
|
229
|
-
end
|
230
|
-
|
231
|
-
context "with an after(:each) that raises" do
|
232
|
-
it "runs subsequent after(:each)'s" do
|
233
|
-
after_run = false
|
234
|
-
group = RSpec::Core::ExampleGroup.describe do
|
235
|
-
after(:each) { after_run = true }
|
236
|
-
after(:each) { raise "FOO" }
|
237
|
-
example('example') { expect(1).to eq(1) }
|
238
|
-
end
|
239
|
-
group.run
|
240
|
-
expect(after_run).to be_truthy, "expected after(:each) to be run"
|
241
|
-
end
|
242
|
-
|
243
|
-
it "stores the exception" do
|
244
|
-
group = RSpec::Core::ExampleGroup.describe
|
245
|
-
group.after(:each) { raise "FOO" }
|
246
|
-
example = group.example('example') { expect(1).to eq(1) }
|
247
|
-
|
248
|
-
group.run
|
249
|
-
|
250
|
-
expect(example.metadata[:execution_result][:exception].message).to eq("FOO")
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
it "wraps before/after(:each) inside around" do
|
255
|
-
results = []
|
256
|
-
group = RSpec::Core::ExampleGroup.describe do
|
257
|
-
around(:each) do |e|
|
258
|
-
results << "around (before)"
|
259
|
-
e.run
|
260
|
-
results << "around (after)"
|
261
|
-
end
|
262
|
-
before(:each) { results << "before" }
|
263
|
-
after(:each) { results << "after" }
|
264
|
-
example { results << "example" }
|
265
|
-
end
|
266
|
-
|
267
|
-
group.run
|
268
|
-
expect(results).to eq([
|
269
|
-
"around (before)",
|
270
|
-
"before",
|
271
|
-
"example",
|
272
|
-
"after",
|
273
|
-
"around (after)"
|
274
|
-
])
|
275
|
-
end
|
276
|
-
|
277
|
-
context "clearing ivars" do
|
278
|
-
it "sets ivars to nil to prep them for GC" do
|
279
|
-
group = RSpec::Core::ExampleGroup.describe do
|
280
|
-
before(:all) { @before_all = :before_all }
|
281
|
-
before(:each) { @before_each = :before_each }
|
282
|
-
after(:each) { @after_each = :after_each }
|
283
|
-
after(:all) { @after_all = :after_all }
|
284
|
-
end
|
285
|
-
group.example("does something") do
|
286
|
-
expect(@before_all).to eq(:before_all)
|
287
|
-
expect(@before_each).to eq(:before_each)
|
288
|
-
end
|
289
|
-
expect(group.run(double.as_null_object)).to be_truthy
|
290
|
-
group.new do |example|
|
291
|
-
%w[@before_all @before_each @after_each @after_all].each do |ivar|
|
292
|
-
expect(example.instance_variable_get(ivar)).to be_nil
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
it "does not impact the before_all_ivars which are copied to each example" do
|
298
|
-
group = RSpec::Core::ExampleGroup.describe do
|
299
|
-
before(:all) { @before_all = "abc" }
|
300
|
-
example("first") { expect(@before_all).not_to be_nil }
|
301
|
-
example("second") { expect(@before_all).not_to be_nil }
|
302
|
-
end
|
303
|
-
expect(group.run).to be_truthy
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
context 'when the example raises an error' do
|
308
|
-
def run_and_capture_reported_message(group)
|
309
|
-
reported_msg = nil
|
310
|
-
# We can't use should_receive(:message).with(/.../) here,
|
311
|
-
# because if that fails, it would fail within our example-under-test,
|
312
|
-
# and since there's already two errors, it would just be reported again.
|
313
|
-
allow(RSpec.configuration.reporter).to receive(:message) { |msg| reported_msg = msg }
|
314
|
-
group.run
|
315
|
-
reported_msg
|
316
|
-
end
|
317
|
-
|
318
|
-
it "prints any around hook errors rather than silencing them" do
|
319
|
-
group = RSpec::Core::ExampleGroup.describe do
|
320
|
-
around(:each) { |e| e.run; raise "around" }
|
321
|
-
example("e") { raise "example" }
|
322
|
-
end
|
323
|
-
|
324
|
-
message = run_and_capture_reported_message(group)
|
325
|
-
expect(message).to match(/An error occurred in an around.* hook/i)
|
326
|
-
end
|
327
|
-
|
328
|
-
it "prints any after hook errors rather than silencing them" do
|
329
|
-
group = RSpec::Core::ExampleGroup.describe do
|
330
|
-
after(:each) { raise "after" }
|
331
|
-
example("e") { raise "example" }
|
332
|
-
end
|
333
|
-
|
334
|
-
message = run_and_capture_reported_message(group)
|
335
|
-
expect(message).to match(/An error occurred in an after.* hook/i)
|
336
|
-
end
|
337
|
-
|
338
|
-
it "does not print mock expectation errors" do
|
339
|
-
group = RSpec::Core::ExampleGroup.describe do
|
340
|
-
example do
|
341
|
-
foo = double
|
342
|
-
expect(foo).to receive(:bar)
|
343
|
-
raise "boom"
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
message = run_and_capture_reported_message(group)
|
348
|
-
expect(message).to be_nil
|
349
|
-
end
|
350
|
-
|
351
|
-
it "leaves a raised exception unmodified (GH-1103)" do
|
352
|
-
# set the backtrace, otherwise MRI will build a whole new object,
|
353
|
-
# and thus mess with our expectations. Rubinius and JRuby are not
|
354
|
-
# affected.
|
355
|
-
exception = StandardError.new
|
356
|
-
exception.set_backtrace([])
|
357
|
-
|
358
|
-
group = RSpec::Core::ExampleGroup.describe do
|
359
|
-
example { raise exception.freeze }
|
360
|
-
end
|
361
|
-
group.run
|
362
|
-
|
363
|
-
actual = group.examples.first.metadata[:execution_result][:exception]
|
364
|
-
expect(actual.__id__).to eq(exception.__id__)
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
context "with --dry-run" do
|
369
|
-
before { RSpec.configuration.dry_run = true }
|
370
|
-
|
371
|
-
it "does not execute any examples or hooks" do
|
372
|
-
executed = []
|
373
|
-
|
374
|
-
RSpec.configure do |c|
|
375
|
-
c.before(:each) { executed << :before_each_config }
|
376
|
-
c.before(:all) { executed << :before_all_config }
|
377
|
-
c.after(:each) { executed << :after_each_config }
|
378
|
-
c.after(:all) { executed << :after_all_config }
|
379
|
-
c.around(:each) { |ex| executed << :around_each_config; ex.run }
|
380
|
-
end
|
381
|
-
|
382
|
-
group = RSpec::Core::ExampleGroup.describe do
|
383
|
-
before(:all) { executed << :before_all }
|
384
|
-
before(:each) { executed << :before_each }
|
385
|
-
after(:all) { executed << :after_all }
|
386
|
-
after(:each) { executed << :after_each }
|
387
|
-
around(:each) { |ex| executed << :around_each; ex.run }
|
388
|
-
|
389
|
-
example { executed << :example }
|
390
|
-
|
391
|
-
context "nested" do
|
392
|
-
before(:all) { executed << :nested_before_all }
|
393
|
-
before(:each) { executed << :nested_before_each }
|
394
|
-
after(:all) { executed << :nested_after_all }
|
395
|
-
after(:each) { executed << :nested_after_each }
|
396
|
-
around(:each) { |ex| executed << :nested_around_each; ex.run }
|
397
|
-
|
398
|
-
example { executed << :nested_example }
|
399
|
-
end
|
400
|
-
end
|
401
|
-
|
402
|
-
group.run
|
403
|
-
expect(executed).to eq([])
|
404
|
-
end
|
405
|
-
end
|
406
|
-
end
|
407
|
-
|
408
|
-
describe "#pending" do
|
409
|
-
def expect_pending_result(example)
|
410
|
-
expect(example).to be_pending
|
411
|
-
expect(example.metadata[:execution_result][:status]).to eq("pending")
|
412
|
-
expect(example.metadata[:execution_result][:pending_message]).to be
|
413
|
-
end
|
414
|
-
|
415
|
-
context "in the example" do
|
416
|
-
it "sets the example to pending" do
|
417
|
-
group = RSpec::Core::ExampleGroup.describe do
|
418
|
-
example { pending; fail }
|
419
|
-
end
|
420
|
-
group.run
|
421
|
-
expect_pending_result(group.examples.first)
|
422
|
-
end
|
423
|
-
|
424
|
-
it "allows post-example processing in around hooks (see https://github.com/rspec/rspec-core/issues/322)" do
|
425
|
-
blah = nil
|
426
|
-
group = RSpec::Core::ExampleGroup.describe do
|
427
|
-
around do |example|
|
428
|
-
example.run
|
429
|
-
blah = :success
|
430
|
-
end
|
431
|
-
example { pending }
|
432
|
-
end
|
433
|
-
group.run
|
434
|
-
expect(blah).to be(:success)
|
435
|
-
end
|
436
|
-
|
437
|
-
it 'sets the backtrace to the example definition so it can be located by the user' do
|
438
|
-
expected = [__FILE__, __LINE__ + 2].map(&:to_s)
|
439
|
-
group = RSpec::Core::ExampleGroup.describe do
|
440
|
-
example {
|
441
|
-
pending
|
442
|
-
}
|
443
|
-
end
|
444
|
-
group.run
|
445
|
-
# TODO: De-dup this logic in rspec-support
|
446
|
-
actual = group.examples.first.exception.backtrace.
|
447
|
-
find { |line| line !~ RSpec::CallerFilter::LIB_REGEX }.
|
448
|
-
split(':')[0..1]
|
449
|
-
expect(actual).to eq(expected)
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
context "in before(:each)" do
|
454
|
-
it "sets each example to pending" do
|
455
|
-
group = RSpec::Core::ExampleGroup.describe do
|
456
|
-
before(:each) { pending }
|
457
|
-
example { fail }
|
458
|
-
example { fail }
|
459
|
-
end
|
460
|
-
group.run
|
461
|
-
expect_pending_result(group.examples.first)
|
462
|
-
expect_pending_result(group.examples.last)
|
463
|
-
end
|
464
|
-
|
465
|
-
it 'sets example to pending when failure occurs in before(:each)' do
|
466
|
-
group = RSpec::Core::ExampleGroup.describe do
|
467
|
-
before(:each) { pending; fail }
|
468
|
-
example {}
|
469
|
-
end
|
470
|
-
group.run
|
471
|
-
expect_pending_result(group.examples.first)
|
472
|
-
end
|
473
|
-
end
|
474
|
-
|
475
|
-
context "in before(:all)" do
|
476
|
-
it "is forbidden" do
|
477
|
-
group = RSpec::Core::ExampleGroup.describe do
|
478
|
-
before(:all) { pending }
|
479
|
-
example { fail }
|
480
|
-
example { fail }
|
481
|
-
end
|
482
|
-
group.run
|
483
|
-
expect(group.examples.first.exception).to be
|
484
|
-
expect(group.examples.first.exception.message).to \
|
485
|
-
match(/may not be used outside of examples/)
|
486
|
-
end
|
487
|
-
end
|
488
|
-
|
489
|
-
context "in around(:each)" do
|
490
|
-
it "sets the example to pending" do
|
491
|
-
group = RSpec::Core::ExampleGroup.describe do
|
492
|
-
around(:each) { pending }
|
493
|
-
example { fail }
|
494
|
-
end
|
495
|
-
group.run
|
496
|
-
expect_pending_result(group.examples.first)
|
497
|
-
end
|
498
|
-
|
499
|
-
it 'sets example to pending when failure occurs in around(:each)' do
|
500
|
-
group = RSpec::Core::ExampleGroup.describe do
|
501
|
-
around(:each) { pending; fail }
|
502
|
-
example {}
|
503
|
-
end
|
504
|
-
group.run
|
505
|
-
expect_pending_result(group.examples.first)
|
506
|
-
end
|
507
|
-
end
|
508
|
-
|
509
|
-
context "in after(:each)" do
|
510
|
-
it "sets each example to pending" do
|
511
|
-
group = RSpec::Core::ExampleGroup.describe do
|
512
|
-
after(:each) { pending; fail }
|
513
|
-
example { }
|
514
|
-
example { }
|
515
|
-
end
|
516
|
-
group.run
|
517
|
-
expect_pending_result(group.examples.first)
|
518
|
-
expect_pending_result(group.examples.last)
|
519
|
-
end
|
520
|
-
end
|
521
|
-
|
522
|
-
end
|
523
|
-
|
524
|
-
describe "#skip" do
|
525
|
-
context "in the example" do
|
526
|
-
it "sets the example to skipped" do
|
527
|
-
group = RSpec::Core::ExampleGroup.describe do
|
528
|
-
example { skip }
|
529
|
-
end
|
530
|
-
group.run
|
531
|
-
expect(group.examples.first).to be_skipped
|
532
|
-
end
|
533
|
-
|
534
|
-
it "allows post-example processing in around hooks (see https://github.com/rspec/rspec-core/issues/322)" do
|
535
|
-
blah = nil
|
536
|
-
group = RSpec::Core::ExampleGroup.describe do
|
537
|
-
around do |example|
|
538
|
-
example.run
|
539
|
-
blah = :success
|
540
|
-
end
|
541
|
-
example { skip }
|
542
|
-
end
|
543
|
-
group.run
|
544
|
-
expect(blah).to be(:success)
|
545
|
-
end
|
546
|
-
|
547
|
-
context "with a message" do
|
548
|
-
it "sets the example to skipped with the provided message" do
|
549
|
-
group = RSpec::Core::ExampleGroup.describe do
|
550
|
-
example { skip "lorem ipsum" }
|
551
|
-
end
|
552
|
-
group.run
|
553
|
-
expect(group.examples.first).to be_skipped_with("lorem ipsum")
|
554
|
-
end
|
555
|
-
end
|
556
|
-
end
|
557
|
-
|
558
|
-
context "in before(:each)" do
|
559
|
-
it "sets each example to skipped" do
|
560
|
-
group = RSpec::Core::ExampleGroup.describe do
|
561
|
-
before(:each) { skip }
|
562
|
-
example {}
|
563
|
-
example {}
|
564
|
-
end
|
565
|
-
group.run
|
566
|
-
expect(group.examples.first).to be_skipped
|
567
|
-
expect(group.examples.last).to be_skipped
|
568
|
-
end
|
569
|
-
end
|
570
|
-
|
571
|
-
context "in before(:all)" do
|
572
|
-
it "sets each example to pending" do
|
573
|
-
group = RSpec::Core::ExampleGroup.describe do
|
574
|
-
before(:all) { skip("not done"); fail }
|
575
|
-
example {}
|
576
|
-
example {}
|
577
|
-
end
|
578
|
-
group.run
|
579
|
-
expect(group.examples.first).to be_skipped_with("not done")
|
580
|
-
expect(group.examples.last).to be_skipped_with("not done")
|
581
|
-
end
|
582
|
-
end
|
583
|
-
|
584
|
-
context "in around(:each)" do
|
585
|
-
it "sets the example to skipped" do
|
586
|
-
group = RSpec::Core::ExampleGroup.describe do
|
587
|
-
around(:each) { skip }
|
588
|
-
example {}
|
589
|
-
end
|
590
|
-
group.run
|
591
|
-
expect(group.examples.first).to be_skipped
|
592
|
-
end
|
593
|
-
end
|
594
|
-
end
|
595
|
-
|
596
|
-
describe "timing" do
|
597
|
-
it "uses RSpec::Core::Time as to not be affected by changes to time in examples" do
|
598
|
-
reporter = double(:reporter).as_null_object
|
599
|
-
group = RSpec::Core::ExampleGroup.describe
|
600
|
-
example = group.example
|
601
|
-
example.__send__ :start, reporter
|
602
|
-
allow(Time).to receive_messages(:now => Time.utc(2012, 10, 1))
|
603
|
-
example.__send__ :finish, reporter
|
604
|
-
expect(example.metadata[:execution_result][:run_time]).to be < 0.2
|
605
|
-
end
|
606
|
-
end
|
607
|
-
|
608
|
-
it "does not interfere with per-example randomness when running examples in a random order" do
|
609
|
-
values = []
|
610
|
-
|
611
|
-
RSpec.configuration.order = :random
|
612
|
-
|
613
|
-
RSpec::Core::ExampleGroup.describe do
|
614
|
-
# The bug was only triggered when the examples
|
615
|
-
# were in nested contexts; see https://github.com/rspec/rspec-core/pull/837
|
616
|
-
context { example { values << rand } }
|
617
|
-
context { example { values << rand } }
|
618
|
-
end.run
|
619
|
-
|
620
|
-
expect(values.uniq.count).to eq(2)
|
621
|
-
end
|
622
|
-
|
623
|
-
describe "optional block argument" do
|
624
|
-
it "contains the example" do |ex|
|
625
|
-
expect(ex).to be_an(RSpec::Core::Example)
|
626
|
-
expect(ex.description).to match(/contains the example/)
|
627
|
-
end
|
628
|
-
end
|
629
|
-
|
630
|
-
describe "setting the current example" do
|
631
|
-
it "sets RSpec.current_example to the example that is currently running" do
|
632
|
-
group = RSpec::Core::ExampleGroup.describe("an example group")
|
633
|
-
|
634
|
-
current_examples = []
|
635
|
-
example1 = group.example("example 1") { current_examples << RSpec.current_example }
|
636
|
-
example2 = group.example("example 2") { current_examples << RSpec.current_example }
|
637
|
-
|
638
|
-
group.run
|
639
|
-
expect(current_examples).to eq([example1, example2])
|
640
|
-
end
|
641
|
-
end
|
642
|
-
end
|