rspec-core 2.99.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- checksums.yaml.gz.sig +0 -0
- data/.yardopts +1 -0
- data/Changelog.md +339 -1
- data/License.txt +1 -0
- data/README.md +19 -37
- data/exe/rspec +2 -23
- data/lib/rspec/core/backport_random.rb +336 -0
- data/lib/rspec/core/backtrace_formatter.rb +70 -0
- data/lib/rspec/core/configuration.rb +479 -577
- data/lib/rspec/core/configuration_options.rb +71 -54
- data/lib/rspec/core/drb.rb +111 -0
- data/lib/rspec/core/dsl.rb +86 -18
- data/lib/rspec/core/example.rb +267 -119
- data/lib/rspec/core/example_group.rb +381 -393
- data/lib/rspec/core/filter_manager.rb +133 -114
- data/lib/rspec/core/flat_map.rb +18 -0
- data/lib/rspec/core/formatters/base_formatter.rb +51 -125
- data/lib/rspec/core/formatters/base_text_formatter.rb +34 -286
- data/lib/rspec/core/formatters/console_codes.rb +24 -1
- data/lib/rspec/core/formatters/deprecation_formatter.rb +25 -26
- data/lib/rspec/core/formatters/documentation_formatter.rb +27 -25
- data/lib/rspec/core/formatters/helpers.rb +14 -36
- data/lib/rspec/core/formatters/html_formatter.rb +58 -65
- data/lib/rspec/core/formatters/html_printer.rb +12 -18
- data/lib/rspec/core/formatters/json_formatter.rb +54 -31
- data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
- data/lib/rspec/core/formatters/progress_formatter.rb +11 -15
- data/lib/rspec/core/formatters/snippet_extractor.rb +22 -11
- data/lib/rspec/core/formatters.rb +90 -43
- data/lib/rspec/core/hooks.rb +325 -270
- data/lib/rspec/core/memoized_helpers.rb +45 -156
- data/lib/rspec/core/metadata.rb +284 -236
- data/lib/rspec/core/metadata_filter.rb +86 -0
- data/lib/rspec/core/mocking_adapters/flexmock.rb +29 -0
- data/lib/rspec/core/{mocking/with_mocha.rb → mocking_adapters/mocha.rb} +19 -16
- data/lib/rspec/core/mocking_adapters/null.rb +12 -0
- data/lib/rspec/core/mocking_adapters/rr.rb +29 -0
- data/lib/rspec/core/mocking_adapters/rspec.rb +30 -0
- data/lib/rspec/core/notifications.rb +511 -0
- data/lib/rspec/core/option_parser.rb +49 -74
- data/lib/rspec/core/ordering.rb +156 -0
- data/lib/rspec/core/pending.rb +94 -96
- data/lib/rspec/core/project_initializer/.rspec +3 -0
- data/lib/rspec/core/project_initializer/spec/spec_helper.rb +78 -0
- data/lib/rspec/core/project_initializer.rb +24 -64
- data/lib/rspec/core/rake_task.rb +44 -130
- data/lib/rspec/core/reporter.rb +76 -59
- data/lib/rspec/core/ruby_project.rb +2 -1
- data/lib/rspec/core/runner.rb +117 -52
- data/lib/rspec/core/shared_context.rb +10 -10
- data/lib/rspec/core/shared_example_group.rb +108 -121
- data/lib/rspec/core/version.rb +3 -1
- data/lib/rspec/core/warnings.rb +40 -0
- data/lib/rspec/core/world.rb +66 -10
- data/lib/rspec/core.rb +64 -104
- data.tar.gz.sig +3 -0
- metadata +75 -322
- metadata.gz.sig +1 -0
- data/exe/autospec +0 -13
- data/features/Autotest.md +0 -38
- data/features/README.md +0 -17
- data/features/Upgrade.md +0 -364
- data/features/command_line/README.md +0 -28
- data/features/command_line/example_name_option.feature +0 -97
- data/features/command_line/exit_status.feature +0 -82
- data/features/command_line/format_option.feature +0 -75
- data/features/command_line/init.feature +0 -18
- data/features/command_line/line_number_appended_to_path.feature +0 -140
- data/features/command_line/line_number_option.feature +0 -53
- data/features/command_line/order.feature +0 -26
- data/features/command_line/pattern_option.feature +0 -49
- data/features/command_line/rake_task.feature +0 -122
- data/features/command_line/require_option.feature +0 -43
- data/features/command_line/ruby.feature +0 -22
- 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 -48
- data/features/configuration/backtrace_clean_patterns.feature +0 -102
- 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/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/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/configuration/show_failures_in_pending_blocks.feature +0 -61
- data/features/configuration/treat_symbols_as_metadata_keys_with_true_values.feature +0 -52
- 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 -294
- data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -197
- data/features/filtering/exclusion_filters.feature +0 -138
- data/features/filtering/if_and_unless.feature +0 -168
- data/features/filtering/inclusion_filters.feature +0 -105
- data/features/formatters/configurable_colors.feature +0 -31
- data/features/formatters/custom_formatter.feature +0 -36
- data/features/formatters/json_formatter.feature +0 -30
- 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 -149
- data/features/hooks/around_hooks.feature +0 -343
- data/features/hooks/before_and_after_hooks.feature +0 -427
- data/features/hooks/filtering.feature +0 -234
- data/features/metadata/current_example.feature +0 -56
- data/features/metadata/described_class.feature +0 -17
- data/features/metadata/user_defined.feature +0 -113
- data/features/mock_framework_integration/use_any_framework.feature +0 -106
- data/features/mock_framework_integration/use_flexmock.feature +0 -96
- data/features/mock_framework_integration/use_mocha.feature +0 -97
- data/features/mock_framework_integration/use_rr.feature +0 -98
- data/features/mock_framework_integration/use_rspec.feature +0 -97
- data/features/pending/pending_examples.feature +0 -229
- data/features/spec_files/arbitrary_file_suffix.feature +0 -13
- data/features/step_definitions/additional_cli_steps.rb +0 -49
- data/features/subject/attribute_of_subject.feature +0 -124
- 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 -14
- data/features/support/rubinius.rb +0 -6
- data/lib/autotest/discover.rb +0 -10
- data/lib/autotest/rspec2.rb +0 -77
- data/lib/rspec/core/backtrace_cleaner.rb +0 -46
- data/lib/rspec/core/backward_compatibility.rb +0 -55
- data/lib/rspec/core/caller_filter.rb +0 -60
- data/lib/rspec/core/command_line.rb +0 -47
- data/lib/rspec/core/deprecated_mutable_array_proxy.rb +0 -32
- data/lib/rspec/core/deprecation.rb +0 -26
- data/lib/rspec/core/drb_command_line.rb +0 -26
- data/lib/rspec/core/drb_options.rb +0 -87
- data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
- data/lib/rspec/core/extensions/kernel.rb +0 -9
- data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
- data/lib/rspec/core/extensions/ordered.rb +0 -27
- data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
- data/lib/rspec/core/metadata_hash_builder.rb +0 -97
- data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
- data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
- data/lib/rspec/core/mocking/with_rr.rb +0 -27
- data/lib/rspec/core/mocking/with_rspec.rb +0 -27
- data/lib/rspec/core/shared_example_group/collection.rb +0 -45
- data/spec/autotest/discover_spec.rb +0 -49
- data/spec/autotest/failed_results_re_spec.rb +0 -45
- data/spec/autotest/rspec_spec.rb +0 -133
- data/spec/command_line/order_spec.rb +0 -204
- data/spec/rspec/core/backtrace_cleaner_spec.rb +0 -68
- data/spec/rspec/core/caller_filter_spec.rb +0 -58
- data/spec/rspec/core/command_line_spec.rb +0 -127
- data/spec/rspec/core/command_line_spec_output.txt +0 -0
- data/spec/rspec/core/configuration_options_spec.rb +0 -417
- data/spec/rspec/core/configuration_spec.rb +0 -2072
- data/spec/rspec/core/deprecation_spec.rb +0 -27
- data/spec/rspec/core/deprecations_spec.rb +0 -59
- 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 -25
- data/spec/rspec/core/example_group_spec.rb +0 -1337
- data/spec/rspec/core/example_spec.rb +0 -502
- data/spec/rspec/core/filter_manager_spec.rb +0 -246
- data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -108
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -524
- data/spec/rspec/core/formatters/console_codes_spec.rb +0 -50
- data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -263
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -89
- data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
- data/spec/rspec/core/formatters/html_formatted.html +0 -397
- data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -131
- data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -115
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
- data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
- data/spec/rspec/core/formatters/text_mate_formatted.html +0 -397
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -107
- data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
- data/spec/rspec/core/hooks_spec.rb +0 -269
- data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
- data/spec/rspec/core/memoized_helpers_spec.rb +0 -776
- data/spec/rspec/core/metadata_spec.rb +0 -514
- data/spec/rspec/core/option_parser_spec.rb +0 -297
- data/spec/rspec/core/pending_example_spec.rb +0 -260
- data/spec/rspec/core/pending_spec.rb +0 -27
- data/spec/rspec/core/project_initializer_spec.rb +0 -130
- data/spec/rspec/core/rake_task_spec.rb +0 -202
- data/spec/rspec/core/reporter_spec.rb +0 -167
- 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 -60
- 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 -82
- data/spec/rspec/core/shared_context_spec.rb +0 -114
- data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -70
- data/spec/rspec/core/shared_example_group_spec.rb +0 -138
- data/spec/rspec/core/world_spec.rb +0 -142
- data/spec/rspec/core_spec.rb +0 -108
- data/spec/spec_helper.rb +0 -135
- data/spec/support/config_options_helper.rb +0 -15
- data/spec/support/helper_methods.rb +0 -55
- data/spec/support/in_sub_process.rb +0 -37
- data/spec/support/isolate_load_path_mutation.rb +0 -6
- data/spec/support/isolated_directory.rb +0 -10
- data/spec/support/isolated_home_directory.rb +0 -16
- data/spec/support/matchers.rb +0 -65
- data/spec/support/mathn_integration_support.rb +0 -12
- data/spec/support/sandboxed_mock_space.rb +0 -116
- data/spec/support/shared_example_groups.rb +0 -42
- data/spec/support/silence_dsl_deprecations.rb +0 -32
- data/spec/support/spec_files.rb +0 -44
|
@@ -1,2072 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'tmpdir'
|
|
3
|
-
require 'pathname'
|
|
4
|
-
|
|
5
|
-
module RSpec::Core
|
|
6
|
-
|
|
7
|
-
describe Configuration do
|
|
8
|
-
|
|
9
|
-
let(:config) { Configuration.new }
|
|
10
|
-
|
|
11
|
-
describe "RSpec.configuration with a block" do
|
|
12
|
-
before { RSpec.stub(:warn_deprecation) }
|
|
13
|
-
|
|
14
|
-
it "is deprecated" do
|
|
15
|
-
RSpec.should_receive(:warn_deprecation)
|
|
16
|
-
RSpec.configuration {}
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe '#deprecation_stream' do
|
|
21
|
-
it 'defaults to standard error' do
|
|
22
|
-
expect(config.deprecation_stream).to eq $stderr
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it 'is configurable' do
|
|
26
|
-
io = double 'deprecation io'
|
|
27
|
-
config.deprecation_stream = io
|
|
28
|
-
expect(config.deprecation_stream).to eq io
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
context 'when the reporter has already been initialized' do
|
|
32
|
-
before do
|
|
33
|
-
config.reporter
|
|
34
|
-
allow(config).to receive(:warn)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it 'prints a notice indicating the reconfigured output_stream will be ignored' do
|
|
38
|
-
config.deprecation_stream = double("IO")
|
|
39
|
-
expect(config).to have_received(:warn).with(/deprecation_stream.*#{__FILE__}:#{__LINE__ - 1}/)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it 'does not change the value of `output_stream`' do
|
|
43
|
-
config.deprecation_stream = double("IO")
|
|
44
|
-
expect(config.deprecation_stream).to eq($stderr)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it 'does not print a warning if set to the value it already has' do
|
|
48
|
-
config.deprecation_stream = config.deprecation_stream
|
|
49
|
-
expect(config).not_to have_received(:warn)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
shared_examples_for "output_stream" do |attribute|
|
|
55
|
-
define_method :attribute_value do
|
|
56
|
-
config.__send__(attribute)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
update_line = __LINE__ + 2
|
|
60
|
-
define_method :update_attribute do |value|
|
|
61
|
-
config.__send__(:"#{attribute}=", value)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it 'defaults to standard output' do
|
|
65
|
-
expect(attribute_value).to eq $stdout
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it 'is configurable' do
|
|
69
|
-
io = double 'output io'
|
|
70
|
-
update_attribute(io)
|
|
71
|
-
expect(attribute_value).to eq io
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
context 'when the reporter has already been initialized' do
|
|
75
|
-
before do
|
|
76
|
-
config.reporter
|
|
77
|
-
allow(config).to receive(:warn)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it 'prints a notice indicating the reconfigured output_stream will be ignored' do
|
|
81
|
-
update_attribute(StringIO.new)
|
|
82
|
-
expect(config).to have_received(:warn).with(/output_stream.*#{__FILE__}:#{update_line}/)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'does not change the value of `output_stream`' do
|
|
86
|
-
update_attribute(StringIO.new)
|
|
87
|
-
expect(attribute_value).to eq($stdout)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it 'does not print a warning if set to the value it already has' do
|
|
91
|
-
update_attribute(attribute_value)
|
|
92
|
-
expect(config).not_to have_received(:warn)
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
describe "#output_stream" do
|
|
98
|
-
include_examples "output_stream", :output_stream
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
describe "#output" do
|
|
102
|
-
include_examples "output_stream", :output
|
|
103
|
-
|
|
104
|
-
specify 'the reader is deprecated' do
|
|
105
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /output/)
|
|
106
|
-
config.output
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
specify 'the writer is deprecated' do
|
|
110
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /output=/)
|
|
111
|
-
config.output = $stdout
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
describe "#out" do
|
|
116
|
-
include_examples "output_stream", :out
|
|
117
|
-
|
|
118
|
-
specify 'the reader is deprecated' do
|
|
119
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /out/)
|
|
120
|
-
config.out
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
specify 'the writer is deprecated' do
|
|
124
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /out=/)
|
|
125
|
-
config.out = $stdout
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
describe "#setup_load_path_and_require" do
|
|
130
|
-
include_context "isolate load path mutation"
|
|
131
|
-
|
|
132
|
-
def absolute_path_to(dir)
|
|
133
|
-
File.expand_path("../../../../#{dir}", __FILE__)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
it 'adds `lib` to the load path' do
|
|
137
|
-
lib_dir = absolute_path_to("lib")
|
|
138
|
-
$LOAD_PATH.delete(lib_dir)
|
|
139
|
-
|
|
140
|
-
expect($LOAD_PATH).not_to include(lib_dir)
|
|
141
|
-
config.setup_load_path_and_require []
|
|
142
|
-
expect($LOAD_PATH).to include(lib_dir)
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
it 'adds the configured `default_path` to the load path' do
|
|
146
|
-
config.default_path = 'features'
|
|
147
|
-
foo_dir = absolute_path_to("features")
|
|
148
|
-
|
|
149
|
-
expect($LOAD_PATH).not_to include(foo_dir)
|
|
150
|
-
config.setup_load_path_and_require []
|
|
151
|
-
expect($LOAD_PATH).to include(foo_dir)
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
it 'stores the required files' do
|
|
155
|
-
config.should_receive(:require).with('a/path')
|
|
156
|
-
config.setup_load_path_and_require ['a/path']
|
|
157
|
-
expect(config.requires).to eq ['a/path']
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
context "when `default_path` refers to a file rather than a directory" do
|
|
161
|
-
it 'does not add it to the load path' do
|
|
162
|
-
config.default_path = 'Rakefile'
|
|
163
|
-
config.setup_load_path_and_require []
|
|
164
|
-
expect($LOAD_PATH).not_to include(match(/Rakefile/))
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
describe "#load_spec_files" do
|
|
170
|
-
it "loads files using load" do
|
|
171
|
-
config.files_to_run = ["foo.bar", "blah_spec.rb"]
|
|
172
|
-
config.should_receive(:load).twice
|
|
173
|
-
config.load_spec_files
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
it "loads each file once, even if duplicated in list" do
|
|
177
|
-
config.files_to_run = ["a_spec.rb", "a_spec.rb"]
|
|
178
|
-
config.should_receive(:load).once
|
|
179
|
-
config.load_spec_files
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
context "with rspec-1 loaded" do
|
|
183
|
-
before { stub_const("Spec::VERSION::MAJOR", 1) }
|
|
184
|
-
|
|
185
|
-
it "raises with a helpful message" do
|
|
186
|
-
expect {
|
|
187
|
-
config.load_spec_files
|
|
188
|
-
}.to raise_error(/rspec-1 has been loaded/)
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
describe "#treat_symbols_as_metadata_keys_with_true_values?" do
|
|
194
|
-
it 'defaults to false' do
|
|
195
|
-
expect(config.treat_symbols_as_metadata_keys_with_true_values?).to be_falsey
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
it 'prints a deprecation warning when explicitly set to false since RSpec 3 will not support that' do
|
|
199
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
|
|
200
|
-
config.treat_symbols_as_metadata_keys_with_true_values = false
|
|
201
|
-
expect(config.treat_symbols_as_metadata_keys_with_true_values?).to be false
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
it 'can be set to true' do
|
|
205
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
206
|
-
expect(config.treat_symbols_as_metadata_keys_with_true_values?).to be_truthy
|
|
207
|
-
end
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
describe "#mock_framework" do
|
|
211
|
-
it "defaults to :rspec" do
|
|
212
|
-
config.should_receive(:require).with('rspec/core/mocking/with_rspec')
|
|
213
|
-
config.mock_framework
|
|
214
|
-
end
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
describe "#mock_framework="do
|
|
218
|
-
it "delegates to mock_with" do
|
|
219
|
-
config.should_receive(:mock_with).with(:rspec)
|
|
220
|
-
config.mock_framework = :rspec
|
|
221
|
-
end
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
shared_examples "a configurable framework adapter" do |m|
|
|
225
|
-
it "yields a config object if the framework_module supports it" do
|
|
226
|
-
custom_config = Struct.new(:custom_setting).new
|
|
227
|
-
mod = Module.new
|
|
228
|
-
mod.stub(:configuration => custom_config)
|
|
229
|
-
|
|
230
|
-
config.send m, mod do |mod_config|
|
|
231
|
-
mod_config.custom_setting = true
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
expect(custom_config.custom_setting).to be_truthy
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
it "raises if framework module doesn't support configuration" do
|
|
238
|
-
mod = Module.new
|
|
239
|
-
|
|
240
|
-
expect {
|
|
241
|
-
config.send m, mod do |mod_config|
|
|
242
|
-
end
|
|
243
|
-
}.to raise_error(/must respond to `configuration`/)
|
|
244
|
-
end
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
describe "#mock_with" do
|
|
248
|
-
before { config.stub(:require) }
|
|
249
|
-
|
|
250
|
-
it_behaves_like "a configurable framework adapter", :mock_with
|
|
251
|
-
|
|
252
|
-
[:rspec, :mocha, :rr, :flexmock].each do |framework|
|
|
253
|
-
context "with :#{framework}" do
|
|
254
|
-
it "requires the adapter for #{framework}" do
|
|
255
|
-
config.should_receive(:require).with("rspec/core/mocking/with_#{framework}")
|
|
256
|
-
config.mock_with framework
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
it "does not print a deprecation" do
|
|
260
|
-
expect(RSpec).not_to receive(:deprecate)
|
|
261
|
-
config.mock_with framework
|
|
262
|
-
end
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
context "with #{framework.to_s.inspect}" do
|
|
266
|
-
it "requires the adapter for #{framework}" do
|
|
267
|
-
config.should_receive(:require).with("rspec/core/mocking/with_#{framework}")
|
|
268
|
-
config.mock_with framework.to_s
|
|
269
|
-
end
|
|
270
|
-
|
|
271
|
-
it "prints a deprecation warning" do
|
|
272
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /mock_with/)
|
|
273
|
-
config.mock_with framework.to_s
|
|
274
|
-
end
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
context "with :the_#{framework}_adapter" do
|
|
278
|
-
it "requires the adapter for #{framework}" do
|
|
279
|
-
config.should_receive(:require).with("rspec/core/mocking/with_#{framework}")
|
|
280
|
-
config.mock_with :"the_#{framework}_adapter"
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
it "prints a deprecation warning" do
|
|
284
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /mock_with/)
|
|
285
|
-
config.mock_with :"the_#{framework}_adapter"
|
|
286
|
-
end
|
|
287
|
-
end
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
it "allows rspec-mocks to be configured with a provided block" do
|
|
291
|
-
mod = Module.new
|
|
292
|
-
|
|
293
|
-
RSpec::Mocks.configuration.should_receive(:add_stub_and_should_receive_to).with(mod)
|
|
294
|
-
|
|
295
|
-
config.mock_with :rspec do |c|
|
|
296
|
-
c.add_stub_and_should_receive_to mod
|
|
297
|
-
end
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
context "with a module" do
|
|
301
|
-
it "sets the mock_framework_adapter to that module" do
|
|
302
|
-
mod = Module.new
|
|
303
|
-
config.mock_with mod
|
|
304
|
-
expect(config.mock_framework).to eq(mod)
|
|
305
|
-
end
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
context "with an unknown key" do
|
|
309
|
-
it "uses the null adapter" do
|
|
310
|
-
config.should_receive(:require).with('rspec/core/mocking/with_absolutely_nothing')
|
|
311
|
-
config.mock_with :crazy_new_mocking_framework_ive_not_yet_heard_of
|
|
312
|
-
end
|
|
313
|
-
|
|
314
|
-
it "prints a deprecation warning" do
|
|
315
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /mock_with/)
|
|
316
|
-
config.mock_with :crazy_new_mocking_framework_ive_not_yet_heard_of
|
|
317
|
-
end
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
context "with :nothing" do
|
|
321
|
-
it "uses the null adapter" do
|
|
322
|
-
config.should_receive(:require).with('rspec/core/mocking/with_absolutely_nothing')
|
|
323
|
-
config.mock_with :nothing
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
it "does not print a deprecation warning" do
|
|
327
|
-
expect(RSpec).not_to receive(:deprecate)
|
|
328
|
-
config.mock_with :nothing
|
|
329
|
-
end
|
|
330
|
-
end
|
|
331
|
-
|
|
332
|
-
context 'when there are already some example groups defined' do
|
|
333
|
-
it 'raises an error since this setting must be applied before any groups are defined' do
|
|
334
|
-
RSpec.world.stub(:example_groups).and_return([double.as_null_object])
|
|
335
|
-
expect {
|
|
336
|
-
config.mock_with :mocha
|
|
337
|
-
}.to raise_error(/must be configured before any example groups are defined/)
|
|
338
|
-
end
|
|
339
|
-
|
|
340
|
-
it 'does not raise an error if the default `mock_with :rspec` is re-configured' do
|
|
341
|
-
config.mock_framework # called by RSpec when configuring the first example group
|
|
342
|
-
RSpec.world.stub(:example_groups).and_return([double.as_null_object])
|
|
343
|
-
config.mock_with :rspec
|
|
344
|
-
end
|
|
345
|
-
|
|
346
|
-
it 'does not raise an error if re-setting the same config' do
|
|
347
|
-
groups = []
|
|
348
|
-
RSpec.world.stub(:example_groups => groups)
|
|
349
|
-
config.mock_with :mocha
|
|
350
|
-
groups << double.as_null_object
|
|
351
|
-
config.mock_with :mocha
|
|
352
|
-
end
|
|
353
|
-
end
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
describe "#expectation_framework" do
|
|
357
|
-
it "defaults to :rspec" do
|
|
358
|
-
config.should_receive(:require).with('rspec/expectations')
|
|
359
|
-
config.expectation_frameworks
|
|
360
|
-
end
|
|
361
|
-
end
|
|
362
|
-
|
|
363
|
-
describe "#expectation_framework=" do
|
|
364
|
-
it "delegates to expect_with=" do
|
|
365
|
-
config.should_receive(:expect_with).with(:rspec)
|
|
366
|
-
config.expectation_framework = :rspec
|
|
367
|
-
end
|
|
368
|
-
end
|
|
369
|
-
|
|
370
|
-
def stub_expectation_adapters
|
|
371
|
-
stub_const("Test::Unit::Assertions", Module.new)
|
|
372
|
-
stub_const("Minitest::Assertions", Module.new)
|
|
373
|
-
stub_const("RSpec::Core::TestUnitAssertionsAdapter", Module.new)
|
|
374
|
-
stub_const("RSpec::Core::MinitestAssertionsAdapter", Module.new)
|
|
375
|
-
allow(config).to receive(:require)
|
|
376
|
-
end
|
|
377
|
-
|
|
378
|
-
describe "#expect_with" do
|
|
379
|
-
before do
|
|
380
|
-
stub_expectation_adapters
|
|
381
|
-
end
|
|
382
|
-
|
|
383
|
-
it_behaves_like "a configurable framework adapter", :expect_with
|
|
384
|
-
|
|
385
|
-
context "with :stdlib" do
|
|
386
|
-
it "is deprecated" do
|
|
387
|
-
expect_deprecation_with_call_site __FILE__, __LINE__ + 1, /:stdlib/
|
|
388
|
-
config.expect_with :stdlib
|
|
389
|
-
end
|
|
390
|
-
|
|
391
|
-
it "requires test/unit/assertions" do
|
|
392
|
-
expect(config).to receive(:require).with('test/unit/assertions')
|
|
393
|
-
config.expect_with :stdlib
|
|
394
|
-
end
|
|
395
|
-
|
|
396
|
-
it "sets the expectation framework to ::Test::Unit::Assertions" do
|
|
397
|
-
config.expect_with :stdlib
|
|
398
|
-
expect(config.expectation_frameworks).to eq [::Test::Unit::Assertions]
|
|
399
|
-
end
|
|
400
|
-
end
|
|
401
|
-
|
|
402
|
-
context "with :rspec" do
|
|
403
|
-
it "requires rspec/expectations" do
|
|
404
|
-
expect(config).to receive(:require).with('rspec/expectations')
|
|
405
|
-
config.expect_with :rspec
|
|
406
|
-
end
|
|
407
|
-
|
|
408
|
-
it "sets the expectation framework to ::RSpec::Matchers" do
|
|
409
|
-
config.expect_with :rspec
|
|
410
|
-
expect(config.expectation_frameworks).to eq [::RSpec::Matchers]
|
|
411
|
-
end
|
|
412
|
-
end
|
|
413
|
-
|
|
414
|
-
context "with :test_unit" do
|
|
415
|
-
it "requires rspec/core/test_unit_assertions_adapter" do
|
|
416
|
-
expect(config).to receive(:require).
|
|
417
|
-
with('rspec/core/test_unit_assertions_adapter')
|
|
418
|
-
config.expect_with :test_unit
|
|
419
|
-
end
|
|
420
|
-
|
|
421
|
-
it "sets the expectation framework to ::Test::Unit::Assertions" do
|
|
422
|
-
config.expect_with :test_unit
|
|
423
|
-
expect(config.expectation_frameworks).to eq [
|
|
424
|
-
::RSpec::Core::TestUnitAssertionsAdapter
|
|
425
|
-
]
|
|
426
|
-
end
|
|
427
|
-
end
|
|
428
|
-
|
|
429
|
-
context "with :minitest" do
|
|
430
|
-
it "requires rspec/core/minitest_assertions_adapter" do
|
|
431
|
-
expect(config).to receive(:require).
|
|
432
|
-
with('rspec/core/minitest_assertions_adapter')
|
|
433
|
-
config.expect_with :minitest
|
|
434
|
-
end
|
|
435
|
-
|
|
436
|
-
it "sets the expectation framework to ::Minitest::Assertions" do
|
|
437
|
-
config.expect_with :minitest
|
|
438
|
-
expect(config.expectation_frameworks).to eq [
|
|
439
|
-
::RSpec::Core::MinitestAssertionsAdapter
|
|
440
|
-
]
|
|
441
|
-
end
|
|
442
|
-
end
|
|
443
|
-
|
|
444
|
-
it "supports multiple calls" do
|
|
445
|
-
config.expect_with :rspec
|
|
446
|
-
config.expect_with :minitest
|
|
447
|
-
expect(config.expectation_frameworks).to eq [
|
|
448
|
-
RSpec::Matchers,
|
|
449
|
-
RSpec::Core::MinitestAssertionsAdapter
|
|
450
|
-
]
|
|
451
|
-
end
|
|
452
|
-
|
|
453
|
-
it "raises if block given with multiple args" do
|
|
454
|
-
expect {
|
|
455
|
-
config.expect_with :rspec, :minitest do |mod_config|
|
|
456
|
-
end
|
|
457
|
-
}.to raise_error(/expect_with only accepts/)
|
|
458
|
-
end
|
|
459
|
-
|
|
460
|
-
it "raises ArgumentError if framework is not supported" do
|
|
461
|
-
expect do
|
|
462
|
-
config.expect_with :not_supported
|
|
463
|
-
end.to raise_error(ArgumentError)
|
|
464
|
-
end
|
|
465
|
-
|
|
466
|
-
context 'when there are already some example groups defined' do
|
|
467
|
-
it 'raises an error since this setting must be applied before any groups are defined' do
|
|
468
|
-
RSpec.world.stub(:example_groups).and_return([double.as_null_object])
|
|
469
|
-
expect {
|
|
470
|
-
config.expect_with :rspec
|
|
471
|
-
}.to raise_error(/must be configured before any example groups are defined/)
|
|
472
|
-
end
|
|
473
|
-
|
|
474
|
-
it 'does not raise an error if the default `expect_with :rspec` is re-configured' do
|
|
475
|
-
config.expectation_frameworks # called by RSpec when configuring the first example group
|
|
476
|
-
RSpec.world.stub(:example_groups).and_return([double.as_null_object])
|
|
477
|
-
config.expect_with :rspec
|
|
478
|
-
end
|
|
479
|
-
|
|
480
|
-
it 'does not raise an error if re-setting the same config' do
|
|
481
|
-
groups = []
|
|
482
|
-
RSpec.world.stub(:example_groups => groups)
|
|
483
|
-
config.expect_with :minitest
|
|
484
|
-
groups << double.as_null_object
|
|
485
|
-
config.expect_with :minitest
|
|
486
|
-
end
|
|
487
|
-
end
|
|
488
|
-
end
|
|
489
|
-
|
|
490
|
-
describe "#expecting_with_rspec?" do
|
|
491
|
-
before do
|
|
492
|
-
stub_expectation_adapters
|
|
493
|
-
end
|
|
494
|
-
|
|
495
|
-
it "returns false by default" do
|
|
496
|
-
expect(config).not_to be_expecting_with_rspec
|
|
497
|
-
end
|
|
498
|
-
|
|
499
|
-
it "returns true when `expect_with :rspec` has been configured" do
|
|
500
|
-
config.expect_with :rspec
|
|
501
|
-
expect(config).to be_expecting_with_rspec
|
|
502
|
-
end
|
|
503
|
-
|
|
504
|
-
it "returns true when `expect_with :rspec, :minitest` has been configured" do
|
|
505
|
-
config.expect_with :rspec, :minitest
|
|
506
|
-
expect(config).to be_expecting_with_rspec
|
|
507
|
-
end
|
|
508
|
-
|
|
509
|
-
it "returns true when `expect_with :minitest, :rspec` has been configured" do
|
|
510
|
-
config.expect_with :minitest, :rspec
|
|
511
|
-
expect(config).to be_expecting_with_rspec
|
|
512
|
-
end
|
|
513
|
-
|
|
514
|
-
it "returns false when `expect_with :minitest` has been configured" do
|
|
515
|
-
config.expect_with :minitest
|
|
516
|
-
expect(config).not_to be_expecting_with_rspec
|
|
517
|
-
end
|
|
518
|
-
end
|
|
519
|
-
|
|
520
|
-
describe "#files_to_run" do
|
|
521
|
-
it "loads files not following pattern if named explicitly" do
|
|
522
|
-
config.files_or_directories_to_run = "spec/rspec/core/resources/a_bar.rb"
|
|
523
|
-
expect(config.files_to_run).to eq([ "spec/rspec/core/resources/a_bar.rb"])
|
|
524
|
-
end
|
|
525
|
-
|
|
526
|
-
it "prevents repetition of dir when start of the pattern" do
|
|
527
|
-
config.pattern = "spec/**/a_spec.rb"
|
|
528
|
-
config.files_or_directories_to_run = "spec"
|
|
529
|
-
expect(config.files_to_run).to eq(["spec/rspec/core/resources/a_spec.rb"])
|
|
530
|
-
end
|
|
531
|
-
|
|
532
|
-
it "does not prevent repetition of dir when later of the pattern" do
|
|
533
|
-
config.pattern = "rspec/**/a_spec.rb"
|
|
534
|
-
config.files_or_directories_to_run = "spec"
|
|
535
|
-
expect(config.files_to_run).to eq(["spec/rspec/core/resources/a_spec.rb"])
|
|
536
|
-
end
|
|
537
|
-
|
|
538
|
-
context "with <path>:<line_number>" do
|
|
539
|
-
it "overrides inclusion filters set on config" do
|
|
540
|
-
config.filter_run_including :foo => :bar
|
|
541
|
-
config.files_or_directories_to_run = "path/to/file.rb:37"
|
|
542
|
-
expect(config.inclusion_filter.size).to eq(1)
|
|
543
|
-
expect(config.inclusion_filter[:locations].keys.first).to match(/path\/to\/file\.rb$/)
|
|
544
|
-
expect(config.inclusion_filter[:locations].values.first).to eq([37])
|
|
545
|
-
end
|
|
546
|
-
|
|
547
|
-
it "overrides inclusion filters set before config" do
|
|
548
|
-
config.force(:inclusion_filter => {:foo => :bar})
|
|
549
|
-
config.files_or_directories_to_run = "path/to/file.rb:37"
|
|
550
|
-
expect(config.inclusion_filter.size).to eq(1)
|
|
551
|
-
expect(config.inclusion_filter[:locations].keys.first).to match(/path\/to\/file\.rb$/)
|
|
552
|
-
expect(config.inclusion_filter[:locations].values.first).to eq([37])
|
|
553
|
-
end
|
|
554
|
-
|
|
555
|
-
it "clears exclusion filters set on config" do
|
|
556
|
-
config.exclusion_filter = { :foo => :bar }
|
|
557
|
-
config.files_or_directories_to_run = "path/to/file.rb:37"
|
|
558
|
-
expect(config.exclusion_filter).to be_empty,
|
|
559
|
-
"expected exclusion filter to be empty:\n#{config.exclusion_filter}"
|
|
560
|
-
end
|
|
561
|
-
|
|
562
|
-
it "clears exclusion filters set before config" do
|
|
563
|
-
config.force(:exclusion_filter => { :foo => :bar })
|
|
564
|
-
config.files_or_directories_to_run = "path/to/file.rb:37"
|
|
565
|
-
expect(config.exclusion_filter).to be_empty,
|
|
566
|
-
"expected exclusion filter to be empty:\n#{config.exclusion_filter}"
|
|
567
|
-
end
|
|
568
|
-
end
|
|
569
|
-
|
|
570
|
-
context "with default pattern" do
|
|
571
|
-
it "loads files named _spec.rb" do
|
|
572
|
-
config.files_or_directories_to_run = "spec/rspec/core/resources"
|
|
573
|
-
expect(config.files_to_run).to eq([ "spec/rspec/core/resources/a_spec.rb"])
|
|
574
|
-
end
|
|
575
|
-
|
|
576
|
-
it "loads files in Windows", :if => RSpec.windows_os? do
|
|
577
|
-
config.files_or_directories_to_run = "C:\\path\\to\\project\\spec\\sub\\foo_spec.rb"
|
|
578
|
-
expect(config.files_to_run).to eq([ "C:/path/to/project/spec/sub/foo_spec.rb"])
|
|
579
|
-
end
|
|
580
|
-
|
|
581
|
-
it "loads files in Windows when directory is specified", :if => RSpec.windows_os? do
|
|
582
|
-
config.files_or_directories_to_run = "spec\\rspec\\core\\resources"
|
|
583
|
-
expect(config.files_to_run).to eq([ "spec/rspec/core/resources/a_spec.rb"])
|
|
584
|
-
end
|
|
585
|
-
end
|
|
586
|
-
|
|
587
|
-
context "with default default_path" do
|
|
588
|
-
it "loads files in the default path when run by rspec" do
|
|
589
|
-
config.stub(:command) { 'rspec' }
|
|
590
|
-
config.files_or_directories_to_run = []
|
|
591
|
-
expect(config.files_to_run).not_to be_empty
|
|
592
|
-
end
|
|
593
|
-
|
|
594
|
-
it "loads files in the default path when run with DRB (e.g., spork)" do
|
|
595
|
-
config.stub(:command) { 'spork' }
|
|
596
|
-
RSpec::Core::Runner.stub(:running_in_drb?) { true }
|
|
597
|
-
config.files_or_directories_to_run = []
|
|
598
|
-
expect(config.files_to_run).not_to be_empty
|
|
599
|
-
end
|
|
600
|
-
|
|
601
|
-
it "does not load files in the default path when run by ruby" do
|
|
602
|
-
config.stub(:command) { 'ruby' }
|
|
603
|
-
config.files_or_directories_to_run = []
|
|
604
|
-
expect(config.files_to_run).to be_empty
|
|
605
|
-
end
|
|
606
|
-
end
|
|
607
|
-
|
|
608
|
-
def specify_consistent_ordering_of_files_to_run
|
|
609
|
-
File.stub(:directory?).with('a') { true }
|
|
610
|
-
|
|
611
|
-
orderings = [
|
|
612
|
-
%w[ a/1.rb a/2.rb a/3.rb ],
|
|
613
|
-
%w[ a/2.rb a/1.rb a/3.rb ],
|
|
614
|
-
%w[ a/3.rb a/2.rb a/1.rb ]
|
|
615
|
-
].map do |files|
|
|
616
|
-
Dir.should_receive(:[]).with(/^\{?a/) { files }
|
|
617
|
-
yield
|
|
618
|
-
config.files_to_run
|
|
619
|
-
end
|
|
620
|
-
|
|
621
|
-
expect(orderings.uniq.size).to eq(1)
|
|
622
|
-
end
|
|
623
|
-
|
|
624
|
-
context 'when the given directories match the pattern' do
|
|
625
|
-
it 'orders the files in a consistent ordering, regardless of the underlying OS ordering' do
|
|
626
|
-
specify_consistent_ordering_of_files_to_run do
|
|
627
|
-
config.pattern = 'a/*.rb'
|
|
628
|
-
config.files_or_directories_to_run = 'a'
|
|
629
|
-
end
|
|
630
|
-
end
|
|
631
|
-
end
|
|
632
|
-
|
|
633
|
-
context 'when the pattern is given relative to the given directories' do
|
|
634
|
-
it 'orders the files in a consistent ordering, regardless of the underlying OS ordering' do
|
|
635
|
-
specify_consistent_ordering_of_files_to_run do
|
|
636
|
-
config.pattern = '*.rb'
|
|
637
|
-
config.files_or_directories_to_run = 'a'
|
|
638
|
-
end
|
|
639
|
-
end
|
|
640
|
-
end
|
|
641
|
-
|
|
642
|
-
context 'when given multiple file paths' do
|
|
643
|
-
it 'orders the files in a consistent ordering, regardless of the given order' do
|
|
644
|
-
File.stub(:directory?) { false } # fake it into thinking these a full file paths
|
|
645
|
-
|
|
646
|
-
files = ['a/b/c_spec.rb', 'c/b/a_spec.rb']
|
|
647
|
-
config.files_or_directories_to_run = *files
|
|
648
|
-
ordering_1 = config.files_to_run
|
|
649
|
-
|
|
650
|
-
config.files_or_directories_to_run = *(files.reverse)
|
|
651
|
-
ordering_2 = config.files_to_run
|
|
652
|
-
|
|
653
|
-
expect(ordering_1).to eq(ordering_2)
|
|
654
|
-
end
|
|
655
|
-
end
|
|
656
|
-
end
|
|
657
|
-
|
|
658
|
-
specify "#filename_pattern is deprecated" do
|
|
659
|
-
expect_deprecation_with_call_site __FILE__, __LINE__ + 1
|
|
660
|
-
config.filename_pattern
|
|
661
|
-
end
|
|
662
|
-
|
|
663
|
-
specify "#filename_pattern= is deprecated" do
|
|
664
|
-
expect_deprecation_with_call_site __FILE__, __LINE__ + 1
|
|
665
|
-
config.filename_pattern = "/whatever"
|
|
666
|
-
end
|
|
667
|
-
|
|
668
|
-
%w[pattern= filename_pattern=].each do |setter|
|
|
669
|
-
describe "##{setter}" do
|
|
670
|
-
before { allow_deprecation } if setter == "filename_pattern="
|
|
671
|
-
|
|
672
|
-
context "with single pattern" do
|
|
673
|
-
before { config.send(setter, "**/*_foo.rb") }
|
|
674
|
-
it "loads files following pattern" do
|
|
675
|
-
file = File.expand_path(File.dirname(__FILE__) + "/resources/a_foo.rb")
|
|
676
|
-
config.files_or_directories_to_run = file
|
|
677
|
-
expect(config.files_to_run).to include(file)
|
|
678
|
-
end
|
|
679
|
-
|
|
680
|
-
it "loads files in directories following pattern" do
|
|
681
|
-
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
|
682
|
-
config.files_or_directories_to_run = dir
|
|
683
|
-
expect(config.files_to_run).to include("#{dir}/a_foo.rb")
|
|
684
|
-
end
|
|
685
|
-
|
|
686
|
-
it "does not load files in directories not following pattern" do
|
|
687
|
-
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
|
688
|
-
config.files_or_directories_to_run = dir
|
|
689
|
-
expect(config.files_to_run).not_to include("#{dir}/a_bar.rb")
|
|
690
|
-
end
|
|
691
|
-
end
|
|
692
|
-
|
|
693
|
-
context "with multiple patterns" do
|
|
694
|
-
it "supports comma separated values" do
|
|
695
|
-
config.send(setter, "**/*_foo.rb,**/*_bar.rb")
|
|
696
|
-
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
|
697
|
-
config.files_or_directories_to_run = dir
|
|
698
|
-
expect(config.files_to_run).to include("#{dir}/a_foo.rb")
|
|
699
|
-
expect(config.files_to_run).to include("#{dir}/a_bar.rb")
|
|
700
|
-
end
|
|
701
|
-
|
|
702
|
-
it "supports comma separated values with spaces" do
|
|
703
|
-
config.send(setter, "**/*_foo.rb, **/*_bar.rb")
|
|
704
|
-
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
|
705
|
-
config.files_or_directories_to_run = dir
|
|
706
|
-
expect(config.files_to_run).to include("#{dir}/a_foo.rb")
|
|
707
|
-
expect(config.files_to_run).to include("#{dir}/a_bar.rb")
|
|
708
|
-
end
|
|
709
|
-
|
|
710
|
-
it "supports curly braces glob syntax" do
|
|
711
|
-
config.send(setter, "**/*_{foo,bar}.rb")
|
|
712
|
-
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
|
713
|
-
config.files_or_directories_to_run = dir
|
|
714
|
-
expect(config.files_to_run).to include("#{dir}/a_foo.rb")
|
|
715
|
-
expect(config.files_to_run).to include("#{dir}/a_bar.rb")
|
|
716
|
-
end
|
|
717
|
-
end
|
|
718
|
-
|
|
719
|
-
context "after files have already been loaded" do
|
|
720
|
-
it 'will warn that it will have no effect' do
|
|
721
|
-
allow(Kernel).to receive(:warn)
|
|
722
|
-
config.load_spec_files
|
|
723
|
-
config.send(setter, "rspec/**/*.spec"); line = __LINE__
|
|
724
|
-
expect(Kernel).to have_received(:warn).with(/has no effect.*#{__FILE__}:#{line}/)
|
|
725
|
-
end
|
|
726
|
-
|
|
727
|
-
it 'will not warn if reset is called after load_spec_files' do
|
|
728
|
-
config.load_spec_files
|
|
729
|
-
config.reset
|
|
730
|
-
expect(Kernel).to_not receive(:warn)
|
|
731
|
-
config.send(setter, "rspec/**/*.spec")
|
|
732
|
-
end
|
|
733
|
-
end
|
|
734
|
-
end
|
|
735
|
-
end
|
|
736
|
-
|
|
737
|
-
describe "path with line number" do
|
|
738
|
-
it "assigns the line number as a location filter" do
|
|
739
|
-
config.files_or_directories_to_run = "path/to/a_spec.rb:37"
|
|
740
|
-
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37]}})
|
|
741
|
-
end
|
|
742
|
-
end
|
|
743
|
-
|
|
744
|
-
context "with full_description set" do
|
|
745
|
-
it "overrides filters" do
|
|
746
|
-
config.filter_run :focused => true
|
|
747
|
-
config.full_description = "foo"
|
|
748
|
-
expect(config.filter).not_to have_key(:focused)
|
|
749
|
-
end
|
|
750
|
-
|
|
751
|
-
it 'is possible to access the full description regular expression' do
|
|
752
|
-
config.full_description = "foo"
|
|
753
|
-
expect(config.full_description).to eq(/foo/)
|
|
754
|
-
end
|
|
755
|
-
end
|
|
756
|
-
|
|
757
|
-
context "without full_description having been set" do
|
|
758
|
-
it 'returns nil from #full_description' do
|
|
759
|
-
expect(config.full_description).to eq nil
|
|
760
|
-
end
|
|
761
|
-
end
|
|
762
|
-
|
|
763
|
-
context "with line number" do
|
|
764
|
-
it "assigns the file and line number as a location filter" do
|
|
765
|
-
config.files_or_directories_to_run = "path/to/a_spec.rb:37"
|
|
766
|
-
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37]}})
|
|
767
|
-
end
|
|
768
|
-
|
|
769
|
-
it "assigns multiple files with line numbers as location filters" do
|
|
770
|
-
config.files_or_directories_to_run = "path/to/a_spec.rb:37", "other_spec.rb:44"
|
|
771
|
-
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37],
|
|
772
|
-
File.expand_path("other_spec.rb") => [44]}})
|
|
773
|
-
end
|
|
774
|
-
|
|
775
|
-
it "assigns files with multiple line numbers as location filters" do
|
|
776
|
-
config.files_or_directories_to_run = "path/to/a_spec.rb:37", "path/to/a_spec.rb:44"
|
|
777
|
-
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37, 44]}})
|
|
778
|
-
end
|
|
779
|
-
end
|
|
780
|
-
|
|
781
|
-
context "with multiple line numbers" do
|
|
782
|
-
it "assigns the file and line numbers as a location filter" do
|
|
783
|
-
config.files_or_directories_to_run = "path/to/a_spec.rb:1:3:5:7"
|
|
784
|
-
expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [1,3,5,7]}})
|
|
785
|
-
end
|
|
786
|
-
end
|
|
787
|
-
|
|
788
|
-
it "assigns the example name as the filter on description" do
|
|
789
|
-
config.full_description = "foo"
|
|
790
|
-
expect(config.filter).to eq({:full_description => /foo/})
|
|
791
|
-
end
|
|
792
|
-
|
|
793
|
-
it "assigns the example names as the filter on description if description is an array" do
|
|
794
|
-
config.full_description = [ "foo", "bar" ]
|
|
795
|
-
expect(config.filter).to eq({:full_description => Regexp.union(/foo/, /bar/)})
|
|
796
|
-
end
|
|
797
|
-
|
|
798
|
-
it 'is possible to access the full description regular expression' do
|
|
799
|
-
config.full_description = "foo","bar"
|
|
800
|
-
expect(config.full_description).to eq Regexp.union(/foo/,/bar/)
|
|
801
|
-
end
|
|
802
|
-
|
|
803
|
-
describe "#default_path" do
|
|
804
|
-
it 'defaults to "spec"' do
|
|
805
|
-
expect(config.default_path).to eq('spec')
|
|
806
|
-
end
|
|
807
|
-
end
|
|
808
|
-
|
|
809
|
-
describe "#include" do
|
|
810
|
-
|
|
811
|
-
module InstanceLevelMethods
|
|
812
|
-
def you_call_this_a_blt?
|
|
813
|
-
"egad man, where's the mayo?!?!?"
|
|
814
|
-
end
|
|
815
|
-
end
|
|
816
|
-
|
|
817
|
-
it_behaves_like "metadata hash builder" do
|
|
818
|
-
def metadata_hash(*args)
|
|
819
|
-
config.include(InstanceLevelMethods, *args)
|
|
820
|
-
config.include_or_extend_modules.last.last
|
|
821
|
-
end
|
|
822
|
-
end
|
|
823
|
-
|
|
824
|
-
context "with no filter" do
|
|
825
|
-
it "includes the given module into each example group" do
|
|
826
|
-
RSpec.configure do |c|
|
|
827
|
-
c.include(InstanceLevelMethods)
|
|
828
|
-
end
|
|
829
|
-
|
|
830
|
-
group = ExampleGroup.describe('does like, stuff and junk', :magic_key => :include) { }
|
|
831
|
-
expect(group).not_to respond_to(:you_call_this_a_blt?)
|
|
832
|
-
expect(group.new.you_call_this_a_blt?).to eq("egad man, where's the mayo?!?!?")
|
|
833
|
-
end
|
|
834
|
-
end
|
|
835
|
-
|
|
836
|
-
context "with a filter" do
|
|
837
|
-
it "includes the given module into each matching example group" do
|
|
838
|
-
RSpec.configure do |c|
|
|
839
|
-
c.include(InstanceLevelMethods, :magic_key => :include)
|
|
840
|
-
end
|
|
841
|
-
|
|
842
|
-
group = ExampleGroup.describe('does like, stuff and junk', :magic_key => :include) { }
|
|
843
|
-
expect(group).not_to respond_to(:you_call_this_a_blt?)
|
|
844
|
-
expect(group.new.you_call_this_a_blt?).to eq("egad man, where's the mayo?!?!?")
|
|
845
|
-
end
|
|
846
|
-
end
|
|
847
|
-
|
|
848
|
-
end
|
|
849
|
-
|
|
850
|
-
describe "#extend" do
|
|
851
|
-
|
|
852
|
-
module ThatThingISentYou
|
|
853
|
-
def that_thing
|
|
854
|
-
end
|
|
855
|
-
end
|
|
856
|
-
|
|
857
|
-
it_behaves_like "metadata hash builder" do
|
|
858
|
-
def metadata_hash(*args)
|
|
859
|
-
config.extend(ThatThingISentYou, *args)
|
|
860
|
-
config.include_or_extend_modules.last.last
|
|
861
|
-
end
|
|
862
|
-
end
|
|
863
|
-
|
|
864
|
-
it "extends the given module into each matching example group" do
|
|
865
|
-
RSpec.configure do |c|
|
|
866
|
-
c.extend(ThatThingISentYou, :magic_key => :extend)
|
|
867
|
-
end
|
|
868
|
-
|
|
869
|
-
group = ExampleGroup.describe(ThatThingISentYou, :magic_key => :extend) { }
|
|
870
|
-
expect(group).to respond_to(:that_thing)
|
|
871
|
-
end
|
|
872
|
-
|
|
873
|
-
end
|
|
874
|
-
|
|
875
|
-
describe "#run_all_when_everything_filtered?" do
|
|
876
|
-
|
|
877
|
-
it "defaults to false" do
|
|
878
|
-
expect(config.run_all_when_everything_filtered?).to be_falsey
|
|
879
|
-
end
|
|
880
|
-
|
|
881
|
-
it "can be queried with question method" do
|
|
882
|
-
config.run_all_when_everything_filtered = true
|
|
883
|
-
expect(config.run_all_when_everything_filtered?).to be_truthy
|
|
884
|
-
end
|
|
885
|
-
end
|
|
886
|
-
|
|
887
|
-
specify '#color? is deprecated' do
|
|
888
|
-
expect_deprecation_with_call_site __FILE__, __LINE__+1
|
|
889
|
-
config.color?
|
|
890
|
-
end
|
|
891
|
-
|
|
892
|
-
specify "#color_enabled? is not deprecated" do
|
|
893
|
-
expect_no_deprecation
|
|
894
|
-
config.color_enabled?
|
|
895
|
-
config.color_enabled? double("output")
|
|
896
|
-
end
|
|
897
|
-
|
|
898
|
-
specify '#color with no argument is not deprecated' do
|
|
899
|
-
expect_no_deprecation
|
|
900
|
-
config.color
|
|
901
|
-
end
|
|
902
|
-
|
|
903
|
-
specify '#color with a non tty output and color = true is deprecated' do
|
|
904
|
-
allow(config.output_stream).to receive(:tty?).and_return(false)
|
|
905
|
-
config.color = true
|
|
906
|
-
expect_warn_deprecation_with_call_site __FILE__, __LINE__+1
|
|
907
|
-
expect(config.color).to be_falsey
|
|
908
|
-
end
|
|
909
|
-
|
|
910
|
-
specify '#color with an argument is deprecated' do
|
|
911
|
-
expect_deprecation_with_call_site __FILE__, __LINE__+1
|
|
912
|
-
config.color config.output_stream
|
|
913
|
-
end
|
|
914
|
-
|
|
915
|
-
specify '#color_enabled with no argument is deprecated' do
|
|
916
|
-
expect_deprecation_with_call_site __FILE__, __LINE__+1
|
|
917
|
-
config.color_enabled
|
|
918
|
-
end
|
|
919
|
-
|
|
920
|
-
specify '#color_enabled with an argument is deprecated in favour of #color_enabled?' do
|
|
921
|
-
expect_deprecation_with_call_site __FILE__, __LINE__+1
|
|
922
|
-
config.color_enabled config.output_stream
|
|
923
|
-
end
|
|
924
|
-
|
|
925
|
-
%w[color color_enabled].each do |color_option|
|
|
926
|
-
describe "##{color_option}=" do
|
|
927
|
-
before { allow_deprecation } if color_option == 'color_enabled'
|
|
928
|
-
|
|
929
|
-
specify "color_enabled is deprecated" do
|
|
930
|
-
expect_deprecation_with_call_site __FILE__, __LINE__+1
|
|
931
|
-
config.color_enabled = true
|
|
932
|
-
end
|
|
933
|
-
|
|
934
|
-
context "given true" do
|
|
935
|
-
before { config.send "#{color_option}=", true }
|
|
936
|
-
|
|
937
|
-
context "with config.tty? and output.tty?" do
|
|
938
|
-
it "does not set color_enabled" do
|
|
939
|
-
output = StringIO.new
|
|
940
|
-
config.output_stream = output
|
|
941
|
-
|
|
942
|
-
config.tty = true
|
|
943
|
-
config.output_stream.stub :tty? => true
|
|
944
|
-
|
|
945
|
-
expect(config.send(color_option)).to be_truthy
|
|
946
|
-
expect(config.send(color_option, output)).to be_truthy
|
|
947
|
-
end
|
|
948
|
-
end
|
|
949
|
-
|
|
950
|
-
context "with config.tty? and !output.tty?" do
|
|
951
|
-
it "sets color_enabled" do
|
|
952
|
-
output = StringIO.new
|
|
953
|
-
config.output_stream = output
|
|
954
|
-
|
|
955
|
-
config.tty = true
|
|
956
|
-
config.output_stream.stub :tty? => false
|
|
957
|
-
|
|
958
|
-
expect(config.send(color_option)).to be_truthy
|
|
959
|
-
expect(config.send(color_option, output)).to be_truthy
|
|
960
|
-
end
|
|
961
|
-
end
|
|
962
|
-
|
|
963
|
-
context "with config.tty? and !output.tty?" do
|
|
964
|
-
it "does not set color_enabled" do
|
|
965
|
-
output = StringIO.new
|
|
966
|
-
config.output_stream = output
|
|
967
|
-
|
|
968
|
-
config.tty = false
|
|
969
|
-
config.output_stream.stub :tty? => true
|
|
970
|
-
|
|
971
|
-
expect(config.send(color_option)).to be_truthy
|
|
972
|
-
expect(config.send(color_option, output)).to be_truthy
|
|
973
|
-
end
|
|
974
|
-
end
|
|
975
|
-
|
|
976
|
-
context "with !config.tty? and !output.tty?" do
|
|
977
|
-
it "does not set color_enabled" do
|
|
978
|
-
output = StringIO.new
|
|
979
|
-
config.output_stream = output
|
|
980
|
-
|
|
981
|
-
config.tty = false
|
|
982
|
-
config.output_stream.stub :tty? => false
|
|
983
|
-
|
|
984
|
-
expect(config.send(color_option)).to be_falsey
|
|
985
|
-
expect(config.send(color_option, output)).to be_falsey
|
|
986
|
-
end
|
|
987
|
-
end
|
|
988
|
-
|
|
989
|
-
context "on windows" do
|
|
990
|
-
before do
|
|
991
|
-
@original_host = RbConfig::CONFIG['host_os']
|
|
992
|
-
RbConfig::CONFIG['host_os'] = 'mingw'
|
|
993
|
-
config.stub(:require)
|
|
994
|
-
config.stub(:warn)
|
|
995
|
-
end
|
|
996
|
-
|
|
997
|
-
after do
|
|
998
|
-
RbConfig::CONFIG['host_os'] = @original_host
|
|
999
|
-
end
|
|
1000
|
-
|
|
1001
|
-
context "with ANSICON available" do
|
|
1002
|
-
around(:each) { |e| with_env_vars('ANSICON' => 'ANSICON', &e) }
|
|
1003
|
-
|
|
1004
|
-
it "enables colors" do
|
|
1005
|
-
config.output_stream = StringIO.new
|
|
1006
|
-
config.output_stream.stub :tty? => true
|
|
1007
|
-
config.send "#{color_option}=", true
|
|
1008
|
-
expect(config.send(color_option)).to be_truthy
|
|
1009
|
-
end
|
|
1010
|
-
|
|
1011
|
-
it "leaves output stream intact" do
|
|
1012
|
-
config.output_stream = $stdout
|
|
1013
|
-
config.stub(:require) do |what|
|
|
1014
|
-
config.output_stream = 'foo' if what =~ /Win32/
|
|
1015
|
-
end
|
|
1016
|
-
config.send "#{color_option}=", true
|
|
1017
|
-
expect(config.output_stream).to eq($stdout)
|
|
1018
|
-
end
|
|
1019
|
-
end
|
|
1020
|
-
|
|
1021
|
-
context "with ANSICON NOT available" do
|
|
1022
|
-
it "warns to install ANSICON" do
|
|
1023
|
-
config.stub(:require) { raise LoadError }
|
|
1024
|
-
config.should_receive(:warn).
|
|
1025
|
-
with(/You must use ANSICON/)
|
|
1026
|
-
config.send "#{color_option}=", true
|
|
1027
|
-
end
|
|
1028
|
-
|
|
1029
|
-
it "sets color_enabled to false" do
|
|
1030
|
-
config.stub(:require) { raise LoadError }
|
|
1031
|
-
config.send "#{color_option}=", true
|
|
1032
|
-
config.color_enabled = true
|
|
1033
|
-
expect(config.send(color_option)).to be_falsey
|
|
1034
|
-
end
|
|
1035
|
-
end
|
|
1036
|
-
end
|
|
1037
|
-
end
|
|
1038
|
-
end
|
|
1039
|
-
|
|
1040
|
-
it "prefers incoming cli_args" do
|
|
1041
|
-
config.output_stream = StringIO.new
|
|
1042
|
-
config.output_stream.stub :tty? => true
|
|
1043
|
-
config.force :color => true
|
|
1044
|
-
config.color = false
|
|
1045
|
-
expect(config.color).to be_truthy
|
|
1046
|
-
end
|
|
1047
|
-
end
|
|
1048
|
-
|
|
1049
|
-
describe '#formatter=' do
|
|
1050
|
-
it "delegates to add_formatter (better API for user-facing configuration)" do
|
|
1051
|
-
config.should_receive(:add_formatter).with('these','options')
|
|
1052
|
-
config.add_formatter('these','options')
|
|
1053
|
-
end
|
|
1054
|
-
end
|
|
1055
|
-
|
|
1056
|
-
describe "#add_formatter" do
|
|
1057
|
-
|
|
1058
|
-
it "adds to the list of formatters" do
|
|
1059
|
-
config.add_formatter :documentation
|
|
1060
|
-
expect(config.formatters.first).to be_an_instance_of(Formatters::DocumentationFormatter)
|
|
1061
|
-
end
|
|
1062
|
-
|
|
1063
|
-
it "finds a formatter by name (w/ Symbol)" do
|
|
1064
|
-
config.add_formatter :documentation
|
|
1065
|
-
expect(config.formatters.first).to be_an_instance_of(Formatters::DocumentationFormatter)
|
|
1066
|
-
end
|
|
1067
|
-
|
|
1068
|
-
it "finds a formatter by name (w/ String)" do
|
|
1069
|
-
config.add_formatter 'documentation'
|
|
1070
|
-
expect(config.formatters.first).to be_an_instance_of(Formatters::DocumentationFormatter)
|
|
1071
|
-
end
|
|
1072
|
-
|
|
1073
|
-
it "finds a formatter by class" do
|
|
1074
|
-
formatter_class = Class.new(Formatters::BaseTextFormatter)
|
|
1075
|
-
config.add_formatter formatter_class
|
|
1076
|
-
expect(config.formatters.first).to be_an_instance_of(formatter_class)
|
|
1077
|
-
end
|
|
1078
|
-
|
|
1079
|
-
it "finds a formatter by class name" do
|
|
1080
|
-
stub_const("CustomFormatter", Class.new(Formatters::BaseFormatter))
|
|
1081
|
-
config.add_formatter "CustomFormatter"
|
|
1082
|
-
expect(config.formatters.first).to be_an_instance_of(CustomFormatter)
|
|
1083
|
-
end
|
|
1084
|
-
|
|
1085
|
-
it "finds a formatter by class fully qualified name" do
|
|
1086
|
-
stub_const("RSpec::CustomFormatter", Class.new(Formatters::BaseFormatter))
|
|
1087
|
-
config.add_formatter "RSpec::CustomFormatter"
|
|
1088
|
-
expect(config.formatters.first).to be_an_instance_of(RSpec::CustomFormatter)
|
|
1089
|
-
end
|
|
1090
|
-
|
|
1091
|
-
it "requires a formatter file based on its fully qualified name" do
|
|
1092
|
-
config.formatter_loader.should_receive(:require).with('rspec/custom_formatter') do
|
|
1093
|
-
stub_const("RSpec::CustomFormatter", Class.new(Formatters::BaseFormatter))
|
|
1094
|
-
end
|
|
1095
|
-
config.add_formatter "RSpec::CustomFormatter"
|
|
1096
|
-
expect(config.formatters.first).to be_an_instance_of(RSpec::CustomFormatter)
|
|
1097
|
-
end
|
|
1098
|
-
|
|
1099
|
-
it "raises NameError if class is unresolvable" do
|
|
1100
|
-
config.formatter_loader.should_receive(:require).with('rspec/custom_formatter3')
|
|
1101
|
-
expect(lambda { config.add_formatter "RSpec::CustomFormatter3" }).to raise_error(NameError)
|
|
1102
|
-
end
|
|
1103
|
-
|
|
1104
|
-
it "raises ArgumentError if formatter is unknown" do
|
|
1105
|
-
expect(lambda { config.add_formatter :progresss }).to raise_error(ArgumentError)
|
|
1106
|
-
end
|
|
1107
|
-
|
|
1108
|
-
it 'warns of deprecation for old document aliases' do
|
|
1109
|
-
expect_deprecation_with_call_site __FILE__, __LINE__ + 1, 's'
|
|
1110
|
-
config.add_formatter 's'
|
|
1111
|
-
expect(config.formatters.first).to be_an_instance_of Formatters::DocumentationFormatter
|
|
1112
|
-
end
|
|
1113
|
-
|
|
1114
|
-
it 'warns of deprecation of the text mate formatter' do
|
|
1115
|
-
expect_deprecation_with_call_site __FILE__, __LINE__ + 1, /rspec-core/
|
|
1116
|
-
config.add_formatter 't'
|
|
1117
|
-
end
|
|
1118
|
-
|
|
1119
|
-
it 'warns of deprecation of the shortcut for the text mate formatter' do
|
|
1120
|
-
stub_const("::RSpec::Mate::Formatters::TextMateFormatter", double)
|
|
1121
|
-
expect_deprecation_with_call_site __FILE__, __LINE__ + 1, /shortcut/
|
|
1122
|
-
config.add_formatter 't'
|
|
1123
|
-
end
|
|
1124
|
-
|
|
1125
|
-
context "with a 2nd arg defining the output" do
|
|
1126
|
-
let(:path) { File.join(Dir.tmpdir, 'output.txt') }
|
|
1127
|
-
|
|
1128
|
-
it "creates a file at that path and sets it as the output" do
|
|
1129
|
-
config.add_formatter('doc', path)
|
|
1130
|
-
expect(config.formatters.first.output).to be_a(File)
|
|
1131
|
-
expect(config.formatters.first.output.path).to eq(path)
|
|
1132
|
-
end
|
|
1133
|
-
|
|
1134
|
-
it "accepts Pathname objects for file paths" do
|
|
1135
|
-
pathname = Pathname.new(path)
|
|
1136
|
-
config.add_formatter('doc', pathname)
|
|
1137
|
-
expect(config.formatters.first.output).to be_a(File)
|
|
1138
|
-
expect(config.formatters.first.output.path).to eq(path)
|
|
1139
|
-
end
|
|
1140
|
-
end
|
|
1141
|
-
end
|
|
1142
|
-
|
|
1143
|
-
describe "#formatters" do
|
|
1144
|
-
it "is deprecated to mutate the array" do
|
|
1145
|
-
expect_deprecation_with_call_site __FILE__, __LINE__ + 1
|
|
1146
|
-
config.formatters.clear
|
|
1147
|
-
end
|
|
1148
|
-
end
|
|
1149
|
-
|
|
1150
|
-
describe "#filter_run_including" do
|
|
1151
|
-
it_behaves_like "metadata hash builder" do
|
|
1152
|
-
def metadata_hash(*args)
|
|
1153
|
-
config.filter_run_including(*args)
|
|
1154
|
-
config.inclusion_filter
|
|
1155
|
-
end
|
|
1156
|
-
end
|
|
1157
|
-
|
|
1158
|
-
it "sets the filter with a hash" do
|
|
1159
|
-
config.filter_run_including :foo => true
|
|
1160
|
-
expect(config.inclusion_filter[:foo]).to be(true)
|
|
1161
|
-
end
|
|
1162
|
-
|
|
1163
|
-
it "sets the filter with a symbol" do
|
|
1164
|
-
RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
|
|
1165
|
-
config.filter_run_including :foo
|
|
1166
|
-
expect(config.inclusion_filter[:foo]).to be(true)
|
|
1167
|
-
end
|
|
1168
|
-
|
|
1169
|
-
it "merges with existing filters" do
|
|
1170
|
-
config.filter_run_including :foo => true
|
|
1171
|
-
config.filter_run_including :bar => false
|
|
1172
|
-
|
|
1173
|
-
expect(config.inclusion_filter[:foo]).to be(true)
|
|
1174
|
-
expect(config.inclusion_filter[:bar]).to be(false)
|
|
1175
|
-
end
|
|
1176
|
-
|
|
1177
|
-
context "given `:focused => true`" do
|
|
1178
|
-
it "issues a deprecation warning" do
|
|
1179
|
-
expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 1, /filter_run_including :focused/)
|
|
1180
|
-
config.filter_run_including :focused => true
|
|
1181
|
-
end
|
|
1182
|
-
|
|
1183
|
-
it "issues a deprecation warning when using `filter_run`" do
|
|
1184
|
-
expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 1, /filter_run :focused/)
|
|
1185
|
-
config.filter_run :focused => true
|
|
1186
|
-
end
|
|
1187
|
-
end
|
|
1188
|
-
end
|
|
1189
|
-
|
|
1190
|
-
describe "#filter_run_excluding" do
|
|
1191
|
-
it_behaves_like "metadata hash builder" do
|
|
1192
|
-
def metadata_hash(*args)
|
|
1193
|
-
config.filter_run_excluding(*args)
|
|
1194
|
-
config.exclusion_filter
|
|
1195
|
-
end
|
|
1196
|
-
end
|
|
1197
|
-
|
|
1198
|
-
it "sets the filter" do
|
|
1199
|
-
config.filter_run_excluding :foo => true
|
|
1200
|
-
expect(config.exclusion_filter[:foo]).to be(true)
|
|
1201
|
-
end
|
|
1202
|
-
|
|
1203
|
-
it "sets the filter using a symbol" do
|
|
1204
|
-
RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
|
|
1205
|
-
config.filter_run_excluding :foo
|
|
1206
|
-
expect(config.exclusion_filter[:foo]).to be(true)
|
|
1207
|
-
end
|
|
1208
|
-
|
|
1209
|
-
it "merges with existing filters" do
|
|
1210
|
-
config.filter_run_excluding :foo => true
|
|
1211
|
-
config.filter_run_excluding :bar => false
|
|
1212
|
-
|
|
1213
|
-
expect(config.exclusion_filter[:foo]).to be(true)
|
|
1214
|
-
expect(config.exclusion_filter[:bar]).to be(false)
|
|
1215
|
-
end
|
|
1216
|
-
end
|
|
1217
|
-
|
|
1218
|
-
describe "#inclusion_filter" do
|
|
1219
|
-
it "returns {} even if set to nil" do
|
|
1220
|
-
config.inclusion_filter = nil
|
|
1221
|
-
expect(config.inclusion_filter).to eq({})
|
|
1222
|
-
end
|
|
1223
|
-
end
|
|
1224
|
-
|
|
1225
|
-
describe "#inclusion_filter=" do
|
|
1226
|
-
it "treats symbols as hash keys with true values when told to" do
|
|
1227
|
-
RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
|
|
1228
|
-
config.inclusion_filter = :foo
|
|
1229
|
-
expect(config.inclusion_filter).to eq({:foo => true})
|
|
1230
|
-
end
|
|
1231
|
-
|
|
1232
|
-
it "overrides any inclusion filters set on the command line or in configuration files" do
|
|
1233
|
-
config.force(:inclusion_filter => { :foo => :bar })
|
|
1234
|
-
config.inclusion_filter = {:want => :this}
|
|
1235
|
-
expect(config.inclusion_filter).to eq({:want => :this})
|
|
1236
|
-
end
|
|
1237
|
-
end
|
|
1238
|
-
|
|
1239
|
-
describe "#exclusion_filter" do
|
|
1240
|
-
it "returns {} even if set to nil" do
|
|
1241
|
-
config.exclusion_filter = nil
|
|
1242
|
-
expect(config.exclusion_filter).to eq({})
|
|
1243
|
-
end
|
|
1244
|
-
|
|
1245
|
-
describe "the default :if filter" do
|
|
1246
|
-
it "does not exclude a spec with { :if => true } metadata" do
|
|
1247
|
-
expect(config.exclusion_filter[:if].call(true)).to be_falsey
|
|
1248
|
-
end
|
|
1249
|
-
|
|
1250
|
-
it "excludes a spec with { :if => false } metadata" do
|
|
1251
|
-
expect(config.exclusion_filter[:if].call(false)).to be_truthy
|
|
1252
|
-
end
|
|
1253
|
-
|
|
1254
|
-
it "excludes a spec with { :if => nil } metadata" do
|
|
1255
|
-
expect(config.exclusion_filter[:if].call(nil)).to be_truthy
|
|
1256
|
-
end
|
|
1257
|
-
end
|
|
1258
|
-
|
|
1259
|
-
describe "the default :unless filter" do
|
|
1260
|
-
it "excludes a spec with { :unless => true } metadata" do
|
|
1261
|
-
expect(config.exclusion_filter[:unless].call(true)).to be_truthy
|
|
1262
|
-
end
|
|
1263
|
-
|
|
1264
|
-
it "does not exclude a spec with { :unless => false } metadata" do
|
|
1265
|
-
expect(config.exclusion_filter[:unless].call(false)).to be_falsey
|
|
1266
|
-
end
|
|
1267
|
-
|
|
1268
|
-
it "does not exclude a spec with { :unless => nil } metadata" do
|
|
1269
|
-
expect(config.exclusion_filter[:unless].call(nil)).to be_falsey
|
|
1270
|
-
end
|
|
1271
|
-
end
|
|
1272
|
-
end
|
|
1273
|
-
|
|
1274
|
-
describe "#exclusion_filter=" do
|
|
1275
|
-
it "treats symbols as hash keys with true values when told to" do
|
|
1276
|
-
RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
|
|
1277
|
-
config.exclusion_filter = :foo
|
|
1278
|
-
expect(config.exclusion_filter).to eq({:foo => true})
|
|
1279
|
-
end
|
|
1280
|
-
|
|
1281
|
-
it "overrides any exclusion filters set on the command line or in configuration files" do
|
|
1282
|
-
config.force(:exclusion_filter => { :foo => :bar })
|
|
1283
|
-
config.exclusion_filter = {:want => :this}
|
|
1284
|
-
expect(config.exclusion_filter).to eq({:want => :this})
|
|
1285
|
-
end
|
|
1286
|
-
end
|
|
1287
|
-
|
|
1288
|
-
describe "line_numbers=" do
|
|
1289
|
-
before { config.filter_manager.stub(:warn) }
|
|
1290
|
-
|
|
1291
|
-
it "sets the line numbers" do
|
|
1292
|
-
config.line_numbers = ['37']
|
|
1293
|
-
expect(config.filter).to eq({:line_numbers => [37]})
|
|
1294
|
-
end
|
|
1295
|
-
|
|
1296
|
-
it "overrides filters" do
|
|
1297
|
-
config.filter_run :focused => true
|
|
1298
|
-
config.line_numbers = ['37']
|
|
1299
|
-
expect(config.filter).to eq({:line_numbers => [37]})
|
|
1300
|
-
end
|
|
1301
|
-
|
|
1302
|
-
it "prevents subsequent filters" do
|
|
1303
|
-
config.line_numbers = ['37']
|
|
1304
|
-
config.filter_run :focused => true
|
|
1305
|
-
expect(config.filter).to eq({:line_numbers => [37]})
|
|
1306
|
-
end
|
|
1307
|
-
end
|
|
1308
|
-
|
|
1309
|
-
describe "line_numbers" do
|
|
1310
|
-
it "returns the line numbers from the filter" do
|
|
1311
|
-
config.line_numbers = ['42']
|
|
1312
|
-
expect(config.line_numbers).to eq [42]
|
|
1313
|
-
end
|
|
1314
|
-
|
|
1315
|
-
it "defaults to empty" do
|
|
1316
|
-
expect(config.line_numbers).to eq []
|
|
1317
|
-
end
|
|
1318
|
-
end
|
|
1319
|
-
|
|
1320
|
-
describe "#full_backtrace=" do
|
|
1321
|
-
context "given true" do
|
|
1322
|
-
it "clears the backtrace exclusion patterns" do
|
|
1323
|
-
config.full_backtrace = true
|
|
1324
|
-
expect(config.backtrace_exclusion_patterns).to eq([])
|
|
1325
|
-
end
|
|
1326
|
-
end
|
|
1327
|
-
|
|
1328
|
-
context "given false" do
|
|
1329
|
-
it "restores backtrace clean patterns" do
|
|
1330
|
-
config.full_backtrace = false
|
|
1331
|
-
expect(config.backtrace_exclusion_patterns).to eq(RSpec::Core::BacktraceCleaner::DEFAULT_EXCLUSION_PATTERNS)
|
|
1332
|
-
end
|
|
1333
|
-
end
|
|
1334
|
-
|
|
1335
|
-
it "doesn't impact other instances of config" do
|
|
1336
|
-
config_1 = Configuration.new
|
|
1337
|
-
config_2 = Configuration.new
|
|
1338
|
-
|
|
1339
|
-
config_1.full_backtrace = true
|
|
1340
|
-
expect(config_2.backtrace_exclusion_patterns).not_to be_empty
|
|
1341
|
-
end
|
|
1342
|
-
end
|
|
1343
|
-
|
|
1344
|
-
describe "#backtrace_clean_patterns=" do
|
|
1345
|
-
it "actually receives the new filter values" do
|
|
1346
|
-
RSpec.stub(:deprecate)
|
|
1347
|
-
config = Configuration.new
|
|
1348
|
-
config.backtrace_clean_patterns = [/.*/]
|
|
1349
|
-
expect(config.backtrace_formatter.exclude? "this").to be_truthy
|
|
1350
|
-
end
|
|
1351
|
-
end
|
|
1352
|
-
|
|
1353
|
-
describe 'full_backtrace' do
|
|
1354
|
-
it 'returns true when backtrace patterns is empty' do
|
|
1355
|
-
config.backtrace_exclusion_patterns = []
|
|
1356
|
-
expect(config.full_backtrace?).to eq true
|
|
1357
|
-
end
|
|
1358
|
-
|
|
1359
|
-
it 'returns false when backtrace patterns isnt empty' do
|
|
1360
|
-
config.backtrace_exclusion_patterns = [:lib]
|
|
1361
|
-
expect(config.full_backtrace?).to eq false
|
|
1362
|
-
end
|
|
1363
|
-
end
|
|
1364
|
-
|
|
1365
|
-
describe "#backtrace_clean_patterns" do
|
|
1366
|
-
before { allow(RSpec).to receive(:deprecate) }
|
|
1367
|
-
it "is deprecated" do
|
|
1368
|
-
RSpec.should_receive(:deprecate)
|
|
1369
|
-
config = Configuration.new
|
|
1370
|
-
config.backtrace_clean_patterns
|
|
1371
|
-
end
|
|
1372
|
-
|
|
1373
|
-
it "can be appended to" do
|
|
1374
|
-
config = Configuration.new
|
|
1375
|
-
config.backtrace_clean_patterns << /.*/
|
|
1376
|
-
expect(config.backtrace_formatter.exclude? "this").to be_truthy
|
|
1377
|
-
end
|
|
1378
|
-
end
|
|
1379
|
-
|
|
1380
|
-
specify "#backtrace_cleaner is deprecated" do
|
|
1381
|
-
expect_deprecation_with_call_site __FILE__, __LINE__ + 1
|
|
1382
|
-
config.backtrace_cleaner
|
|
1383
|
-
end
|
|
1384
|
-
|
|
1385
|
-
describe ".backtrace_formatter#exclude? defaults" do
|
|
1386
|
-
before { allow_deprecation }
|
|
1387
|
-
|
|
1388
|
-
it "returns true for rspec files" do
|
|
1389
|
-
expect(config.backtrace_formatter.exclude?("lib/rspec/core.rb")).to be_truthy
|
|
1390
|
-
end
|
|
1391
|
-
|
|
1392
|
-
it "returns true for spec_helper" do
|
|
1393
|
-
expect(config.backtrace_formatter.exclude?("spec/spec_helper.rb")).to be_truthy
|
|
1394
|
-
end
|
|
1395
|
-
|
|
1396
|
-
it "returns true for java files (for JRuby)" do
|
|
1397
|
-
expect(config.backtrace_formatter.exclude?("org/jruby/RubyArray.java:2336")).to be_truthy
|
|
1398
|
-
end
|
|
1399
|
-
|
|
1400
|
-
it "returns true for files within installed gems" do
|
|
1401
|
-
expect(config.backtrace_formatter.exclude?('ruby-1.8.7-p334/gems/mygem-2.3.0/lib/mygem.rb')).to be_truthy
|
|
1402
|
-
end
|
|
1403
|
-
|
|
1404
|
-
it "returns false for files in projects containing 'gems' in the name" do
|
|
1405
|
-
expect(config.backtrace_formatter.exclude?('code/my-gems-plugin/lib/plugin.rb')).to be_falsey
|
|
1406
|
-
end
|
|
1407
|
-
|
|
1408
|
-
it "returns false for something in the current working directory" do
|
|
1409
|
-
expect(config.backtrace_formatter.exclude?("#{Dir.getwd}/arbitrary")).to be_falsey
|
|
1410
|
-
end
|
|
1411
|
-
end
|
|
1412
|
-
|
|
1413
|
-
describe "#debug=true" do
|
|
1414
|
-
before do
|
|
1415
|
-
if defined?(Debugger)
|
|
1416
|
-
@orig_debugger = Debugger
|
|
1417
|
-
Object.send(:remove_const, :Debugger)
|
|
1418
|
-
else
|
|
1419
|
-
@orig_debugger = nil
|
|
1420
|
-
end
|
|
1421
|
-
config.stub(:require)
|
|
1422
|
-
Object.const_set("Debugger", debugger)
|
|
1423
|
-
|
|
1424
|
-
allow_deprecation
|
|
1425
|
-
end
|
|
1426
|
-
|
|
1427
|
-
after do
|
|
1428
|
-
Object.send(:remove_const, :Debugger)
|
|
1429
|
-
Object.const_set("Debugger", @orig_debugger) if @orig_debugger
|
|
1430
|
-
end
|
|
1431
|
-
|
|
1432
|
-
let(:debugger) { double('Debugger').as_null_object }
|
|
1433
|
-
|
|
1434
|
-
it "requires 'ruby-debug'" do
|
|
1435
|
-
config.should_receive(:require).with('ruby-debug')
|
|
1436
|
-
config.debug = true
|
|
1437
|
-
end
|
|
1438
|
-
|
|
1439
|
-
it "starts the debugger" do
|
|
1440
|
-
debugger.should_receive(:start)
|
|
1441
|
-
config.debug = true
|
|
1442
|
-
end
|
|
1443
|
-
|
|
1444
|
-
it "warns that this feature is deprecated" do
|
|
1445
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
|
|
1446
|
-
config.debug = true
|
|
1447
|
-
end
|
|
1448
|
-
end
|
|
1449
|
-
|
|
1450
|
-
describe "#debug=false" do
|
|
1451
|
-
before { allow_deprecation }
|
|
1452
|
-
|
|
1453
|
-
it "does not require 'ruby-debug'" do
|
|
1454
|
-
config.should_not_receive(:require).with('ruby-debug')
|
|
1455
|
-
config.debug = false
|
|
1456
|
-
end
|
|
1457
|
-
|
|
1458
|
-
it "warns that this feature is deprecated" do
|
|
1459
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
|
|
1460
|
-
config.debug = false
|
|
1461
|
-
end
|
|
1462
|
-
end
|
|
1463
|
-
|
|
1464
|
-
describe "#debug?" do
|
|
1465
|
-
before { allow_deprecation }
|
|
1466
|
-
|
|
1467
|
-
it 'returns true if the debugger has been loaded' do
|
|
1468
|
-
stub_const("Debugger", Object.new)
|
|
1469
|
-
expect(config.debug?).to be_truthy
|
|
1470
|
-
end
|
|
1471
|
-
|
|
1472
|
-
it 'returns false if the debugger has not been loaded' do
|
|
1473
|
-
hide_const("Debugger")
|
|
1474
|
-
expect(config.debug?).to be_falsey
|
|
1475
|
-
end
|
|
1476
|
-
|
|
1477
|
-
it "warns that this feature is deprecated" do
|
|
1478
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
|
|
1479
|
-
config.debug?
|
|
1480
|
-
end
|
|
1481
|
-
end
|
|
1482
|
-
|
|
1483
|
-
describe "#libs=" do
|
|
1484
|
-
include_context "isolate load path mutation"
|
|
1485
|
-
|
|
1486
|
-
it "adds directories to the LOAD_PATH" do
|
|
1487
|
-
$LOAD_PATH.should_receive(:unshift).with("a/dir")
|
|
1488
|
-
config.libs = ["a/dir"]
|
|
1489
|
-
end
|
|
1490
|
-
end
|
|
1491
|
-
|
|
1492
|
-
describe "libs" do
|
|
1493
|
-
include_context "isolate load path mutation"
|
|
1494
|
-
|
|
1495
|
-
it 'records paths added to the load path' do
|
|
1496
|
-
config.libs = ["a/dir"]
|
|
1497
|
-
expect(config.libs).to eq ["a/dir"]
|
|
1498
|
-
end
|
|
1499
|
-
end
|
|
1500
|
-
|
|
1501
|
-
describe "#requires=" do
|
|
1502
|
-
before { RSpec.should_receive :deprecate }
|
|
1503
|
-
|
|
1504
|
-
it "requires the configured files" do
|
|
1505
|
-
config.should_receive(:require).with('foo').ordered
|
|
1506
|
-
config.should_receive(:require).with('bar').ordered
|
|
1507
|
-
config.requires = ['foo', 'bar']
|
|
1508
|
-
end
|
|
1509
|
-
|
|
1510
|
-
it "stores require paths" do
|
|
1511
|
-
config.should_receive(:require).with("a/path")
|
|
1512
|
-
config.requires = ["a/path"]
|
|
1513
|
-
expect(config.requires).to eq ['a/path']
|
|
1514
|
-
end
|
|
1515
|
-
end
|
|
1516
|
-
|
|
1517
|
-
describe "#add_setting" do
|
|
1518
|
-
describe "with no modifiers" do
|
|
1519
|
-
context "with no additional options" do
|
|
1520
|
-
before do
|
|
1521
|
-
config.add_setting :custom_option
|
|
1522
|
-
end
|
|
1523
|
-
|
|
1524
|
-
it "defaults to nil" do
|
|
1525
|
-
expect(config.custom_option).to be_nil
|
|
1526
|
-
end
|
|
1527
|
-
|
|
1528
|
-
it "adds a predicate" do
|
|
1529
|
-
expect(config.custom_option?).to be_falsey
|
|
1530
|
-
end
|
|
1531
|
-
|
|
1532
|
-
it "can be overridden" do
|
|
1533
|
-
config.custom_option = "a value"
|
|
1534
|
-
expect(config.custom_option).to eq("a value")
|
|
1535
|
-
end
|
|
1536
|
-
end
|
|
1537
|
-
|
|
1538
|
-
context "with :default => 'a value'" do
|
|
1539
|
-
before do
|
|
1540
|
-
config.add_setting :custom_option, :default => 'a value'
|
|
1541
|
-
end
|
|
1542
|
-
|
|
1543
|
-
it "defaults to 'a value'" do
|
|
1544
|
-
expect(config.custom_option).to eq("a value")
|
|
1545
|
-
end
|
|
1546
|
-
|
|
1547
|
-
it "returns true for the predicate" do
|
|
1548
|
-
expect(config.custom_option?).to be_truthy
|
|
1549
|
-
end
|
|
1550
|
-
|
|
1551
|
-
it "can be overridden with a truthy value" do
|
|
1552
|
-
config.custom_option = "a new value"
|
|
1553
|
-
expect(config.custom_option).to eq("a new value")
|
|
1554
|
-
end
|
|
1555
|
-
|
|
1556
|
-
it "can be overridden with nil" do
|
|
1557
|
-
config.custom_option = nil
|
|
1558
|
-
expect(config.custom_option).to eq(nil)
|
|
1559
|
-
end
|
|
1560
|
-
|
|
1561
|
-
it "can be overridden with false" do
|
|
1562
|
-
config.custom_option = false
|
|
1563
|
-
expect(config.custom_option).to eq(false)
|
|
1564
|
-
end
|
|
1565
|
-
end
|
|
1566
|
-
end
|
|
1567
|
-
|
|
1568
|
-
context "with :alias => " do
|
|
1569
|
-
it "is deprecated" do
|
|
1570
|
-
RSpec::should_receive(:deprecate).with(/:alias option/, :replacement => ":alias_with")
|
|
1571
|
-
config.add_setting :custom_option
|
|
1572
|
-
config.add_setting :another_custom_option, :alias => :custom_option
|
|
1573
|
-
end
|
|
1574
|
-
end
|
|
1575
|
-
|
|
1576
|
-
context "with :alias_with => " do
|
|
1577
|
-
before do
|
|
1578
|
-
config.add_setting :custom_option, :alias_with => :another_custom_option
|
|
1579
|
-
end
|
|
1580
|
-
|
|
1581
|
-
it "delegates the getter to the other option" do
|
|
1582
|
-
config.another_custom_option = "this value"
|
|
1583
|
-
expect(config.custom_option).to eq("this value")
|
|
1584
|
-
end
|
|
1585
|
-
|
|
1586
|
-
it "delegates the setter to the other option" do
|
|
1587
|
-
config.custom_option = "this value"
|
|
1588
|
-
expect(config.another_custom_option).to eq("this value")
|
|
1589
|
-
end
|
|
1590
|
-
|
|
1591
|
-
it "delegates the predicate to the other option" do
|
|
1592
|
-
config.custom_option = true
|
|
1593
|
-
expect(config.another_custom_option?).to be_truthy
|
|
1594
|
-
end
|
|
1595
|
-
end
|
|
1596
|
-
end
|
|
1597
|
-
|
|
1598
|
-
describe "#configure_group" do
|
|
1599
|
-
it "extends with 'extend'" do
|
|
1600
|
-
mod = Module.new
|
|
1601
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
|
1602
|
-
|
|
1603
|
-
config.extend(mod, :foo => :bar)
|
|
1604
|
-
config.configure_group(group)
|
|
1605
|
-
expect(group).to be_a(mod)
|
|
1606
|
-
end
|
|
1607
|
-
|
|
1608
|
-
it "extends with 'module'" do
|
|
1609
|
-
mod = Module.new
|
|
1610
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
|
1611
|
-
|
|
1612
|
-
config.include(mod, :foo => :bar)
|
|
1613
|
-
config.configure_group(group)
|
|
1614
|
-
expect(group.included_modules).to include(mod)
|
|
1615
|
-
end
|
|
1616
|
-
|
|
1617
|
-
it "requires only one matching filter" do
|
|
1618
|
-
mod = Module.new
|
|
1619
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
|
1620
|
-
|
|
1621
|
-
config.include(mod, :foo => :bar, :baz => :bam)
|
|
1622
|
-
config.configure_group(group)
|
|
1623
|
-
expect(group.included_modules).to include(mod)
|
|
1624
|
-
end
|
|
1625
|
-
|
|
1626
|
-
it "includes each one before deciding whether to include the next" do
|
|
1627
|
-
mod1 = Module.new do
|
|
1628
|
-
def self.included(host)
|
|
1629
|
-
host.metadata[:foo] = :bar
|
|
1630
|
-
end
|
|
1631
|
-
end
|
|
1632
|
-
mod2 = Module.new
|
|
1633
|
-
|
|
1634
|
-
group = ExampleGroup.describe("group")
|
|
1635
|
-
|
|
1636
|
-
config.include(mod1)
|
|
1637
|
-
config.include(mod2, :foo => :bar)
|
|
1638
|
-
config.configure_group(group)
|
|
1639
|
-
expect(group.included_modules).to include(mod1)
|
|
1640
|
-
expect(group.included_modules).to include(mod2)
|
|
1641
|
-
end
|
|
1642
|
-
|
|
1643
|
-
module IncludeOrExtendMeOnce
|
|
1644
|
-
def self.included(host)
|
|
1645
|
-
raise "included again" if host.instance_methods.include?(:foobar)
|
|
1646
|
-
host.class_eval { def foobar; end }
|
|
1647
|
-
end
|
|
1648
|
-
|
|
1649
|
-
def self.extended(host)
|
|
1650
|
-
raise "extended again" if host.respond_to?(:foobar)
|
|
1651
|
-
def host.foobar; end
|
|
1652
|
-
end
|
|
1653
|
-
end
|
|
1654
|
-
|
|
1655
|
-
it "doesn't include a module when already included in ancestor" do
|
|
1656
|
-
config.include(IncludeOrExtendMeOnce, :foo => :bar)
|
|
1657
|
-
|
|
1658
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
|
1659
|
-
child = group.describe("child")
|
|
1660
|
-
|
|
1661
|
-
config.configure_group(group)
|
|
1662
|
-
config.configure_group(child)
|
|
1663
|
-
end
|
|
1664
|
-
|
|
1665
|
-
it "doesn't extend when ancestor is already extended with same module" do
|
|
1666
|
-
config.extend(IncludeOrExtendMeOnce, :foo => :bar)
|
|
1667
|
-
|
|
1668
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
|
1669
|
-
child = group.describe("child")
|
|
1670
|
-
|
|
1671
|
-
config.configure_group(group)
|
|
1672
|
-
config.configure_group(child)
|
|
1673
|
-
end
|
|
1674
|
-
end
|
|
1675
|
-
|
|
1676
|
-
describe "#alias_example_to" do
|
|
1677
|
-
it_behaves_like "metadata hash builder" do
|
|
1678
|
-
after do
|
|
1679
|
-
RSpec::Core::ExampleGroup.module_eval do
|
|
1680
|
-
class << self
|
|
1681
|
-
undef :my_example_method if method_defined? :my_example_method
|
|
1682
|
-
end
|
|
1683
|
-
end
|
|
1684
|
-
end
|
|
1685
|
-
def metadata_hash(*args)
|
|
1686
|
-
config.alias_example_to :my_example_method, *args
|
|
1687
|
-
group = ExampleGroup.describe("group")
|
|
1688
|
-
example = group.my_example_method("description")
|
|
1689
|
-
example.metadata
|
|
1690
|
-
end
|
|
1691
|
-
end
|
|
1692
|
-
end
|
|
1693
|
-
|
|
1694
|
-
describe "#reset" do
|
|
1695
|
-
it "clears the reporter" do
|
|
1696
|
-
expect(config.reporter).not_to be_nil
|
|
1697
|
-
config.reset
|
|
1698
|
-
expect(config.instance_variable_get("@reporter")).to be_nil
|
|
1699
|
-
end
|
|
1700
|
-
|
|
1701
|
-
it "clears the formatters" do
|
|
1702
|
-
config.add_formatter "doc"
|
|
1703
|
-
config.reset
|
|
1704
|
-
expect(config.formatters).to be_empty
|
|
1705
|
-
end
|
|
1706
|
-
end
|
|
1707
|
-
|
|
1708
|
-
describe "#force" do
|
|
1709
|
-
let(:collection) { [1, 2, 3, 4] }
|
|
1710
|
-
let(:ordered) { config.group_ordering_block.call(collection) }
|
|
1711
|
-
|
|
1712
|
-
it "forces order (when given default)" do
|
|
1713
|
-
config.force :order => "default"
|
|
1714
|
-
config.order = "rand"
|
|
1715
|
-
|
|
1716
|
-
expect(config.order).to eq("default")
|
|
1717
|
-
expect(ordered).to eq([1, 2, 3, 4])
|
|
1718
|
-
end
|
|
1719
|
-
|
|
1720
|
-
it "forces order (when given defined)" do
|
|
1721
|
-
config.force :order => "defined"
|
|
1722
|
-
config.order = "rand"
|
|
1723
|
-
|
|
1724
|
-
expect(config.order).to eq("defined")
|
|
1725
|
-
expect(ordered).to eq([1, 2, 3, 4])
|
|
1726
|
-
end
|
|
1727
|
-
|
|
1728
|
-
it "forces order and seed with :order => 'rand:37'" do
|
|
1729
|
-
config.force :order => "rand:37"
|
|
1730
|
-
config.order = "default"
|
|
1731
|
-
|
|
1732
|
-
expect(config.order).to eq("rand")
|
|
1733
|
-
expect(config.seed).to eq(37)
|
|
1734
|
-
|
|
1735
|
-
allow(Kernel).to receive(:rand).and_return(3, 1, 4, 2)
|
|
1736
|
-
expect(ordered).to_not eq([1, 2, 3, 4])
|
|
1737
|
-
end
|
|
1738
|
-
|
|
1739
|
-
it "forces order and seed with :seed => '37'" do
|
|
1740
|
-
config.force :seed => "37"
|
|
1741
|
-
config.order = "defined"
|
|
1742
|
-
|
|
1743
|
-
expect(config.seed).to eq(37)
|
|
1744
|
-
expect(config.order).to eq("rand")
|
|
1745
|
-
|
|
1746
|
-
allow(Kernel).to receive(:rand).and_return(3, 1, 4, 2)
|
|
1747
|
-
expect(ordered).to eq([2, 4, 1, 3])
|
|
1748
|
-
end
|
|
1749
|
-
|
|
1750
|
-
it 'can set random ordering' do
|
|
1751
|
-
config.force :seed => "rand:37"
|
|
1752
|
-
RSpec.stub(:configuration => config)
|
|
1753
|
-
list = [1, 2, 3, 4].extend(Extensions::Ordered::Examples)
|
|
1754
|
-
Kernel.should_receive(:rand).and_return(3, 1, 4, 2)
|
|
1755
|
-
expect(list.ordered).to eq([2, 4, 1, 3])
|
|
1756
|
-
end
|
|
1757
|
-
|
|
1758
|
-
it "forces 'false' value" do
|
|
1759
|
-
config.add_setting :custom_option
|
|
1760
|
-
config.custom_option = true
|
|
1761
|
-
expect(config.custom_option?).to be_truthy
|
|
1762
|
-
config.force :custom_option => false
|
|
1763
|
-
expect(config.custom_option?).to be_falsey
|
|
1764
|
-
config.custom_option = true
|
|
1765
|
-
expect(config.custom_option?).to be_falsey
|
|
1766
|
-
end
|
|
1767
|
-
end
|
|
1768
|
-
|
|
1769
|
-
describe '#seed' do
|
|
1770
|
-
it 'returns the seed as an int' do
|
|
1771
|
-
config.seed = '123'
|
|
1772
|
-
expect(config.seed).to eq(123)
|
|
1773
|
-
end
|
|
1774
|
-
end
|
|
1775
|
-
|
|
1776
|
-
describe '#randomize?' do
|
|
1777
|
-
context 'with order set to :random' do
|
|
1778
|
-
before { config.order = :random }
|
|
1779
|
-
|
|
1780
|
-
it 'returns true' do
|
|
1781
|
-
expect(config.randomize?).to be_truthy
|
|
1782
|
-
end
|
|
1783
|
-
end
|
|
1784
|
-
|
|
1785
|
-
context 'with order set to nil' do
|
|
1786
|
-
before { config.order = nil }
|
|
1787
|
-
|
|
1788
|
-
it 'returns false' do
|
|
1789
|
-
expect(config.randomize?).to be_falsey
|
|
1790
|
-
end
|
|
1791
|
-
end
|
|
1792
|
-
|
|
1793
|
-
it 'is deprecated' do
|
|
1794
|
-
expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 1, /randomize\?/)
|
|
1795
|
-
config.randomize?
|
|
1796
|
-
end
|
|
1797
|
-
end
|
|
1798
|
-
|
|
1799
|
-
describe '#order=' do
|
|
1800
|
-
context 'given "random:123"' do
|
|
1801
|
-
before { config.order = 'random:123' }
|
|
1802
|
-
|
|
1803
|
-
it 'sets order to "random"' do
|
|
1804
|
-
expect(config.order).to eq('random')
|
|
1805
|
-
end
|
|
1806
|
-
|
|
1807
|
-
it 'sets seed to 123' do
|
|
1808
|
-
expect(config.seed).to eq(123)
|
|
1809
|
-
end
|
|
1810
|
-
|
|
1811
|
-
it 'sets up random ordering' do
|
|
1812
|
-
RSpec.stub(:configuration => config)
|
|
1813
|
-
list = [1, 2, 3, 4].extend(Extensions::Ordered::Examples)
|
|
1814
|
-
Kernel.should_receive(:rand).and_return(3, 1, 4, 2)
|
|
1815
|
-
expect(list.ordered).to eq([2, 4, 1, 3])
|
|
1816
|
-
end
|
|
1817
|
-
end
|
|
1818
|
-
|
|
1819
|
-
shared_examples_for "defined order" do |order|
|
|
1820
|
-
before do
|
|
1821
|
-
config.order = 'rand:123'
|
|
1822
|
-
config.order = order
|
|
1823
|
-
end
|
|
1824
|
-
|
|
1825
|
-
it "sets the order to nil" do
|
|
1826
|
-
expect(config.order).to be_nil
|
|
1827
|
-
end
|
|
1828
|
-
|
|
1829
|
-
it "sets the seed to nil" do
|
|
1830
|
-
expect(config.seed).to be_nil
|
|
1831
|
-
end
|
|
1832
|
-
|
|
1833
|
-
it 'clears the random ordering' do
|
|
1834
|
-
RSpec.stub(:configuration => config)
|
|
1835
|
-
list = [1, 2, 3, 4].extend(Extensions::Ordered::Examples)
|
|
1836
|
-
Kernel.should_not_receive(:rand)
|
|
1837
|
-
expect(list.ordered).to eq([1, 2, 3, 4])
|
|
1838
|
-
end
|
|
1839
|
-
end
|
|
1840
|
-
|
|
1841
|
-
context "given 'default'" do
|
|
1842
|
-
include_examples "defined order", 'default'
|
|
1843
|
-
|
|
1844
|
-
it 'prints a deprecation notice' do
|
|
1845
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /default/)
|
|
1846
|
-
config.order = 'default'
|
|
1847
|
-
end
|
|
1848
|
-
end
|
|
1849
|
-
|
|
1850
|
-
context "given 'defined'" do
|
|
1851
|
-
include_examples "defined order", 'defined'
|
|
1852
|
-
end
|
|
1853
|
-
end
|
|
1854
|
-
|
|
1855
|
-
describe "#order_examples" do
|
|
1856
|
-
before do
|
|
1857
|
-
allow_deprecation
|
|
1858
|
-
RSpec.stub(:configuration => config)
|
|
1859
|
-
end
|
|
1860
|
-
|
|
1861
|
-
it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::Examples' do
|
|
1862
|
-
examples = [1, 2, 3, 4]
|
|
1863
|
-
examples.extend Extensions::Ordered::Examples
|
|
1864
|
-
config.order_examples { |examples_to_order| examples_to_order.reverse }
|
|
1865
|
-
expect(examples.ordered).to eq([4, 3, 2, 1])
|
|
1866
|
-
end
|
|
1867
|
-
|
|
1868
|
-
it 'sets #order to "custom"' do
|
|
1869
|
-
config.order_examples { |examples| examples.reverse }
|
|
1870
|
-
expect(config.order).to eq("custom")
|
|
1871
|
-
end
|
|
1872
|
-
|
|
1873
|
-
it 'prints a deprecation warning' do
|
|
1874
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /RSpec::Configuration#order_examples/)
|
|
1875
|
-
config.order_examples { }
|
|
1876
|
-
end
|
|
1877
|
-
end
|
|
1878
|
-
|
|
1879
|
-
describe "#example_ordering_block" do
|
|
1880
|
-
it 'defaults to a block that returns the passed argument' do
|
|
1881
|
-
expect(config.example_ordering_block.call([1, 2, 3])).to eq([1, 2, 3])
|
|
1882
|
-
end
|
|
1883
|
-
end
|
|
1884
|
-
|
|
1885
|
-
describe "#order_groups" do
|
|
1886
|
-
before do
|
|
1887
|
-
allow_deprecation
|
|
1888
|
-
RSpec.stub(:configuration => config)
|
|
1889
|
-
end
|
|
1890
|
-
|
|
1891
|
-
it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::ExampleGroups' do
|
|
1892
|
-
groups = [1, 2, 3, 4]
|
|
1893
|
-
groups.extend Extensions::Ordered::ExampleGroups
|
|
1894
|
-
config.order_groups { |groups_to_order| groups_to_order.reverse }
|
|
1895
|
-
expect(groups.ordered).to eq([4, 3, 2, 1])
|
|
1896
|
-
end
|
|
1897
|
-
|
|
1898
|
-
it 'sets #order to "custom"' do
|
|
1899
|
-
config.order_groups { |groups| groups.reverse }
|
|
1900
|
-
expect(config.order).to eq("custom")
|
|
1901
|
-
end
|
|
1902
|
-
|
|
1903
|
-
it 'prints a deprecation warning' do
|
|
1904
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /RSpec::Configuration#order_groups/)
|
|
1905
|
-
config.order_groups { }
|
|
1906
|
-
end
|
|
1907
|
-
end
|
|
1908
|
-
|
|
1909
|
-
describe "#group_ordering_block" do
|
|
1910
|
-
it 'defaults to a block that returns the passed argument' do
|
|
1911
|
-
expect(config.group_ordering_block.call([1, 2, 3])).to eq([1, 2, 3])
|
|
1912
|
-
end
|
|
1913
|
-
end
|
|
1914
|
-
|
|
1915
|
-
describe "#order_groups_and_examples" do
|
|
1916
|
-
let(:examples) { [1, 2, 3, 4].extend Extensions::Ordered::Examples }
|
|
1917
|
-
let(:groups) { [1, 2, 3, 4].extend Extensions::Ordered::ExampleGroups }
|
|
1918
|
-
|
|
1919
|
-
before do
|
|
1920
|
-
RSpec.stub(:configuration => config)
|
|
1921
|
-
config.order_groups_and_examples { |list| list.reverse }
|
|
1922
|
-
end
|
|
1923
|
-
|
|
1924
|
-
it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::Examples' do
|
|
1925
|
-
expect(examples.ordered).to eq([4, 3, 2, 1])
|
|
1926
|
-
end
|
|
1927
|
-
|
|
1928
|
-
it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::ExampleGroups' do
|
|
1929
|
-
expect(groups.ordered).to eq([4, 3, 2, 1])
|
|
1930
|
-
end
|
|
1931
|
-
end
|
|
1932
|
-
|
|
1933
|
-
describe "#register_ordering(:global)" do
|
|
1934
|
-
let(:examples) { [1, 2, 3, 4].extend Extensions::Ordered::Examples }
|
|
1935
|
-
let(:groups) { [1, 2, 3, 4].extend Extensions::Ordered::ExampleGroups }
|
|
1936
|
-
|
|
1937
|
-
before do
|
|
1938
|
-
RSpec.stub(:configuration => config)
|
|
1939
|
-
config.register_ordering(:global) { |list| list.reverse }
|
|
1940
|
-
end
|
|
1941
|
-
|
|
1942
|
-
it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::Examples' do
|
|
1943
|
-
expect(examples.ordered).to eq([4, 3, 2, 1])
|
|
1944
|
-
end
|
|
1945
|
-
|
|
1946
|
-
it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::ExampleGroups' do
|
|
1947
|
-
expect(groups.ordered).to eq([4, 3, 2, 1])
|
|
1948
|
-
end
|
|
1949
|
-
|
|
1950
|
-
it 'sets #order to "custom"' do
|
|
1951
|
-
expect(config.order).to eq("custom")
|
|
1952
|
-
end
|
|
1953
|
-
|
|
1954
|
-
it 'raises an ArgumentError if given a symbol other than `:global`' do
|
|
1955
|
-
expect {
|
|
1956
|
-
config.register_ordering(:custom) { }
|
|
1957
|
-
}.to raise_error(ArgumentError, /:global/)
|
|
1958
|
-
end
|
|
1959
|
-
end
|
|
1960
|
-
|
|
1961
|
-
describe "#order" do
|
|
1962
|
-
it 'is deprecated' do
|
|
1963
|
-
expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 1, /order/)
|
|
1964
|
-
config.order
|
|
1965
|
-
end
|
|
1966
|
-
end
|
|
1967
|
-
|
|
1968
|
-
describe '#warnings' do
|
|
1969
|
-
around do |example|
|
|
1970
|
-
@_original_setting = $VERBOSE
|
|
1971
|
-
example.run
|
|
1972
|
-
$VERBOSE = @_original_setting
|
|
1973
|
-
end
|
|
1974
|
-
|
|
1975
|
-
it "sets verbose to true when true" do
|
|
1976
|
-
config.warnings = true
|
|
1977
|
-
expect($VERBOSE).to eq true
|
|
1978
|
-
end
|
|
1979
|
-
|
|
1980
|
-
it "sets verbose to false when true" do
|
|
1981
|
-
config.warnings = false
|
|
1982
|
-
expect($VERBOSE).to eq false
|
|
1983
|
-
end
|
|
1984
|
-
|
|
1985
|
-
it 'returns the verbosity setting as a predicate' do
|
|
1986
|
-
expect(config.warnings?).to eq $VERBOSE
|
|
1987
|
-
end
|
|
1988
|
-
|
|
1989
|
-
it 'warns when using the deprecated `warnings` reader' do
|
|
1990
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /warnings/)
|
|
1991
|
-
expect(config.warnings).to eq $VERBOSE
|
|
1992
|
-
end
|
|
1993
|
-
|
|
1994
|
-
it 'is loaded from config by #force' do
|
|
1995
|
-
config.force :warnings => true
|
|
1996
|
-
expect($VERBOSE).to eq true
|
|
1997
|
-
end
|
|
1998
|
-
end
|
|
1999
|
-
|
|
2000
|
-
describe "#raise_errors_for_deprecations!" do
|
|
2001
|
-
it 'causes deprecations to raise errors rather than printing to the deprecation stream' do
|
|
2002
|
-
config.deprecation_stream = stream = StringIO.new
|
|
2003
|
-
config.raise_errors_for_deprecations!
|
|
2004
|
-
|
|
2005
|
-
expect {
|
|
2006
|
-
config.reporter.deprecation(:deprecated => "foo", :call_site => "foo.rb:1")
|
|
2007
|
-
}.to raise_error(RSpec::Core::DeprecationError, /foo is deprecated/)
|
|
2008
|
-
|
|
2009
|
-
expect(stream.string).to eq("")
|
|
2010
|
-
end
|
|
2011
|
-
end
|
|
2012
|
-
|
|
2013
|
-
describe "#expose_current_running_example_as" do
|
|
2014
|
-
before { stub_const(Configuration::ExposeCurrentExample.name, Module.new) }
|
|
2015
|
-
|
|
2016
|
-
it 'exposes the current example via the named method' do
|
|
2017
|
-
RSpec.configuration.expose_current_running_example_as :the_example
|
|
2018
|
-
RSpec.configuration.expose_current_running_example_as :another_example_helper
|
|
2019
|
-
|
|
2020
|
-
value_1 = value_2 = nil
|
|
2021
|
-
|
|
2022
|
-
ExampleGroup.describe "Group" do
|
|
2023
|
-
it "works" do
|
|
2024
|
-
value_1 = the_example
|
|
2025
|
-
value_2 = another_example_helper
|
|
2026
|
-
end
|
|
2027
|
-
end.run
|
|
2028
|
-
|
|
2029
|
-
expect(value_1).to be_an(RSpec::Core::Example)
|
|
2030
|
-
expect(value_1.description).to eq("works")
|
|
2031
|
-
expect(value_2).to be(value_1)
|
|
2032
|
-
end
|
|
2033
|
-
|
|
2034
|
-
[:example, :running_example].each do |name|
|
|
2035
|
-
it "silences the deprecation warning for ##{name} when configured to expose via that name" do
|
|
2036
|
-
RSpec.configuration.expose_current_running_example_as name
|
|
2037
|
-
allow(RSpec).to receive(:deprecate)
|
|
2038
|
-
|
|
2039
|
-
ExampleGroup.describe "Group" do
|
|
2040
|
-
specify { __send__(name) }
|
|
2041
|
-
end.run
|
|
2042
|
-
|
|
2043
|
-
expect(RSpec).to_not have_received(:deprecate)
|
|
2044
|
-
end
|
|
2045
|
-
end
|
|
2046
|
-
end
|
|
2047
|
-
|
|
2048
|
-
describe '#show_failures_in_pending_blocks' do
|
|
2049
|
-
specify 'reader is deprecated' do
|
|
2050
|
-
expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 3,
|
|
2051
|
-
/show_failures_in_pending_blocks/)
|
|
2052
|
-
|
|
2053
|
-
config.show_failures_in_pending_blocks
|
|
2054
|
-
end
|
|
2055
|
-
|
|
2056
|
-
specify 'predicate is deprecated' do
|
|
2057
|
-
expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 3,
|
|
2058
|
-
/show_failures_in_pending_blocks/)
|
|
2059
|
-
|
|
2060
|
-
config.show_failures_in_pending_blocks?
|
|
2061
|
-
end
|
|
2062
|
-
|
|
2063
|
-
specify 'writer is deprecated' do
|
|
2064
|
-
expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 3,
|
|
2065
|
-
/show_failures_in_pending_blocks/)
|
|
2066
|
-
|
|
2067
|
-
config.show_failures_in_pending_blocks = true
|
|
2068
|
-
end
|
|
2069
|
-
end
|
|
2070
|
-
|
|
2071
|
-
end
|
|
2072
|
-
end
|