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,1479 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'tmpdir'
|
3
|
-
|
4
|
-
module RSpec::Core
|
5
|
-
|
6
|
-
RSpec.describe Configuration do
|
7
|
-
|
8
|
-
let(:config) { Configuration.new }
|
9
|
-
|
10
|
-
describe '#deprecation_stream' do
|
11
|
-
it 'defaults to standard error' do
|
12
|
-
expect($rspec_core_without_stderr_monkey_patch.deprecation_stream).to eq STDERR
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'is configurable' do
|
16
|
-
io = double 'deprecation io'
|
17
|
-
config.deprecation_stream = io
|
18
|
-
expect(config.deprecation_stream).to eq io
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "#output_stream" do
|
23
|
-
it 'defaults to standard output' do
|
24
|
-
expect(config.output_stream).to eq $stdout
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'is configurable' do
|
28
|
-
io = double 'output io'
|
29
|
-
config.output_stream = io
|
30
|
-
expect(config.output_stream).to eq io
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'when the reporter has already been initialized' do
|
34
|
-
before do
|
35
|
-
config.reporter
|
36
|
-
allow(config).to receive(:warn)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'prints a notice indicating the reconfigured output_stream will be ignored' do
|
40
|
-
config.output_stream = StringIO.new
|
41
|
-
expect(config).to have_received(:warn).with(/output_stream.*#{__FILE__}:#{__LINE__ - 1}/)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'does not change the value of `output_stream`' do
|
45
|
-
config.output_stream = StringIO.new
|
46
|
-
expect(config.output_stream).to eq($stdout)
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'does not print a warning if set to the value it already has' do
|
50
|
-
config.output_stream = config.output_stream
|
51
|
-
expect(config).not_to have_received(:warn)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "#requires=" do
|
57
|
-
include_context "isolate load path mutation"
|
58
|
-
|
59
|
-
def absolute_path_to(dir)
|
60
|
-
File.expand_path("../../../../#{dir}", __FILE__)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'adds `lib` to the load path' do
|
64
|
-
lib_dir = absolute_path_to("lib")
|
65
|
-
$LOAD_PATH.delete(lib_dir)
|
66
|
-
|
67
|
-
expect($LOAD_PATH).not_to include(lib_dir)
|
68
|
-
config.requires = []
|
69
|
-
expect($LOAD_PATH).to include(lib_dir)
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'adds the configured `default_path` to the load path' do
|
73
|
-
config.default_path = 'features'
|
74
|
-
foo_dir = absolute_path_to("features")
|
75
|
-
|
76
|
-
expect($LOAD_PATH).not_to include(foo_dir)
|
77
|
-
config.requires = []
|
78
|
-
expect($LOAD_PATH).to include(foo_dir)
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'stores the required files' do
|
82
|
-
expect(config).to receive(:require).with('a/path')
|
83
|
-
config.requires = ['a/path']
|
84
|
-
expect(config.requires).to eq ['a/path']
|
85
|
-
end
|
86
|
-
|
87
|
-
context "when `default_path` refers to a file rather than a directory" do
|
88
|
-
it 'does not add it to the load path' do
|
89
|
-
config.default_path = 'Rakefile'
|
90
|
-
config.requires = []
|
91
|
-
expect($LOAD_PATH).not_to include(match(/Rakefile/))
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "#load_spec_files" do
|
97
|
-
it "loads files using load" do
|
98
|
-
config.files_to_run = ["foo.bar", "blah_spec.rb"]
|
99
|
-
expect(config).to receive(:load).twice
|
100
|
-
config.load_spec_files
|
101
|
-
end
|
102
|
-
|
103
|
-
it "loads each file once, even if duplicated in list" do
|
104
|
-
config.files_to_run = ["a_spec.rb", "a_spec.rb"]
|
105
|
-
expect(config).to receive(:load).once
|
106
|
-
config.load_spec_files
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe "#mock_framework" do
|
111
|
-
it "defaults to :rspec" do
|
112
|
-
expect(config).to receive(:require).with('rspec/core/mocking_adapters/rspec')
|
113
|
-
config.mock_framework
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "#mock_framework="do
|
118
|
-
it "delegates to mock_with" do
|
119
|
-
expect(config).to receive(:mock_with).with(:rspec)
|
120
|
-
config.mock_framework = :rspec
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
shared_examples "a configurable framework adapter" do |m|
|
125
|
-
it "yields a config object if the framework_module supports it" do
|
126
|
-
custom_config = Struct.new(:custom_setting).new
|
127
|
-
mod = Module.new
|
128
|
-
allow(mod).to receive_messages(:configuration => custom_config)
|
129
|
-
|
130
|
-
config.send m, mod do |mod_config|
|
131
|
-
mod_config.custom_setting = true
|
132
|
-
end
|
133
|
-
|
134
|
-
expect(custom_config.custom_setting).to be_truthy
|
135
|
-
end
|
136
|
-
|
137
|
-
it "raises if framework module doesn't support configuration" do
|
138
|
-
mod = Module.new
|
139
|
-
|
140
|
-
expect {
|
141
|
-
config.send m, mod do |mod_config|
|
142
|
-
end
|
143
|
-
}.to raise_error(/must respond to `configuration`/)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe "#mock_with" do
|
148
|
-
before { allow(config).to receive(:require) }
|
149
|
-
|
150
|
-
it_behaves_like "a configurable framework adapter", :mock_with
|
151
|
-
|
152
|
-
it "allows rspec-mocks to be configured with a provided block" do
|
153
|
-
mod = Module.new
|
154
|
-
|
155
|
-
expect(RSpec::Mocks.configuration).to receive(:add_stub_and_should_receive_to).with(mod)
|
156
|
-
|
157
|
-
config.mock_with :rspec do |c|
|
158
|
-
c.add_stub_and_should_receive_to mod
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context "with a module" do
|
163
|
-
it "sets the mock_framework_adapter to that module" do
|
164
|
-
mod = Module.new
|
165
|
-
config.mock_with mod
|
166
|
-
expect(config.mock_framework).to eq(mod)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'uses the named adapter' do
|
171
|
-
expect(config).to receive(:require).with("rspec/core/mocking_adapters/mocha")
|
172
|
-
stub_const("RSpec::Core::MockingAdapters::Mocha", Module.new)
|
173
|
-
config.mock_with :mocha
|
174
|
-
end
|
175
|
-
|
176
|
-
it "uses the null adapter when given :nothing" do
|
177
|
-
expect(config).to receive(:require).with('rspec/core/mocking_adapters/null').and_call_original
|
178
|
-
config.mock_with :nothing
|
179
|
-
end
|
180
|
-
|
181
|
-
it "raises an error when given an unknown key" do
|
182
|
-
expect {
|
183
|
-
config.mock_with :crazy_new_mocking_framework_ive_not_yet_heard_of
|
184
|
-
}.to raise_error(ArgumentError, /unknown mocking framework/i)
|
185
|
-
end
|
186
|
-
|
187
|
-
it "raises an error when given another type of object" do
|
188
|
-
expect {
|
189
|
-
config.mock_with Object.new
|
190
|
-
}.to raise_error(ArgumentError, /unknown mocking framework/i)
|
191
|
-
end
|
192
|
-
|
193
|
-
context 'when there are already some example groups defined' do
|
194
|
-
it 'raises an error since this setting must be applied before any groups are defined' do
|
195
|
-
allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object])
|
196
|
-
stub_const("RSpec::Core::MockingAdapters::Mocha", double(:framework_name => :mocha))
|
197
|
-
expect {
|
198
|
-
config.mock_with :mocha
|
199
|
-
}.to raise_error(/must be configured before any example groups are defined/)
|
200
|
-
end
|
201
|
-
|
202
|
-
it 'does not raise an error if the default `mock_with :rspec` is re-configured' do
|
203
|
-
config.mock_framework # called by RSpec when configuring the first example group
|
204
|
-
allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object])
|
205
|
-
config.mock_with :rspec
|
206
|
-
end
|
207
|
-
|
208
|
-
it 'does not raise an error if re-setting the same config' do
|
209
|
-
stub_const("RSpec::Core::MockingAdapters::Mocha", double(:framework_name => :mocha))
|
210
|
-
groups = []
|
211
|
-
allow(RSpec.world).to receive_messages(:example_groups => groups)
|
212
|
-
config.mock_with :mocha
|
213
|
-
groups << double.as_null_object
|
214
|
-
config.mock_with :mocha
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
describe "#expectation_framework" do
|
220
|
-
it "defaults to :rspec" do
|
221
|
-
expect(config).to receive(:require).with('rspec/expectations')
|
222
|
-
config.expectation_frameworks
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
describe "#expectation_framework=" do
|
227
|
-
it "delegates to expect_with=" do
|
228
|
-
expect(config).to receive(:expect_with).with(:rspec)
|
229
|
-
config.expectation_framework = :rspec
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
describe "#expect_with" do
|
234
|
-
before do
|
235
|
-
stub_const("Test::Unit::Assertions", Module.new)
|
236
|
-
allow(config).to receive(:require)
|
237
|
-
end
|
238
|
-
|
239
|
-
it_behaves_like "a configurable framework adapter", :expect_with
|
240
|
-
|
241
|
-
[
|
242
|
-
[:rspec, 'rspec/expectations'],
|
243
|
-
[:stdlib, 'test/unit/assertions']
|
244
|
-
].each do |framework, required_file|
|
245
|
-
context "with #{framework}" do
|
246
|
-
it "requires #{required_file}" do
|
247
|
-
expect(config).to receive(:require).with(required_file)
|
248
|
-
config.expect_with framework
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
it "supports multiple calls" do
|
254
|
-
config.expect_with :rspec
|
255
|
-
config.expect_with :stdlib
|
256
|
-
expect(config.expectation_frameworks).to eq [RSpec::Matchers, Test::Unit::Assertions]
|
257
|
-
end
|
258
|
-
|
259
|
-
it "raises if block given with multiple args" do
|
260
|
-
expect {
|
261
|
-
config.expect_with :rspec, :stdlib do |mod_config|
|
262
|
-
end
|
263
|
-
}.to raise_error(/expect_with only accepts/)
|
264
|
-
end
|
265
|
-
|
266
|
-
it "raises ArgumentError if framework is not supported" do
|
267
|
-
expect do
|
268
|
-
config.expect_with :not_supported
|
269
|
-
end.to raise_error(ArgumentError)
|
270
|
-
end
|
271
|
-
|
272
|
-
context 'when there are already some example groups defined' do
|
273
|
-
it 'raises an error since this setting must be applied before any groups are defined' do
|
274
|
-
allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object])
|
275
|
-
expect {
|
276
|
-
config.expect_with :rspec
|
277
|
-
}.to raise_error(/must be configured before any example groups are defined/)
|
278
|
-
end
|
279
|
-
|
280
|
-
it 'does not raise an error if the default `expect_with :rspec` is re-configured' do
|
281
|
-
config.expectation_frameworks # called by RSpec when configuring the first example group
|
282
|
-
allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object])
|
283
|
-
config.expect_with :rspec
|
284
|
-
end
|
285
|
-
|
286
|
-
it 'does not raise an error if re-setting the same config' do
|
287
|
-
groups = []
|
288
|
-
allow(RSpec.world).to receive_messages(:example_groups => groups)
|
289
|
-
config.expect_with :stdlib
|
290
|
-
groups << double.as_null_object
|
291
|
-
config.expect_with :stdlib
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
describe "#expecting_with_rspec?" do
|
297
|
-
before do
|
298
|
-
stub_const("Test::Unit::Assertions", Module.new)
|
299
|
-
allow(config).to receive(:require)
|
300
|
-
end
|
301
|
-
|
302
|
-
it "returns false by default" do
|
303
|
-
expect(config).not_to be_expecting_with_rspec
|
304
|
-
end
|
305
|
-
|
306
|
-
it "returns true when `expect_with :rspec` has been configured" do
|
307
|
-
config.expect_with :rspec
|
308
|
-
expect(config).to be_expecting_with_rspec
|
309
|
-
end
|
310
|
-
|
311
|
-
it "returns true when `expect_with :rspec, :stdlib` has been configured" do
|
312
|
-
config.expect_with :rspec, :stdlib
|
313
|
-
expect(config).to be_expecting_with_rspec
|
314
|
-
end
|
315
|
-
|
316
|
-
it "returns true when `expect_with :stdlib, :rspec` has been configured" do
|
317
|
-
config.expect_with :stdlib, :rspec
|
318
|
-
expect(config).to be_expecting_with_rspec
|
319
|
-
end
|
320
|
-
|
321
|
-
it "returns false when `expect_with :stdlib` has been configured" do
|
322
|
-
config.expect_with :stdlib
|
323
|
-
expect(config).not_to be_expecting_with_rspec
|
324
|
-
end
|
325
|
-
end
|
326
|
-
|
327
|
-
describe "#files_to_run" do
|
328
|
-
it "loads files not following pattern if named explicitly" do
|
329
|
-
assign_files_or_directories_to_run "spec/rspec/core/resources/a_bar.rb"
|
330
|
-
expect(config.files_to_run).to eq([ "spec/rspec/core/resources/a_bar.rb"])
|
331
|
-
end
|
332
|
-
|
333
|
-
it "prevents repetition of dir when start of the pattern" do
|
334
|
-
config.pattern = "spec/**/a_spec.rb"
|
335
|
-
assign_files_or_directories_to_run "spec"
|
336
|
-
expect(config.files_to_run).to eq(["spec/rspec/core/resources/a_spec.rb"])
|
337
|
-
end
|
338
|
-
|
339
|
-
it "does not prevent repetition of dir when later of the pattern" do
|
340
|
-
config.pattern = "rspec/**/a_spec.rb"
|
341
|
-
assign_files_or_directories_to_run "spec"
|
342
|
-
expect(config.files_to_run).to eq(["spec/rspec/core/resources/a_spec.rb"])
|
343
|
-
end
|
344
|
-
|
345
|
-
it 'reloads when `files_or_directories_to_run` is reassigned' do
|
346
|
-
config.pattern = "spec/**/a_spec.rb"
|
347
|
-
config.files_or_directories_to_run = "empty_dir"
|
348
|
-
|
349
|
-
expect {
|
350
|
-
config.files_or_directories_to_run = "spec"
|
351
|
-
}.to change { config.files_to_run }.
|
352
|
-
to(["spec/rspec/core/resources/a_spec.rb"])
|
353
|
-
end
|
354
|
-
|
355
|
-
context "with <path>:<line_number>" do
|
356
|
-
it "overrides inclusion filters set on config" do
|
357
|
-
config.filter_run_including :foo => :bar
|
358
|
-
assign_files_or_directories_to_run "path/to/file.rb:37"
|
359
|
-
expect(config.inclusion_filter.size).to eq(1)
|
360
|
-
expect(config.inclusion_filter[:locations].keys.first).to match(/path\/to\/file\.rb$/)
|
361
|
-
expect(config.inclusion_filter[:locations].values.first).to eq([37])
|
362
|
-
end
|
363
|
-
|
364
|
-
it "overrides inclusion filters set before config" do
|
365
|
-
config.force(:inclusion_filter => {:foo => :bar})
|
366
|
-
assign_files_or_directories_to_run "path/to/file.rb:37"
|
367
|
-
expect(config.inclusion_filter.size).to eq(1)
|
368
|
-
expect(config.inclusion_filter[:locations].keys.first).to match(/path\/to\/file\.rb$/)
|
369
|
-
expect(config.inclusion_filter[:locations].values.first).to eq([37])
|
370
|
-
end
|
371
|
-
|
372
|
-
it "clears exclusion filters set on config" do
|
373
|
-
config.exclusion_filter = { :foo => :bar }
|
374
|
-
assign_files_or_directories_to_run "path/to/file.rb:37"
|
375
|
-
expect(config.exclusion_filter).to be_empty,
|
376
|
-
"expected exclusion filter to be empty:\n#{config.exclusion_filter}"
|
377
|
-
end
|
378
|
-
|
379
|
-
it "clears exclusion filters set before config" do
|
380
|
-
config.force(:exclusion_filter => { :foo => :bar })
|
381
|
-
assign_files_or_directories_to_run "path/to/file.rb:37"
|
382
|
-
expect(config.exclusion_filter).to be_empty,
|
383
|
-
"expected exclusion filter to be empty:\n#{config.exclusion_filter}"
|
384
|
-
end
|
385
|
-
end
|
386
|
-
|
387
|
-
context "with default pattern" do
|
388
|
-
it "loads files named _spec.rb" do
|
389
|
-
assign_files_or_directories_to_run "spec/rspec/core/resources"
|
390
|
-
expect(config.files_to_run).to eq([ "spec/rspec/core/resources/a_spec.rb"])
|
391
|
-
end
|
392
|
-
|
393
|
-
it "loads files in Windows", :if => RSpec.windows_os? do
|
394
|
-
assign_files_or_directories_to_run "C:\\path\\to\\project\\spec\\sub\\foo_spec.rb"
|
395
|
-
expect(config.files_to_run).to eq([ "C:/path/to/project/spec/sub/foo_spec.rb"])
|
396
|
-
end
|
397
|
-
|
398
|
-
it "loads files in Windows when directory is specified", :if => RSpec.windows_os? do
|
399
|
-
assign_files_or_directories_to_run "spec\\rspec\\core\\resources"
|
400
|
-
expect(config.files_to_run).to eq([ "spec/rspec/core/resources/a_spec.rb"])
|
401
|
-
end
|
402
|
-
end
|
403
|
-
|
404
|
-
context "with default default_path" do
|
405
|
-
it "loads files in the default path when run by rspec" do
|
406
|
-
allow(config).to receive(:command) { 'rspec' }
|
407
|
-
assign_files_or_directories_to_run []
|
408
|
-
expect(config.files_to_run).not_to be_empty
|
409
|
-
end
|
410
|
-
|
411
|
-
it "loads files in the default path when run with DRB (e.g., spork)" do
|
412
|
-
allow(config).to receive(:command) { 'spork' }
|
413
|
-
allow(RSpec::Core::Runner).to receive(:running_in_drb?) { true }
|
414
|
-
assign_files_or_directories_to_run []
|
415
|
-
expect(config.files_to_run).not_to be_empty
|
416
|
-
end
|
417
|
-
|
418
|
-
it "does not load files in the default path when run by ruby" do
|
419
|
-
allow(config).to receive(:command) { 'ruby' }
|
420
|
-
assign_files_or_directories_to_run []
|
421
|
-
expect(config.files_to_run).to be_empty
|
422
|
-
end
|
423
|
-
end
|
424
|
-
|
425
|
-
def specify_consistent_ordering_of_files_to_run
|
426
|
-
allow(File).to receive(:directory?).with('a') { true }
|
427
|
-
globbed_files = nil
|
428
|
-
allow(Dir).to receive(:[]).with(/^\{?a/) { globbed_files }
|
429
|
-
|
430
|
-
orderings = [
|
431
|
-
%w[ a/1.rb a/2.rb a/3.rb ],
|
432
|
-
%w[ a/2.rb a/1.rb a/3.rb ],
|
433
|
-
%w[ a/3.rb a/2.rb a/1.rb ]
|
434
|
-
].map do |files|
|
435
|
-
globbed_files = files
|
436
|
-
yield
|
437
|
-
config.files_to_run
|
438
|
-
end
|
439
|
-
|
440
|
-
expect(orderings.uniq.size).to eq(1)
|
441
|
-
end
|
442
|
-
|
443
|
-
context 'when the given directories match the pattern' do
|
444
|
-
it 'orders the files in a consistent ordering, regardless of the underlying OS ordering' do
|
445
|
-
specify_consistent_ordering_of_files_to_run do
|
446
|
-
config.pattern = 'a/*.rb'
|
447
|
-
assign_files_or_directories_to_run 'a'
|
448
|
-
end
|
449
|
-
end
|
450
|
-
end
|
451
|
-
|
452
|
-
context 'when the pattern is given relative to the given directories' do
|
453
|
-
it 'orders the files in a consistent ordering, regardless of the underlying OS ordering' do
|
454
|
-
specify_consistent_ordering_of_files_to_run do
|
455
|
-
config.pattern = '*.rb'
|
456
|
-
assign_files_or_directories_to_run 'a'
|
457
|
-
end
|
458
|
-
end
|
459
|
-
end
|
460
|
-
|
461
|
-
context 'when given multiple file paths' do
|
462
|
-
it 'orders the files in a consistent ordering, regardless of the given order' do
|
463
|
-
allow(File).to receive(:directory?) { false } # fake it into thinking these a full file paths
|
464
|
-
|
465
|
-
files = ['a/b/c_spec.rb', 'c/b/a_spec.rb']
|
466
|
-
assign_files_or_directories_to_run(*files)
|
467
|
-
ordering_1 = config.files_to_run
|
468
|
-
|
469
|
-
assign_files_or_directories_to_run(*files.reverse)
|
470
|
-
ordering_2 = config.files_to_run
|
471
|
-
|
472
|
-
expect(ordering_1).to eq(ordering_2)
|
473
|
-
end
|
474
|
-
end
|
475
|
-
end
|
476
|
-
|
477
|
-
%w[pattern= filename_pattern=].each do |setter|
|
478
|
-
describe "##{setter}" do
|
479
|
-
context "with single pattern" do
|
480
|
-
before { config.send(setter, "**/*_foo.rb") }
|
481
|
-
it "loads files following pattern" do
|
482
|
-
file = File.expand_path(File.dirname(__FILE__) + "/resources/a_foo.rb")
|
483
|
-
assign_files_or_directories_to_run file
|
484
|
-
expect(config.files_to_run).to include(file)
|
485
|
-
end
|
486
|
-
|
487
|
-
it "loads files in directories following pattern" do
|
488
|
-
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
489
|
-
assign_files_or_directories_to_run dir
|
490
|
-
expect(config.files_to_run).to include("#{dir}/a_foo.rb")
|
491
|
-
end
|
492
|
-
|
493
|
-
it "does not load files in directories not following pattern" do
|
494
|
-
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
495
|
-
assign_files_or_directories_to_run dir
|
496
|
-
expect(config.files_to_run).not_to include("#{dir}/a_bar.rb")
|
497
|
-
end
|
498
|
-
end
|
499
|
-
|
500
|
-
context "with multiple patterns" do
|
501
|
-
it "supports comma separated values" do
|
502
|
-
config.send(setter, "**/*_foo.rb,**/*_bar.rb")
|
503
|
-
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
504
|
-
assign_files_or_directories_to_run dir
|
505
|
-
expect(config.files_to_run).to include("#{dir}/a_foo.rb")
|
506
|
-
expect(config.files_to_run).to include("#{dir}/a_bar.rb")
|
507
|
-
end
|
508
|
-
|
509
|
-
it "supports comma separated values with spaces" do
|
510
|
-
config.send(setter, "**/*_foo.rb, **/*_bar.rb")
|
511
|
-
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
512
|
-
assign_files_or_directories_to_run dir
|
513
|
-
expect(config.files_to_run).to include("#{dir}/a_foo.rb")
|
514
|
-
expect(config.files_to_run).to include("#{dir}/a_bar.rb")
|
515
|
-
end
|
516
|
-
|
517
|
-
it "supports curly braces glob syntax" do
|
518
|
-
config.send(setter, "**/*_{foo,bar}.rb")
|
519
|
-
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
520
|
-
assign_files_or_directories_to_run dir
|
521
|
-
expect(config.files_to_run).to include("#{dir}/a_foo.rb")
|
522
|
-
expect(config.files_to_run).to include("#{dir}/a_bar.rb")
|
523
|
-
end
|
524
|
-
end
|
525
|
-
|
526
|
-
context "after files have already been loaded" do
|
527
|
-
it 'will warn that it will have no effect' do
|
528
|
-
expect_warning_with_call_site(__FILE__, __LINE__ + 2, /has no effect/)
|
529
|
-
config.load_spec_files
|
530
|
-
config.send(setter, "rspec/**/*.spec")
|
531
|
-
end
|
532
|
-
|
533
|
-
it 'will not warn if reset is called after load_spec_files' do
|
534
|
-
config.load_spec_files
|
535
|
-
config.reset
|
536
|
-
expect(RSpec).to_not receive(:warning)
|
537
|
-
config.send(setter, "rspec/**/*.spec")
|
538
|
-
end
|
539
|
-
end
|
540
|
-
end
|
541
|
-
end
|
542
|
-
|
543
|
-
describe "path with line number" do
|
544
|
-
it "assigns the line number as a location filter" do
|
545
|
-
assign_files_or_directories_to_run "path/to/a_spec.rb:37"
|
546
|
-
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37]}})
|
547
|
-
end
|
548
|
-
end
|
549
|
-
|
550
|
-
context "with full_description set" do
|
551
|
-
it "overrides filters" do
|
552
|
-
config.filter_run :focused => true
|
553
|
-
config.full_description = "foo"
|
554
|
-
expect(config.filter).not_to have_key(:focused)
|
555
|
-
end
|
556
|
-
|
557
|
-
it 'is possible to access the full description regular expression' do
|
558
|
-
config.full_description = "foo"
|
559
|
-
expect(config.full_description).to eq(/foo/)
|
560
|
-
end
|
561
|
-
end
|
562
|
-
|
563
|
-
context "without full_description having been set" do
|
564
|
-
it 'returns nil from #full_description' do
|
565
|
-
expect(config.full_description).to eq nil
|
566
|
-
end
|
567
|
-
end
|
568
|
-
|
569
|
-
context "with line number" do
|
570
|
-
it "assigns the file and line number as a location filter" do
|
571
|
-
assign_files_or_directories_to_run "path/to/a_spec.rb:37"
|
572
|
-
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37]}})
|
573
|
-
end
|
574
|
-
|
575
|
-
it "assigns multiple files with line numbers as location filters" do
|
576
|
-
assign_files_or_directories_to_run "path/to/a_spec.rb:37", "other_spec.rb:44"
|
577
|
-
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37],
|
578
|
-
File.expand_path("other_spec.rb") => [44]}})
|
579
|
-
end
|
580
|
-
|
581
|
-
it "assigns files with multiple line numbers as location filters" do
|
582
|
-
assign_files_or_directories_to_run "path/to/a_spec.rb:37", "path/to/a_spec.rb:44"
|
583
|
-
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37, 44]}})
|
584
|
-
end
|
585
|
-
end
|
586
|
-
|
587
|
-
context "with multiple line numbers" do
|
588
|
-
it "assigns the file and line numbers as a location filter" do
|
589
|
-
assign_files_or_directories_to_run "path/to/a_spec.rb:1:3:5:7"
|
590
|
-
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [1,3,5,7]}})
|
591
|
-
end
|
592
|
-
end
|
593
|
-
|
594
|
-
it "assigns the example name as the filter on description" do
|
595
|
-
config.full_description = "foo"
|
596
|
-
expect(config.filter).to eq({:full_description => /foo/})
|
597
|
-
end
|
598
|
-
|
599
|
-
it "assigns the example names as the filter on description if description is an array" do
|
600
|
-
config.full_description = [ "foo", "bar" ]
|
601
|
-
expect(config.filter).to eq({:full_description => Regexp.union(/foo/, /bar/)})
|
602
|
-
end
|
603
|
-
|
604
|
-
it 'is possible to access the full description regular expression' do
|
605
|
-
config.full_description = "foo","bar"
|
606
|
-
expect(config.full_description).to eq Regexp.union(/foo/,/bar/)
|
607
|
-
end
|
608
|
-
|
609
|
-
describe "#default_path" do
|
610
|
-
it 'defaults to "spec"' do
|
611
|
-
expect(config.default_path).to eq('spec')
|
612
|
-
end
|
613
|
-
end
|
614
|
-
|
615
|
-
describe "#include" do
|
616
|
-
|
617
|
-
module InstanceLevelMethods
|
618
|
-
def you_call_this_a_blt?
|
619
|
-
"egad man, where's the mayo?!?!?"
|
620
|
-
end
|
621
|
-
end
|
622
|
-
|
623
|
-
it_behaves_like "metadata hash builder" do
|
624
|
-
def metadata_hash(*args)
|
625
|
-
config.include(InstanceLevelMethods, *args)
|
626
|
-
config.include_or_extend_modules.last.last
|
627
|
-
end
|
628
|
-
end
|
629
|
-
|
630
|
-
context "with no filter" do
|
631
|
-
it "includes the given module into each example group" do
|
632
|
-
RSpec.configure do |c|
|
633
|
-
c.include(InstanceLevelMethods)
|
634
|
-
end
|
635
|
-
|
636
|
-
group = ExampleGroup.describe('does like, stuff and junk', :magic_key => :include) { }
|
637
|
-
expect(group).not_to respond_to(:you_call_this_a_blt?)
|
638
|
-
expect(group.new.you_call_this_a_blt?).to eq("egad man, where's the mayo?!?!?")
|
639
|
-
end
|
640
|
-
end
|
641
|
-
|
642
|
-
context "with a filter" do
|
643
|
-
it "includes the given module into each matching example group" do
|
644
|
-
RSpec.configure do |c|
|
645
|
-
c.include(InstanceLevelMethods, :magic_key => :include)
|
646
|
-
end
|
647
|
-
|
648
|
-
group = ExampleGroup.describe('does like, stuff and junk', :magic_key => :include) { }
|
649
|
-
expect(group).not_to respond_to(:you_call_this_a_blt?)
|
650
|
-
expect(group.new.you_call_this_a_blt?).to eq("egad man, where's the mayo?!?!?")
|
651
|
-
end
|
652
|
-
end
|
653
|
-
|
654
|
-
end
|
655
|
-
|
656
|
-
describe "#extend" do
|
657
|
-
|
658
|
-
module ThatThingISentYou
|
659
|
-
def that_thing
|
660
|
-
end
|
661
|
-
end
|
662
|
-
|
663
|
-
it_behaves_like "metadata hash builder" do
|
664
|
-
def metadata_hash(*args)
|
665
|
-
config.extend(ThatThingISentYou, *args)
|
666
|
-
config.include_or_extend_modules.last.last
|
667
|
-
end
|
668
|
-
end
|
669
|
-
|
670
|
-
it "extends the given module into each matching example group" do
|
671
|
-
RSpec.configure do |c|
|
672
|
-
c.extend(ThatThingISentYou, :magic_key => :extend)
|
673
|
-
end
|
674
|
-
|
675
|
-
group = ExampleGroup.describe(ThatThingISentYou, :magic_key => :extend) { }
|
676
|
-
expect(group).to respond_to(:that_thing)
|
677
|
-
end
|
678
|
-
|
679
|
-
end
|
680
|
-
|
681
|
-
describe "#run_all_when_everything_filtered?" do
|
682
|
-
|
683
|
-
it "defaults to false" do
|
684
|
-
expect(config.run_all_when_everything_filtered?).to be_falsey
|
685
|
-
end
|
686
|
-
|
687
|
-
it "can be queried with question method" do
|
688
|
-
config.run_all_when_everything_filtered = true
|
689
|
-
expect(config.run_all_when_everything_filtered?).to be_truthy
|
690
|
-
end
|
691
|
-
end
|
692
|
-
|
693
|
-
%w[color color_enabled].each do |color_option|
|
694
|
-
describe "##{color_option}=" do
|
695
|
-
context "given true" do
|
696
|
-
before { config.send "#{color_option}=", true }
|
697
|
-
|
698
|
-
context "with config.tty? and output.tty?" do
|
699
|
-
it "does not set color_enabled" do
|
700
|
-
output = StringIO.new
|
701
|
-
config.output_stream = output
|
702
|
-
|
703
|
-
config.tty = true
|
704
|
-
allow(config.output_stream).to receive_messages :tty? => true
|
705
|
-
|
706
|
-
expect(config.send(color_option)).to be_truthy
|
707
|
-
expect(config.send(color_option, output)).to be_truthy
|
708
|
-
end
|
709
|
-
end
|
710
|
-
|
711
|
-
context "with config.tty? and !output.tty?" do
|
712
|
-
it "sets color_enabled" do
|
713
|
-
output = StringIO.new
|
714
|
-
config.output_stream = output
|
715
|
-
|
716
|
-
config.tty = true
|
717
|
-
allow(config.output_stream).to receive_messages :tty? => false
|
718
|
-
|
719
|
-
expect(config.send(color_option)).to be_truthy
|
720
|
-
expect(config.send(color_option, output)).to be_truthy
|
721
|
-
end
|
722
|
-
end
|
723
|
-
|
724
|
-
context "with config.tty? and !output.tty?" do
|
725
|
-
it "does not set color_enabled" do
|
726
|
-
output = StringIO.new
|
727
|
-
config.output_stream = output
|
728
|
-
|
729
|
-
config.tty = false
|
730
|
-
allow(config.output_stream).to receive_messages :tty? => true
|
731
|
-
|
732
|
-
expect(config.send(color_option)).to be_truthy
|
733
|
-
expect(config.send(color_option, output)).to be_truthy
|
734
|
-
end
|
735
|
-
end
|
736
|
-
|
737
|
-
context "with !config.tty? and !output.tty?" do
|
738
|
-
it "does not set color_enabled" do
|
739
|
-
output = StringIO.new
|
740
|
-
config.output_stream = output
|
741
|
-
|
742
|
-
config.tty = false
|
743
|
-
allow(config.output_stream).to receive_messages :tty? => false
|
744
|
-
|
745
|
-
expect(config.send(color_option)).to be_falsey
|
746
|
-
expect(config.send(color_option, output)).to be_falsey
|
747
|
-
end
|
748
|
-
end
|
749
|
-
|
750
|
-
context "on windows" do
|
751
|
-
before do
|
752
|
-
@original_host = RbConfig::CONFIG['host_os']
|
753
|
-
RbConfig::CONFIG['host_os'] = 'mingw'
|
754
|
-
allow(config).to receive(:require)
|
755
|
-
end
|
756
|
-
|
757
|
-
after do
|
758
|
-
RbConfig::CONFIG['host_os'] = @original_host
|
759
|
-
end
|
760
|
-
|
761
|
-
context "with ANSICON available" do
|
762
|
-
around(:each) { |e| with_env_vars('ANSICON' => 'ANSICON', &e) }
|
763
|
-
|
764
|
-
it "enables colors" do
|
765
|
-
config.output_stream = StringIO.new
|
766
|
-
allow(config.output_stream).to receive_messages :tty? => true
|
767
|
-
config.send "#{color_option}=", true
|
768
|
-
expect(config.send(color_option)).to be_truthy
|
769
|
-
end
|
770
|
-
|
771
|
-
it "leaves output stream intact" do
|
772
|
-
config.output_stream = $stdout
|
773
|
-
allow(config).to receive(:require) do |what|
|
774
|
-
config.output_stream = 'foo' if what =~ /Win32/
|
775
|
-
end
|
776
|
-
config.send "#{color_option}=", true
|
777
|
-
expect(config.output_stream).to eq($stdout)
|
778
|
-
end
|
779
|
-
end
|
780
|
-
|
781
|
-
context "with ANSICON NOT available" do
|
782
|
-
before do
|
783
|
-
allow_warning
|
784
|
-
end
|
785
|
-
|
786
|
-
it "warns to install ANSICON" do
|
787
|
-
allow(config).to receive(:require) { raise LoadError }
|
788
|
-
expect_warning_with_call_site(__FILE__, __LINE__ + 1, /You must use ANSICON/)
|
789
|
-
config.send "#{color_option}=", true
|
790
|
-
end
|
791
|
-
|
792
|
-
it "sets color_enabled to false" do
|
793
|
-
allow(config).to receive(:require) { raise LoadError }
|
794
|
-
config.send "#{color_option}=", true
|
795
|
-
config.color_enabled = true
|
796
|
-
expect(config.send(color_option)).to be_falsey
|
797
|
-
end
|
798
|
-
end
|
799
|
-
end
|
800
|
-
end
|
801
|
-
end
|
802
|
-
|
803
|
-
it "prefers incoming cli_args" do
|
804
|
-
config.output_stream = StringIO.new
|
805
|
-
allow(config.output_stream).to receive_messages :tty? => true
|
806
|
-
config.force :color => true
|
807
|
-
config.color = false
|
808
|
-
expect(config.color).to be_truthy
|
809
|
-
end
|
810
|
-
end
|
811
|
-
|
812
|
-
%w[formatter= add_formatter].each do |config_method|
|
813
|
-
describe "##{config_method}" do
|
814
|
-
it "delegates to formatters#add" do
|
815
|
-
expect(config.formatter_loader).to receive(:add).with('these','options')
|
816
|
-
config.send(config_method,'these','options')
|
817
|
-
end
|
818
|
-
end
|
819
|
-
end
|
820
|
-
|
821
|
-
describe "#filter_run_including" do
|
822
|
-
it_behaves_like "metadata hash builder" do
|
823
|
-
def metadata_hash(*args)
|
824
|
-
config.filter_run_including(*args)
|
825
|
-
config.inclusion_filter
|
826
|
-
end
|
827
|
-
end
|
828
|
-
|
829
|
-
it "sets the filter with a hash" do
|
830
|
-
config.filter_run_including :foo => true
|
831
|
-
expect(config.inclusion_filter[:foo]).to be(true)
|
832
|
-
end
|
833
|
-
|
834
|
-
it "sets the filter with a symbol" do
|
835
|
-
config.filter_run_including :foo
|
836
|
-
expect(config.inclusion_filter[:foo]).to be(true)
|
837
|
-
end
|
838
|
-
|
839
|
-
it "merges with existing filters" do
|
840
|
-
config.filter_run_including :foo => true
|
841
|
-
config.filter_run_including :bar => false
|
842
|
-
|
843
|
-
expect(config.inclusion_filter[:foo]).to be(true)
|
844
|
-
expect(config.inclusion_filter[:bar]).to be(false)
|
845
|
-
end
|
846
|
-
end
|
847
|
-
|
848
|
-
describe "#filter_run_excluding" do
|
849
|
-
it_behaves_like "metadata hash builder" do
|
850
|
-
def metadata_hash(*args)
|
851
|
-
config.filter_run_excluding(*args)
|
852
|
-
config.exclusion_filter
|
853
|
-
end
|
854
|
-
end
|
855
|
-
|
856
|
-
it "sets the filter" do
|
857
|
-
config.filter_run_excluding :foo => true
|
858
|
-
expect(config.exclusion_filter[:foo]).to be(true)
|
859
|
-
end
|
860
|
-
|
861
|
-
it "sets the filter using a symbol" do
|
862
|
-
config.filter_run_excluding :foo
|
863
|
-
expect(config.exclusion_filter[:foo]).to be(true)
|
864
|
-
end
|
865
|
-
|
866
|
-
it "merges with existing filters" do
|
867
|
-
config.filter_run_excluding :foo => true
|
868
|
-
config.filter_run_excluding :bar => false
|
869
|
-
|
870
|
-
expect(config.exclusion_filter[:foo]).to be(true)
|
871
|
-
expect(config.exclusion_filter[:bar]).to be(false)
|
872
|
-
end
|
873
|
-
end
|
874
|
-
|
875
|
-
describe "#inclusion_filter" do
|
876
|
-
it "returns {} even if set to nil" do
|
877
|
-
config.inclusion_filter = nil
|
878
|
-
expect(config.inclusion_filter).to eq({})
|
879
|
-
end
|
880
|
-
end
|
881
|
-
|
882
|
-
describe "#inclusion_filter=" do
|
883
|
-
it "treats symbols as hash keys with true values when told to" do
|
884
|
-
config.inclusion_filter = :foo
|
885
|
-
expect(config.inclusion_filter).to eq({:foo => true})
|
886
|
-
end
|
887
|
-
|
888
|
-
it "overrides any inclusion filters set on the command line or in configuration files" do
|
889
|
-
config.force(:inclusion_filter => { :foo => :bar })
|
890
|
-
config.inclusion_filter = {:want => :this}
|
891
|
-
expect(config.inclusion_filter).to eq({:want => :this})
|
892
|
-
end
|
893
|
-
end
|
894
|
-
|
895
|
-
describe "#exclusion_filter" do
|
896
|
-
it "returns {} even if set to nil" do
|
897
|
-
config.exclusion_filter = nil
|
898
|
-
expect(config.exclusion_filter).to eq({})
|
899
|
-
end
|
900
|
-
|
901
|
-
describe "the default :if filter" do
|
902
|
-
it "does not exclude a spec with { :if => true } metadata" do
|
903
|
-
expect(config.exclusion_filter[:if].call(true)).to be_falsey
|
904
|
-
end
|
905
|
-
|
906
|
-
it "excludes a spec with { :if => false } metadata" do
|
907
|
-
expect(config.exclusion_filter[:if].call(false)).to be_truthy
|
908
|
-
end
|
909
|
-
|
910
|
-
it "excludes a spec with { :if => nil } metadata" do
|
911
|
-
expect(config.exclusion_filter[:if].call(nil)).to be_truthy
|
912
|
-
end
|
913
|
-
end
|
914
|
-
|
915
|
-
describe "the default :unless filter" do
|
916
|
-
it "excludes a spec with { :unless => true } metadata" do
|
917
|
-
expect(config.exclusion_filter[:unless].call(true)).to be_truthy
|
918
|
-
end
|
919
|
-
|
920
|
-
it "does not exclude a spec with { :unless => false } metadata" do
|
921
|
-
expect(config.exclusion_filter[:unless].call(false)).to be_falsey
|
922
|
-
end
|
923
|
-
|
924
|
-
it "does not exclude a spec with { :unless => nil } metadata" do
|
925
|
-
expect(config.exclusion_filter[:unless].call(nil)).to be_falsey
|
926
|
-
end
|
927
|
-
end
|
928
|
-
end
|
929
|
-
|
930
|
-
describe "#treat_symbols_as_metadata_keys_with_true_values=" do
|
931
|
-
it 'is deprecated' do
|
932
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
|
933
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
934
|
-
end
|
935
|
-
end
|
936
|
-
|
937
|
-
describe "#exclusion_filter=" do
|
938
|
-
it "treats symbols as hash keys with true values when told to" do
|
939
|
-
config.exclusion_filter = :foo
|
940
|
-
expect(config.exclusion_filter).to eq({:foo => true})
|
941
|
-
end
|
942
|
-
|
943
|
-
it "overrides any exclusion filters set on the command line or in configuration files" do
|
944
|
-
config.force(:exclusion_filter => { :foo => :bar })
|
945
|
-
config.exclusion_filter = {:want => :this}
|
946
|
-
expect(config.exclusion_filter).to eq({:want => :this})
|
947
|
-
end
|
948
|
-
end
|
949
|
-
|
950
|
-
describe "line_numbers=" do
|
951
|
-
it "sets the line numbers" do
|
952
|
-
config.line_numbers = ['37']
|
953
|
-
expect(config.filter).to eq({:line_numbers => [37]})
|
954
|
-
end
|
955
|
-
|
956
|
-
it "overrides filters" do
|
957
|
-
config.filter_run :focused => true
|
958
|
-
config.line_numbers = ['37']
|
959
|
-
expect(config.filter).to eq({:line_numbers => [37]})
|
960
|
-
end
|
961
|
-
|
962
|
-
it "prevents subsequent filters" do
|
963
|
-
config.line_numbers = ['37']
|
964
|
-
config.filter_run :focused => true
|
965
|
-
expect(config.filter).to eq({:line_numbers => [37]})
|
966
|
-
end
|
967
|
-
end
|
968
|
-
|
969
|
-
describe "line_numbers" do
|
970
|
-
it "returns the line numbers from the filter" do
|
971
|
-
config.line_numbers = ['42']
|
972
|
-
expect(config.line_numbers).to eq [42]
|
973
|
-
end
|
974
|
-
|
975
|
-
it "defaults to empty" do
|
976
|
-
expect(config.line_numbers).to eq []
|
977
|
-
end
|
978
|
-
end
|
979
|
-
|
980
|
-
describe "#full_backtrace=" do
|
981
|
-
it "doesn't impact other instances of config" do
|
982
|
-
config_1 = Configuration.new
|
983
|
-
config_2 = Configuration.new
|
984
|
-
|
985
|
-
config_1.full_backtrace = true
|
986
|
-
expect(config_2.full_backtrace?).to be_falsey
|
987
|
-
end
|
988
|
-
end
|
989
|
-
|
990
|
-
describe "#backtrace_exclusion_patterns=" do
|
991
|
-
it "actually receives the new filter values" do
|
992
|
-
config = Configuration.new
|
993
|
-
config.backtrace_exclusion_patterns = [/.*/]
|
994
|
-
expect(config.backtrace_formatter.exclude? "this").to be_truthy
|
995
|
-
end
|
996
|
-
end
|
997
|
-
|
998
|
-
describe 'full_backtrace' do
|
999
|
-
it 'returns true when backtrace patterns is empty' do
|
1000
|
-
config.backtrace_exclusion_patterns = []
|
1001
|
-
expect(config.full_backtrace?).to eq true
|
1002
|
-
end
|
1003
|
-
|
1004
|
-
it 'returns false when backtrace patterns isnt empty' do
|
1005
|
-
config.backtrace_exclusion_patterns = [:lib]
|
1006
|
-
expect(config.full_backtrace?).to eq false
|
1007
|
-
end
|
1008
|
-
end
|
1009
|
-
|
1010
|
-
describe "#backtrace_exclusion_patterns" do
|
1011
|
-
it "can be appended to" do
|
1012
|
-
config = Configuration.new
|
1013
|
-
config.backtrace_exclusion_patterns << /.*/
|
1014
|
-
expect(config.backtrace_formatter.exclude? "this").to be_truthy
|
1015
|
-
end
|
1016
|
-
end
|
1017
|
-
|
1018
|
-
describe "#libs=" do
|
1019
|
-
include_context "isolate load path mutation"
|
1020
|
-
|
1021
|
-
it "adds directories to the LOAD_PATH" do
|
1022
|
-
expect($LOAD_PATH).to receive(:unshift).with("a/dir")
|
1023
|
-
config.libs = ["a/dir"]
|
1024
|
-
end
|
1025
|
-
end
|
1026
|
-
|
1027
|
-
describe "libs" do
|
1028
|
-
include_context "isolate load path mutation"
|
1029
|
-
|
1030
|
-
it 'records paths added to the load path' do
|
1031
|
-
config.libs = ["a/dir"]
|
1032
|
-
expect(config.libs).to eq ["a/dir"]
|
1033
|
-
end
|
1034
|
-
end
|
1035
|
-
|
1036
|
-
describe "#add_setting" do
|
1037
|
-
describe "with no modifiers" do
|
1038
|
-
context "with no additional options" do
|
1039
|
-
before do
|
1040
|
-
config.add_setting :custom_option
|
1041
|
-
end
|
1042
|
-
|
1043
|
-
it "defaults to nil" do
|
1044
|
-
expect(config.custom_option).to be_nil
|
1045
|
-
end
|
1046
|
-
|
1047
|
-
it "adds a predicate" do
|
1048
|
-
expect(config.custom_option?).to be_falsey
|
1049
|
-
end
|
1050
|
-
|
1051
|
-
it "can be overridden" do
|
1052
|
-
config.custom_option = "a value"
|
1053
|
-
expect(config.custom_option).to eq("a value")
|
1054
|
-
end
|
1055
|
-
end
|
1056
|
-
|
1057
|
-
context "with :default => 'a value'" do
|
1058
|
-
before do
|
1059
|
-
config.add_setting :custom_option, :default => 'a value'
|
1060
|
-
end
|
1061
|
-
|
1062
|
-
it "defaults to 'a value'" do
|
1063
|
-
expect(config.custom_option).to eq("a value")
|
1064
|
-
end
|
1065
|
-
|
1066
|
-
it "returns true for the predicate" do
|
1067
|
-
expect(config.custom_option?).to be_truthy
|
1068
|
-
end
|
1069
|
-
|
1070
|
-
it "can be overridden with a truthy value" do
|
1071
|
-
config.custom_option = "a new value"
|
1072
|
-
expect(config.custom_option).to eq("a new value")
|
1073
|
-
end
|
1074
|
-
|
1075
|
-
it "can be overridden with nil" do
|
1076
|
-
config.custom_option = nil
|
1077
|
-
expect(config.custom_option).to eq(nil)
|
1078
|
-
end
|
1079
|
-
|
1080
|
-
it "can be overridden with false" do
|
1081
|
-
config.custom_option = false
|
1082
|
-
expect(config.custom_option).to eq(false)
|
1083
|
-
end
|
1084
|
-
end
|
1085
|
-
end
|
1086
|
-
|
1087
|
-
context "with :alias_with => " do
|
1088
|
-
before do
|
1089
|
-
config.add_setting :custom_option, :alias_with => :another_custom_option
|
1090
|
-
end
|
1091
|
-
|
1092
|
-
it "delegates the getter to the other option" do
|
1093
|
-
config.another_custom_option = "this value"
|
1094
|
-
expect(config.custom_option).to eq("this value")
|
1095
|
-
end
|
1096
|
-
|
1097
|
-
it "delegates the setter to the other option" do
|
1098
|
-
config.custom_option = "this value"
|
1099
|
-
expect(config.another_custom_option).to eq("this value")
|
1100
|
-
end
|
1101
|
-
|
1102
|
-
it "delegates the predicate to the other option" do
|
1103
|
-
config.custom_option = true
|
1104
|
-
expect(config.another_custom_option?).to be_truthy
|
1105
|
-
end
|
1106
|
-
end
|
1107
|
-
end
|
1108
|
-
|
1109
|
-
describe "#configure_group" do
|
1110
|
-
it "extends with 'extend'" do
|
1111
|
-
mod = Module.new
|
1112
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
1113
|
-
|
1114
|
-
config.extend(mod, :foo => :bar)
|
1115
|
-
config.configure_group(group)
|
1116
|
-
expect(group).to be_a(mod)
|
1117
|
-
end
|
1118
|
-
|
1119
|
-
it "extends with 'module'" do
|
1120
|
-
mod = Module.new
|
1121
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
1122
|
-
|
1123
|
-
config.include(mod, :foo => :bar)
|
1124
|
-
config.configure_group(group)
|
1125
|
-
expect(group.included_modules).to include(mod)
|
1126
|
-
end
|
1127
|
-
|
1128
|
-
it "requires only one matching filter" do
|
1129
|
-
mod = Module.new
|
1130
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
1131
|
-
|
1132
|
-
config.include(mod, :foo => :bar, :baz => :bam)
|
1133
|
-
config.configure_group(group)
|
1134
|
-
expect(group.included_modules).to include(mod)
|
1135
|
-
end
|
1136
|
-
|
1137
|
-
it "includes each one before deciding whether to include the next" do
|
1138
|
-
mod1 = Module.new do
|
1139
|
-
def self.included(host)
|
1140
|
-
host.metadata[:foo] = :bar
|
1141
|
-
end
|
1142
|
-
end
|
1143
|
-
mod2 = Module.new
|
1144
|
-
|
1145
|
-
group = ExampleGroup.describe("group")
|
1146
|
-
|
1147
|
-
config.include(mod1)
|
1148
|
-
config.include(mod2, :foo => :bar)
|
1149
|
-
config.configure_group(group)
|
1150
|
-
expect(group.included_modules).to include(mod1)
|
1151
|
-
expect(group.included_modules).to include(mod2)
|
1152
|
-
end
|
1153
|
-
|
1154
|
-
module IncludeOrExtendMeOnce
|
1155
|
-
def self.included(host)
|
1156
|
-
raise "included again" if host.instance_methods.include?(:foobar)
|
1157
|
-
host.class_eval { def foobar; end }
|
1158
|
-
end
|
1159
|
-
|
1160
|
-
def self.extended(host)
|
1161
|
-
raise "extended again" if host.respond_to?(:foobar)
|
1162
|
-
def host.foobar; end
|
1163
|
-
end
|
1164
|
-
end
|
1165
|
-
|
1166
|
-
it "doesn't include a module when already included in ancestor" do
|
1167
|
-
config.include(IncludeOrExtendMeOnce, :foo => :bar)
|
1168
|
-
|
1169
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
1170
|
-
child = group.describe("child")
|
1171
|
-
|
1172
|
-
config.configure_group(group)
|
1173
|
-
config.configure_group(child)
|
1174
|
-
end
|
1175
|
-
|
1176
|
-
it "doesn't extend when ancestor is already extended with same module" do
|
1177
|
-
config.extend(IncludeOrExtendMeOnce, :foo => :bar)
|
1178
|
-
|
1179
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
1180
|
-
child = group.describe("child")
|
1181
|
-
|
1182
|
-
config.configure_group(group)
|
1183
|
-
config.configure_group(child)
|
1184
|
-
end
|
1185
|
-
end
|
1186
|
-
|
1187
|
-
describe "#alias_example_group_to" do
|
1188
|
-
after do
|
1189
|
-
RSpec::Core::DSL.example_group_aliases.delete(:my_group_method)
|
1190
|
-
|
1191
|
-
RSpec.module_eval do
|
1192
|
-
class << self
|
1193
|
-
undef :my_group_method if method_defined? :my_group_method
|
1194
|
-
end
|
1195
|
-
end
|
1196
|
-
|
1197
|
-
RSpec::Core::ExampleGroup.module_eval do
|
1198
|
-
class << self
|
1199
|
-
undef :my_group_method if method_defined? :my_group_method
|
1200
|
-
end
|
1201
|
-
end
|
1202
|
-
end
|
1203
|
-
|
1204
|
-
it_behaves_like "metadata hash builder" do
|
1205
|
-
def metadata_hash(*args)
|
1206
|
-
config.alias_example_group_to :my_group_method, *args
|
1207
|
-
group = ExampleGroup.my_group_method("a group")
|
1208
|
-
group.metadata
|
1209
|
-
end
|
1210
|
-
end
|
1211
|
-
|
1212
|
-
it "allows adding additional metadata" do
|
1213
|
-
config.alias_example_group_to :my_group_method, { :some => "thing" }
|
1214
|
-
group = ExampleGroup.my_group_method("a group", :another => "thing")
|
1215
|
-
expect(group.metadata).to include(:some => "thing", :another => "thing")
|
1216
|
-
end
|
1217
|
-
|
1218
|
-
context 'when the aliased method is used' do
|
1219
|
-
it_behaves_like "metadata hash builder" do
|
1220
|
-
def metadata_hash(*args)
|
1221
|
-
config.alias_example_group_to :my_group_method
|
1222
|
-
group = ExampleGroup.my_group_method("a group", *args)
|
1223
|
-
group.metadata
|
1224
|
-
end
|
1225
|
-
end
|
1226
|
-
end
|
1227
|
-
end
|
1228
|
-
|
1229
|
-
describe "#alias_example_to" do
|
1230
|
-
it_behaves_like "metadata hash builder" do
|
1231
|
-
after do
|
1232
|
-
RSpec::Core::ExampleGroup.module_eval do
|
1233
|
-
class << self
|
1234
|
-
undef :my_example_method if method_defined? :my_example_method
|
1235
|
-
end
|
1236
|
-
end
|
1237
|
-
end
|
1238
|
-
def metadata_hash(*args)
|
1239
|
-
config.alias_example_to :my_example_method, *args
|
1240
|
-
group = ExampleGroup.describe("group")
|
1241
|
-
example = group.my_example_method("description")
|
1242
|
-
example.metadata
|
1243
|
-
end
|
1244
|
-
end
|
1245
|
-
end
|
1246
|
-
|
1247
|
-
describe "#reset" do
|
1248
|
-
it "clears the reporter" do
|
1249
|
-
expect(config.reporter).not_to be_nil
|
1250
|
-
config.reset
|
1251
|
-
expect(config.instance_variable_get("@reporter")).to be_nil
|
1252
|
-
end
|
1253
|
-
|
1254
|
-
it "clears the formatters" do
|
1255
|
-
config.add_formatter "doc"
|
1256
|
-
config.reset
|
1257
|
-
expect(config.formatters).to be_empty
|
1258
|
-
end
|
1259
|
-
end
|
1260
|
-
|
1261
|
-
describe "#force" do
|
1262
|
-
context "for ordering options" do
|
1263
|
-
let(:list) { [1, 2, 3, 4] }
|
1264
|
-
let(:ordering_strategy) { config.ordering_registry.fetch(:global) }
|
1265
|
-
let(:rng) { RSpec::Core::RandomNumberGenerator.new config.seed }
|
1266
|
-
let(:shuffled) { Ordering::Random.new(config).shuffle list, rng }
|
1267
|
-
|
1268
|
-
specify "CLI `--order defined` takes precedence over `config.order = rand`" do
|
1269
|
-
config.force :order => "defined"
|
1270
|
-
config.order = "rand"
|
1271
|
-
|
1272
|
-
expect(ordering_strategy.order(list)).to eq([1, 2, 3, 4])
|
1273
|
-
end
|
1274
|
-
|
1275
|
-
specify "CLI `--order rand:37` takes precedence over `config.order = defined`" do
|
1276
|
-
config.force :order => "rand:37"
|
1277
|
-
config.order = "defined"
|
1278
|
-
|
1279
|
-
expect(ordering_strategy.order(list)).to eq(shuffled)
|
1280
|
-
end
|
1281
|
-
|
1282
|
-
specify "CLI `--seed 37` forces order and seed" do
|
1283
|
-
config.force :seed => 37
|
1284
|
-
config.order = "defined"
|
1285
|
-
config.seed = 145
|
1286
|
-
|
1287
|
-
expect(ordering_strategy.order(list)).to eq(shuffled)
|
1288
|
-
expect(config.seed).to eq(37)
|
1289
|
-
end
|
1290
|
-
|
1291
|
-
specify "CLI `--order defined` takes precedence over `config.register_ordering(:global)`" do
|
1292
|
-
config.force :order => "defined"
|
1293
|
-
config.register_ordering(:global, &:reverse)
|
1294
|
-
expect(ordering_strategy.order(list)).to eq([1, 2, 3, 4])
|
1295
|
-
end
|
1296
|
-
end
|
1297
|
-
|
1298
|
-
it "forces 'false' value" do
|
1299
|
-
config.add_setting :custom_option
|
1300
|
-
config.custom_option = true
|
1301
|
-
expect(config.custom_option?).to be_truthy
|
1302
|
-
config.force :custom_option => false
|
1303
|
-
expect(config.custom_option?).to be_falsey
|
1304
|
-
config.custom_option = true
|
1305
|
-
expect(config.custom_option?).to be_falsey
|
1306
|
-
end
|
1307
|
-
end
|
1308
|
-
|
1309
|
-
describe '#seed' do
|
1310
|
-
it 'returns the seed as an int' do
|
1311
|
-
config.seed = '123'
|
1312
|
-
expect(config.seed).to eq(123)
|
1313
|
-
end
|
1314
|
-
end
|
1315
|
-
|
1316
|
-
describe "#seed_used?" do
|
1317
|
-
def use_seed_on(registry)
|
1318
|
-
registry.fetch(:random).order([1, 2])
|
1319
|
-
end
|
1320
|
-
|
1321
|
-
it 'returns false if neither ordering registry used the seed' do
|
1322
|
-
expect(config.seed_used?).to be false
|
1323
|
-
end
|
1324
|
-
|
1325
|
-
it 'returns true if the ordering registry used the seed' do
|
1326
|
-
use_seed_on(config.ordering_registry)
|
1327
|
-
expect(config.seed_used?).to be true
|
1328
|
-
end
|
1329
|
-
end
|
1330
|
-
|
1331
|
-
describe '#order=' do
|
1332
|
-
context 'given "random"' do
|
1333
|
-
before do
|
1334
|
-
config.seed = 7654
|
1335
|
-
config.order = 'random'
|
1336
|
-
end
|
1337
|
-
|
1338
|
-
it 'does not change the seed' do
|
1339
|
-
expect(config.seed).to eq(7654)
|
1340
|
-
end
|
1341
|
-
|
1342
|
-
it 'sets up random ordering' do
|
1343
|
-
allow(RSpec).to receive_messages(:configuration => config)
|
1344
|
-
global_ordering = config.ordering_registry.fetch(:global)
|
1345
|
-
expect(global_ordering).to be_an_instance_of(Ordering::Random)
|
1346
|
-
end
|
1347
|
-
end
|
1348
|
-
|
1349
|
-
context 'given "random:123"' do
|
1350
|
-
before { config.order = 'random:123' }
|
1351
|
-
|
1352
|
-
it 'sets seed to 123' do
|
1353
|
-
expect(config.seed).to eq(123)
|
1354
|
-
end
|
1355
|
-
|
1356
|
-
it 'sets up random ordering' do
|
1357
|
-
allow(RSpec).to receive_messages(:configuration => config)
|
1358
|
-
global_ordering = config.ordering_registry.fetch(:global)
|
1359
|
-
expect(global_ordering).to be_an_instance_of(Ordering::Random)
|
1360
|
-
end
|
1361
|
-
end
|
1362
|
-
|
1363
|
-
context 'given "defined"' do
|
1364
|
-
before do
|
1365
|
-
config.order = 'rand:123'
|
1366
|
-
config.order = 'defined'
|
1367
|
-
end
|
1368
|
-
|
1369
|
-
it "does not change the seed" do
|
1370
|
-
expect(config.seed).to eq(123)
|
1371
|
-
end
|
1372
|
-
|
1373
|
-
it 'clears the random ordering' do
|
1374
|
-
allow(RSpec).to receive_messages(:configuration => config)
|
1375
|
-
list = [1, 2, 3, 4]
|
1376
|
-
ordering_strategy = config.ordering_registry.fetch(:global)
|
1377
|
-
expect(ordering_strategy.order(list)).to eq([1, 2, 3, 4])
|
1378
|
-
end
|
1379
|
-
end
|
1380
|
-
end
|
1381
|
-
|
1382
|
-
describe "#register_ordering" do
|
1383
|
-
def register_reverse_ordering
|
1384
|
-
config.register_ordering(:reverse, &:reverse)
|
1385
|
-
end
|
1386
|
-
|
1387
|
-
it 'stores the ordering for later use' do
|
1388
|
-
register_reverse_ordering
|
1389
|
-
|
1390
|
-
list = [1, 2, 3]
|
1391
|
-
strategy = config.ordering_registry.fetch(:reverse)
|
1392
|
-
expect(strategy).to be_a(Ordering::Custom)
|
1393
|
-
expect(strategy.order(list)).to eq([3, 2, 1])
|
1394
|
-
end
|
1395
|
-
|
1396
|
-
it 'can register an ordering object' do
|
1397
|
-
strategy = Object.new
|
1398
|
-
def strategy.order(list)
|
1399
|
-
list.reverse
|
1400
|
-
end
|
1401
|
-
|
1402
|
-
config.register_ordering(:reverse, strategy)
|
1403
|
-
list = [1, 2, 3]
|
1404
|
-
fetched = config.ordering_registry.fetch(:reverse)
|
1405
|
-
expect(fetched).to be(strategy)
|
1406
|
-
expect(fetched.order(list)).to eq([3, 2, 1])
|
1407
|
-
end
|
1408
|
-
end
|
1409
|
-
|
1410
|
-
describe '#warnings' do
|
1411
|
-
around do |example|
|
1412
|
-
@_original_setting = $VERBOSE
|
1413
|
-
example.run
|
1414
|
-
$VERBOSE = @_original_setting
|
1415
|
-
end
|
1416
|
-
|
1417
|
-
it "sets verbose to true when true" do
|
1418
|
-
config.warnings = true
|
1419
|
-
expect($VERBOSE).to eq true
|
1420
|
-
end
|
1421
|
-
|
1422
|
-
it "sets verbose to false when true" do
|
1423
|
-
config.warnings = false
|
1424
|
-
expect($VERBOSE).to eq false
|
1425
|
-
end
|
1426
|
-
|
1427
|
-
it 'returns the verbosity setting' do
|
1428
|
-
expect(config.warnings).to eq $VERBOSE
|
1429
|
-
end
|
1430
|
-
|
1431
|
-
it 'is loaded from config by #force' do
|
1432
|
-
config.force :warnings => true
|
1433
|
-
expect($VERBOSE).to eq true
|
1434
|
-
end
|
1435
|
-
end
|
1436
|
-
|
1437
|
-
describe "#raise_errors_for_deprecations!" do
|
1438
|
-
it 'causes deprecations to raise errors rather than printing to the deprecation stream' do
|
1439
|
-
config.deprecation_stream = stream = StringIO.new
|
1440
|
-
config.raise_errors_for_deprecations!
|
1441
|
-
|
1442
|
-
expect {
|
1443
|
-
config.reporter.deprecation(:deprecated => "foo", :call_site => "foo.rb:1")
|
1444
|
-
}.to raise_error(RSpec::Core::DeprecationError, /foo is deprecated/)
|
1445
|
-
|
1446
|
-
expect(stream.string).to eq("")
|
1447
|
-
end
|
1448
|
-
end
|
1449
|
-
|
1450
|
-
describe "#expose_current_running_example_as" do
|
1451
|
-
before { stub_const(Configuration::ExposeCurrentExample.name, Module.new) }
|
1452
|
-
|
1453
|
-
it 'exposes the current example via the named method' do
|
1454
|
-
RSpec.configuration.expose_current_running_example_as :the_example
|
1455
|
-
RSpec.configuration.expose_current_running_example_as :another_example_helper
|
1456
|
-
|
1457
|
-
value_1 = value_2 = nil
|
1458
|
-
|
1459
|
-
ExampleGroup.describe "Group" do
|
1460
|
-
it "works" do
|
1461
|
-
value_1 = the_example
|
1462
|
-
value_2 = another_example_helper
|
1463
|
-
end
|
1464
|
-
end.run
|
1465
|
-
|
1466
|
-
expect(value_1).to be_an(RSpec::Core::Example)
|
1467
|
-
expect(value_1.description).to eq("works")
|
1468
|
-
expect(value_2).to be(value_1)
|
1469
|
-
end
|
1470
|
-
end
|
1471
|
-
|
1472
|
-
# assigns files_or_directories_to_run and triggers post-processing
|
1473
|
-
# via `files_to_run`.
|
1474
|
-
def assign_files_or_directories_to_run(*value)
|
1475
|
-
config.files_or_directories_to_run = value
|
1476
|
-
config.files_to_run
|
1477
|
-
end
|
1478
|
-
end
|
1479
|
-
end
|