rspec-core 2.11.1 → 3.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +3 -1
- data/Changelog.md +1814 -29
- data/{License.txt → LICENSE.md} +6 -4
- data/README.md +197 -48
- data/exe/rspec +2 -23
- data/lib/rspec/autorun.rb +1 -0
- data/lib/rspec/core/backtrace_formatter.rb +65 -0
- data/lib/rspec/core/bisect/coordinator.rb +62 -0
- data/lib/rspec/core/bisect/example_minimizer.rb +173 -0
- data/lib/rspec/core/bisect/fork_runner.rb +138 -0
- data/lib/rspec/core/bisect/server.rb +61 -0
- data/lib/rspec/core/bisect/shell_command.rb +126 -0
- data/lib/rspec/core/bisect/shell_runner.rb +73 -0
- data/lib/rspec/core/bisect/utilities.rb +69 -0
- data/lib/rspec/core/configuration.rb +1846 -407
- data/lib/rspec/core/configuration_options.rb +154 -50
- data/lib/rspec/core/did_you_mean.rb +46 -0
- data/lib/rspec/core/drb.rb +120 -0
- data/lib/rspec/core/dsl.rb +90 -18
- data/lib/rspec/core/example.rb +488 -152
- data/lib/rspec/core/example_group.rb +733 -294
- data/lib/rspec/core/example_status_persister.rb +235 -0
- data/lib/rspec/core/filter_manager.rb +175 -147
- data/lib/rspec/core/flat_map.rb +20 -0
- data/lib/rspec/core/formatters/base_bisect_formatter.rb +45 -0
- data/lib/rspec/core/formatters/base_formatter.rb +32 -130
- data/lib/rspec/core/formatters/base_text_formatter.rb +62 -190
- data/lib/rspec/core/formatters/bisect_drb_formatter.rb +29 -0
- data/lib/rspec/core/formatters/bisect_progress_formatter.rb +157 -0
- data/lib/rspec/core/formatters/console_codes.rb +76 -0
- data/lib/rspec/core/formatters/deprecation_formatter.rb +223 -0
- data/lib/rspec/core/formatters/documentation_formatter.rb +62 -27
- data/lib/rspec/core/formatters/exception_presenter.rb +521 -0
- data/lib/rspec/core/formatters/failure_list_formatter.rb +23 -0
- data/lib/rspec/core/formatters/fallback_message_formatter.rb +28 -0
- data/lib/rspec/core/formatters/helpers.rb +93 -14
- data/lib/rspec/core/formatters/html_formatter.rb +104 -415
- data/lib/rspec/core/formatters/html_printer.rb +414 -0
- data/lib/rspec/core/formatters/html_snippet_extractor.rb +120 -0
- data/lib/rspec/core/formatters/json_formatter.rb +102 -0
- data/lib/rspec/core/formatters/profile_formatter.rb +68 -0
- data/lib/rspec/core/formatters/progress_formatter.rb +12 -15
- data/lib/rspec/core/formatters/protocol.rb +182 -0
- data/lib/rspec/core/formatters/snippet_extractor.rb +115 -39
- data/lib/rspec/core/formatters/syntax_highlighter.rb +91 -0
- data/lib/rspec/core/formatters.rb +279 -0
- data/lib/rspec/core/hooks.rb +451 -300
- data/lib/rspec/core/invocations.rb +87 -0
- data/lib/rspec/core/memoized_helpers.rb +580 -0
- data/lib/rspec/core/metadata.rb +395 -173
- data/lib/rspec/core/metadata_filter.rb +255 -0
- data/lib/rspec/core/minitest_assertions_adapter.rb +31 -0
- data/lib/rspec/core/mocking_adapters/flexmock.rb +31 -0
- data/lib/rspec/core/mocking_adapters/mocha.rb +57 -0
- data/lib/rspec/core/mocking_adapters/null.rb +14 -0
- data/lib/rspec/core/mocking_adapters/rr.rb +31 -0
- data/lib/rspec/core/mocking_adapters/rspec.rb +32 -0
- data/lib/rspec/core/notifications.rb +521 -0
- data/lib/rspec/core/option_parser.rb +208 -64
- data/lib/rspec/core/ordering.rb +169 -0
- data/lib/rspec/core/output_wrapper.rb +29 -0
- data/lib/rspec/core/pending.rb +115 -59
- data/lib/rspec/core/profiler.rb +34 -0
- data/lib/rspec/core/project_initializer/.rspec +1 -0
- data/lib/rspec/core/project_initializer/spec/spec_helper.rb +98 -0
- data/lib/rspec/core/project_initializer.rb +26 -65
- data/lib/rspec/core/rake_task.rb +140 -131
- data/lib/rspec/core/reporter.rb +207 -44
- data/lib/rspec/core/ruby_project.rb +15 -6
- data/lib/rspec/core/runner.rb +180 -44
- data/lib/rspec/core/sandbox.rb +37 -0
- data/lib/rspec/core/set.rb +54 -0
- data/lib/rspec/core/shared_context.rb +25 -19
- data/lib/rspec/core/shared_example_group.rb +229 -54
- data/lib/rspec/core/shell_escape.rb +49 -0
- data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
- data/lib/rspec/core/version.rb +3 -1
- data/lib/rspec/core/warnings.rb +40 -0
- data/lib/rspec/core/world.rb +208 -49
- data/lib/rspec/core.rb +166 -80
- data.tar.gz.sig +0 -0
- metadata +230 -445
- metadata.gz.sig +0 -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 -101
- data/features/command_line/exit_status.feature +0 -83
- data/features/command_line/format_option.feature +0 -81
- 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 -58
- data/features/command_line/order.feature +0 -29
- data/features/command_line/pattern_option.feature +0 -31
- data/features/command_line/rake_task.feature +0 -68
- data/features/command_line/ruby.feature +0 -22
- data/features/command_line/tag.feature +0 -91
- data/features/configuration/alias_example_to.feature +0 -48
- data/features/configuration/custom_settings.feature +0 -84
- data/features/configuration/default_path.feature +0 -38
- data/features/configuration/fail_fast.feature +0 -77
- data/features/configuration/read_options_from_file.feature +0 -87
- 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 -204
- data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
- data/features/filtering/exclusion_filters.feature +0 -139
- data/features/filtering/if_and_unless.feature +0 -168
- data/features/filtering/inclusion_filters.feature +0 -105
- data/features/filtering/run_all_when_everything_filtered.feature +0 -46
- data/features/formatters/custom_formatter.feature +0 -36
- 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 -423
- data/features/hooks/filtering.feature +0 -234
- data/features/metadata/current_example.feature +0 -17
- 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 -30
- data/features/subject/attribute_of_subject.feature +0 -124
- data/features/subject/explicit_subject.feature +0 -82
- data/features/subject/implicit_receiver.feature +0 -29
- data/features/subject/implicit_subject.feature +0 -63
- data/features/support/env.rb +0 -12
- data/lib/autotest/discover.rb +0 -1
- data/lib/autotest/rspec2.rb +0 -73
- data/lib/rspec/core/backward_compatibility.rb +0 -65
- data/lib/rspec/core/command_line.rb +0 -36
- data/lib/rspec/core/deprecation.rb +0 -36
- 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 -21
- data/lib/rspec/core/extensions.rb +0 -4
- data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
- data/lib/rspec/core/let.rb +0 -110
- data/lib/rspec/core/load_path.rb +0 -3
- 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_mocha.rb +0 -29
- data/lib/rspec/core/mocking/with_rr.rb +0 -27
- data/lib/rspec/core/mocking/with_rspec.rb +0 -23
- data/lib/rspec/core/subject.rb +0 -219
- data/spec/autotest/discover_spec.rb +0 -19
- data/spec/autotest/failed_results_re_spec.rb +0 -45
- data/spec/autotest/rspec_spec.rb +0 -123
- data/spec/command_line/order_spec.rb +0 -137
- data/spec/rspec/core/command_line_spec.rb +0 -108
- data/spec/rspec/core/command_line_spec_output.txt +0 -0
- data/spec/rspec/core/configuration_options_spec.rb +0 -377
- data/spec/rspec/core/configuration_spec.rb +0 -1196
- data/spec/rspec/core/deprecations_spec.rb +0 -66
- data/spec/rspec/core/drb_command_line_spec.rb +0 -108
- data/spec/rspec/core/drb_options_spec.rb +0 -180
- data/spec/rspec/core/dsl_spec.rb +0 -17
- data/spec/rspec/core/example_group_spec.rb +0 -1098
- data/spec/rspec/core/example_spec.rb +0 -370
- data/spec/rspec/core/filter_manager_spec.rb +0 -256
- data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -80
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -363
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -88
- data/spec/rspec/core/formatters/helpers_spec.rb +0 -66
- data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +0 -410
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +0 -409
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +0 -416
- data/spec/rspec/core/formatters/html_formatted-1.9.3.html +0 -416
- data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -82
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
- data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -18
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +0 -410
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +0 -409
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +0 -416
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +0 -416
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -83
- data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
- data/spec/rspec/core/hooks_spec.rb +0 -250
- data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
- data/spec/rspec/core/let_spec.rb +0 -55
- data/spec/rspec/core/metadata_spec.rb +0 -447
- data/spec/rspec/core/option_parser_spec.rb +0 -166
- data/spec/rspec/core/pending_example_spec.rb +0 -220
- data/spec/rspec/core/project_initializer_spec.rb +0 -130
- data/spec/rspec/core/rake_task_spec.rb +0 -138
- data/spec/rspec/core/reporter_spec.rb +0 -103
- 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 -24
- data/spec/rspec/core/runner_spec.rb +0 -81
- data/spec/rspec/core/shared_context_spec.rb +0 -67
- data/spec/rspec/core/shared_example_group_spec.rb +0 -84
- data/spec/rspec/core/subject_spec.rb +0 -244
- data/spec/rspec/core/world_spec.rb +0 -144
- data/spec/rspec/core_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -98
- data/spec/support/config_options_helper.rb +0 -24
- data/spec/support/helper_methods.rb +0 -5
- data/spec/support/matchers.rb +0 -65
- data/spec/support/shared_example_groups.rb +0 -41
- data/spec/support/spec_files.rb +0 -44
@@ -1,1196 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'tmpdir'
|
3
|
-
|
4
|
-
# so the stdlib module is available...
|
5
|
-
module Test; module Unit; module Assertions; end; end; end
|
6
|
-
|
7
|
-
module RSpec::Core
|
8
|
-
|
9
|
-
describe Configuration do
|
10
|
-
|
11
|
-
let(:config) { Configuration.new }
|
12
|
-
|
13
|
-
describe "#load_spec_files" do
|
14
|
-
|
15
|
-
it "loads files using load" do
|
16
|
-
config.files_to_run = ["foo.bar", "blah_spec.rb"]
|
17
|
-
config.should_receive(:load).twice
|
18
|
-
config.load_spec_files
|
19
|
-
end
|
20
|
-
|
21
|
-
it "loads each file once, even if duplicated in list" do
|
22
|
-
config.files_to_run = ["a_spec.rb", "a_spec.rb"]
|
23
|
-
config.should_receive(:load).once
|
24
|
-
config.load_spec_files
|
25
|
-
end
|
26
|
-
|
27
|
-
context "with rspec-1 loaded" do
|
28
|
-
before do
|
29
|
-
Object.const_set(:Spec, Module.new)
|
30
|
-
::Spec::const_set(:VERSION, Module.new)
|
31
|
-
::Spec::VERSION::const_set(:MAJOR, 1)
|
32
|
-
end
|
33
|
-
after { Object.__send__(:remove_const, :Spec) }
|
34
|
-
it "raises with a helpful message" do
|
35
|
-
expect {
|
36
|
-
config.load_spec_files
|
37
|
-
}.to raise_error(/rspec-1 has been loaded/)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "#treat_symbols_as_metadata_keys_with_true_values?" do
|
43
|
-
it 'defaults to false' do
|
44
|
-
config.treat_symbols_as_metadata_keys_with_true_values?.should be_false
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'can be set to true' do
|
48
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
49
|
-
config.treat_symbols_as_metadata_keys_with_true_values?.should be_true
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#mock_framework" do
|
54
|
-
it "defaults to :rspec" do
|
55
|
-
config.should_receive(:require).with('rspec/core/mocking/with_rspec')
|
56
|
-
config.mock_framework
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "#mock_framework="do
|
61
|
-
it "delegates to mock_with" do
|
62
|
-
config.should_receive(:mock_with).with(:rspec)
|
63
|
-
config.mock_framework = :rspec
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
shared_examples "a configurable framework adapter" do |m|
|
68
|
-
it "yields a config object if the framework_module supports it" do
|
69
|
-
custom_config = Struct.new(:custom_setting).new
|
70
|
-
mod = Module.new
|
71
|
-
mod.stub(:configuration => custom_config)
|
72
|
-
|
73
|
-
config.send m, mod do |mod_config|
|
74
|
-
mod_config.custom_setting = true
|
75
|
-
end
|
76
|
-
|
77
|
-
custom_config.custom_setting.should be_true
|
78
|
-
end
|
79
|
-
|
80
|
-
it "raises if framework module doesn't support configuration" do
|
81
|
-
mod = Module.new
|
82
|
-
|
83
|
-
lambda do
|
84
|
-
config.send m, mod do |mod_config|
|
85
|
-
end
|
86
|
-
end.should raise_error(/must respond to `configuration`/)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "#mock_with" do
|
91
|
-
before { config.stub(:require) }
|
92
|
-
|
93
|
-
it_behaves_like "a configurable framework adapter", :mock_with
|
94
|
-
|
95
|
-
[:rspec, :mocha, :rr, :flexmock].each do |framework|
|
96
|
-
context "with #{framework}" do
|
97
|
-
it "requires the adapter for #{framework}" do
|
98
|
-
config.should_receive(:require).with("rspec/core/mocking/with_#{framework}")
|
99
|
-
config.mock_with framework
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "with a module" do
|
105
|
-
it "sets the mock_framework_adapter to that module" do
|
106
|
-
mod = Module.new
|
107
|
-
config.mock_with mod
|
108
|
-
config.mock_framework.should eq(mod)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
it "uses the null adapter when set to any unknown key" do
|
113
|
-
config.should_receive(:require).with('rspec/core/mocking/with_absolutely_nothing')
|
114
|
-
config.mock_with :crazy_new_mocking_framework_ive_not_yet_heard_of
|
115
|
-
end
|
116
|
-
|
117
|
-
context 'when there are already some example groups defined' do
|
118
|
-
it 'raises an error since this setting must be applied before any groups are defined' do
|
119
|
-
RSpec.world.stub(:example_groups).and_return([double.as_null_object])
|
120
|
-
expect {
|
121
|
-
config.mock_with :mocha
|
122
|
-
}.to raise_error(/must be configured before any example groups are defined/)
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'does not raise an error if the default `mock_with :rspec` is re-configured' do
|
126
|
-
config.mock_framework # called by RSpec when configuring the first example group
|
127
|
-
RSpec.world.stub(:example_groups).and_return([double.as_null_object])
|
128
|
-
config.mock_with :rspec
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'does not raise an error if re-setting the same config' do
|
132
|
-
groups = []
|
133
|
-
RSpec.world.stub(:example_groups => groups)
|
134
|
-
config.mock_with :mocha
|
135
|
-
groups << double.as_null_object
|
136
|
-
config.mock_with :mocha
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe "#expectation_framework" do
|
142
|
-
it "defaults to :rspec" do
|
143
|
-
config.should_receive(:require).with('rspec/expectations')
|
144
|
-
config.expectation_frameworks
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
describe "#expectation_framework=" do
|
149
|
-
it "delegates to expect_with=" do
|
150
|
-
config.should_receive(:expect_with).with(:rspec)
|
151
|
-
config.expectation_framework = :rspec
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
describe "#expect_with" do
|
156
|
-
before { config.stub(:require) }
|
157
|
-
|
158
|
-
it_behaves_like "a configurable framework adapter", :expect_with
|
159
|
-
|
160
|
-
[
|
161
|
-
[:rspec, 'rspec/expectations'],
|
162
|
-
[:stdlib, 'test/unit/assertions']
|
163
|
-
].each do |framework, required_file|
|
164
|
-
context "with #{framework}" do
|
165
|
-
it "requires #{required_file}" do
|
166
|
-
config.should_receive(:require).with(required_file)
|
167
|
-
config.expect_with framework
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
it "supports multiple calls" do
|
173
|
-
config.expect_with :rspec
|
174
|
-
config.expect_with :stdlib
|
175
|
-
config.expectation_frameworks.should eq [RSpec::Matchers, Test::Unit::Assertions]
|
176
|
-
end
|
177
|
-
|
178
|
-
it "raises if block given with multiple args" do
|
179
|
-
lambda do
|
180
|
-
config.expect_with :rspec, :stdlib do |mod_config|
|
181
|
-
end
|
182
|
-
end.should raise_error(/expect_with only accepts/)
|
183
|
-
end
|
184
|
-
|
185
|
-
it "raises ArgumentError if framework is not supported" do
|
186
|
-
expect do
|
187
|
-
config.expect_with :not_supported
|
188
|
-
end.to raise_error(ArgumentError)
|
189
|
-
end
|
190
|
-
|
191
|
-
context 'when there are already some example groups defined' do
|
192
|
-
it 'raises an error since this setting must be applied before any groups are defined' do
|
193
|
-
RSpec.world.stub(:example_groups).and_return([double.as_null_object])
|
194
|
-
expect {
|
195
|
-
config.expect_with :rspec
|
196
|
-
}.to raise_error(/must be configured before any example groups are defined/)
|
197
|
-
end
|
198
|
-
|
199
|
-
it 'does not raise an error if the default `expect_with :rspec` is re-configured' do
|
200
|
-
config.expectation_frameworks # called by RSpec when configuring the first example group
|
201
|
-
RSpec.world.stub(:example_groups).and_return([double.as_null_object])
|
202
|
-
config.expect_with :rspec
|
203
|
-
end
|
204
|
-
|
205
|
-
it 'does not raise an error if re-setting the same config' do
|
206
|
-
groups = []
|
207
|
-
RSpec.world.stub(:example_groups => groups)
|
208
|
-
config.expect_with :stdlib
|
209
|
-
groups << double.as_null_object
|
210
|
-
config.expect_with :stdlib
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
describe "#expecting_with_rspec?" do
|
216
|
-
before { config.stub(:require) }
|
217
|
-
|
218
|
-
it "returns false by default" do
|
219
|
-
config.should_not be_expecting_with_rspec
|
220
|
-
end
|
221
|
-
|
222
|
-
it "returns true when `expect_with :rspec` has been configured" do
|
223
|
-
config.expect_with :rspec
|
224
|
-
config.should be_expecting_with_rspec
|
225
|
-
end
|
226
|
-
|
227
|
-
it "returns true when `expect_with :rspec, :stdlib` has been configured" do
|
228
|
-
config.expect_with :rspec, :stdlib
|
229
|
-
config.should be_expecting_with_rspec
|
230
|
-
end
|
231
|
-
|
232
|
-
it "returns true when `expect_with :stdlib, :rspec` has been configured" do
|
233
|
-
config.expect_with :stdlib, :rspec
|
234
|
-
config.should be_expecting_with_rspec
|
235
|
-
end
|
236
|
-
|
237
|
-
it "returns false when `expect_with :stdlib` has been configured" do
|
238
|
-
config.expect_with :stdlib
|
239
|
-
config.should_not be_expecting_with_rspec
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
describe "#files_to_run" do
|
244
|
-
it "loads files not following pattern if named explicitly" do
|
245
|
-
config.files_or_directories_to_run = "spec/rspec/core/resources/a_bar.rb"
|
246
|
-
config.files_to_run.should eq([ "spec/rspec/core/resources/a_bar.rb"])
|
247
|
-
end
|
248
|
-
|
249
|
-
it "prevents repetition of dir when start of the pattern" do
|
250
|
-
config.pattern = "spec/**/a_spec.rb"
|
251
|
-
config.files_or_directories_to_run = "spec"
|
252
|
-
config.files_to_run.should eq(["spec/rspec/core/resources/a_spec.rb"])
|
253
|
-
end
|
254
|
-
|
255
|
-
it "does not prevent repetition of dir when later of the pattern" do
|
256
|
-
config.pattern = "rspec/**/a_spec.rb"
|
257
|
-
config.files_or_directories_to_run = "spec"
|
258
|
-
config.files_to_run.should eq(["spec/rspec/core/resources/a_spec.rb"])
|
259
|
-
end
|
260
|
-
|
261
|
-
context "with <path>:<line_number>" do
|
262
|
-
it "overrides inclusion filters set on config" do
|
263
|
-
config.filter_run_including :foo => :bar
|
264
|
-
config.files_or_directories_to_run = "path/to/file.rb:37"
|
265
|
-
config.inclusion_filter.size.should eq(1)
|
266
|
-
config.inclusion_filter[:locations].keys.first.should match(/path\/to\/file\.rb$/)
|
267
|
-
config.inclusion_filter[:locations].values.first.should eq([37])
|
268
|
-
end
|
269
|
-
|
270
|
-
it "overrides inclusion filters set before config" do
|
271
|
-
config.force(:inclusion_filter => {:foo => :bar})
|
272
|
-
config.files_or_directories_to_run = "path/to/file.rb:37"
|
273
|
-
config.inclusion_filter.size.should eq(1)
|
274
|
-
config.inclusion_filter[:locations].keys.first.should match(/path\/to\/file\.rb$/)
|
275
|
-
config.inclusion_filter[:locations].values.first.should eq([37])
|
276
|
-
end
|
277
|
-
|
278
|
-
it "clears exclusion filters set on config" do
|
279
|
-
config.exclusion_filter = { :foo => :bar }
|
280
|
-
config.files_or_directories_to_run = "path/to/file.rb:37"
|
281
|
-
config.exclusion_filter.should be_empty,
|
282
|
-
"expected exclusion filter to be empty:\n#{config.exclusion_filter}"
|
283
|
-
end
|
284
|
-
|
285
|
-
it "clears exclusion filters set before config" do
|
286
|
-
config.force(:exclusion_filter => { :foo => :bar })
|
287
|
-
config.files_or_directories_to_run = "path/to/file.rb:37"
|
288
|
-
config.exclusion_filter.should be_empty,
|
289
|
-
"expected exclusion filter to be empty:\n#{config.exclusion_filter}"
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
context "with default pattern" do
|
294
|
-
it "loads files named _spec.rb" do
|
295
|
-
config.files_or_directories_to_run = "spec/rspec/core/resources"
|
296
|
-
config.files_to_run.should eq([ "spec/rspec/core/resources/a_spec.rb"])
|
297
|
-
end
|
298
|
-
|
299
|
-
it "loads files in Windows", :if => RSpec.windows_os? do
|
300
|
-
config.files_or_directories_to_run = "C:\\path\\to\\project\\spec\\sub\\foo_spec.rb"
|
301
|
-
config.files_to_run.should eq([ "C:/path/to/project/spec/sub/foo_spec.rb"])
|
302
|
-
end
|
303
|
-
|
304
|
-
it "loads files in Windows when directory is specified", :if => RSpec.windows_os? do
|
305
|
-
config.files_or_directories_to_run = "spec\\rspec\\core\\resources"
|
306
|
-
config.files_to_run.should eq([ "spec/rspec/core/resources/a_spec.rb"])
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
context "with default default_path" do
|
311
|
-
it "loads files in the default path when run by rspec" do
|
312
|
-
config.stub(:command) { 'rspec' }
|
313
|
-
config.files_or_directories_to_run = []
|
314
|
-
config.files_to_run.should_not be_empty
|
315
|
-
end
|
316
|
-
|
317
|
-
it "does not load files in the default path when run by ruby" do
|
318
|
-
config.stub(:command) { 'ruby' }
|
319
|
-
config.files_or_directories_to_run = []
|
320
|
-
config.files_to_run.should be_empty
|
321
|
-
end
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
%w[pattern= filename_pattern=].each do |setter|
|
326
|
-
describe "##{setter}" do
|
327
|
-
context "with single pattern" do
|
328
|
-
before { config.send(setter, "**/*_foo.rb") }
|
329
|
-
it "loads files following pattern" do
|
330
|
-
file = File.expand_path(File.dirname(__FILE__) + "/resources/a_foo.rb")
|
331
|
-
config.files_or_directories_to_run = file
|
332
|
-
config.files_to_run.should include(file)
|
333
|
-
end
|
334
|
-
|
335
|
-
it "loads files in directories following pattern" do
|
336
|
-
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
337
|
-
config.files_or_directories_to_run = dir
|
338
|
-
config.files_to_run.should include("#{dir}/a_foo.rb")
|
339
|
-
end
|
340
|
-
|
341
|
-
it "does not load files in directories not following pattern" do
|
342
|
-
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
343
|
-
config.files_or_directories_to_run = dir
|
344
|
-
config.files_to_run.should_not include("#{dir}/a_bar.rb")
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
context "with multiple patterns" do
|
349
|
-
it "supports comma separated values" do
|
350
|
-
config.send(setter, "**/*_foo.rb,**/*_bar.rb")
|
351
|
-
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
352
|
-
config.files_or_directories_to_run = dir
|
353
|
-
config.files_to_run.should include("#{dir}/a_foo.rb")
|
354
|
-
config.files_to_run.should include("#{dir}/a_bar.rb")
|
355
|
-
end
|
356
|
-
|
357
|
-
it "supports comma separated values with spaces" do
|
358
|
-
config.send(setter, "**/*_foo.rb, **/*_bar.rb")
|
359
|
-
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
|
360
|
-
config.files_or_directories_to_run = dir
|
361
|
-
config.files_to_run.should include("#{dir}/a_foo.rb")
|
362
|
-
config.files_to_run.should include("#{dir}/a_bar.rb")
|
363
|
-
end
|
364
|
-
end
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
describe "path with line number" do
|
369
|
-
it "assigns the line number as a location filter" do
|
370
|
-
config.files_or_directories_to_run = "path/to/a_spec.rb:37"
|
371
|
-
config.filter.should eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37]}})
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
context "with full_description" do
|
376
|
-
it "overrides filters" do
|
377
|
-
config.filter_run :focused => true
|
378
|
-
config.full_description = "foo"
|
379
|
-
config.filter.should_not have_key(:focused)
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
context "with line number" do
|
384
|
-
|
385
|
-
it "assigns the file and line number as a location filter" do
|
386
|
-
config.files_or_directories_to_run = "path/to/a_spec.rb:37"
|
387
|
-
config.filter.should eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37]}})
|
388
|
-
end
|
389
|
-
|
390
|
-
it "assigns multiple files with line numbers as location filters" do
|
391
|
-
config.files_or_directories_to_run = "path/to/a_spec.rb:37", "other_spec.rb:44"
|
392
|
-
config.filter.should eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37],
|
393
|
-
File.expand_path("other_spec.rb") => [44]}})
|
394
|
-
end
|
395
|
-
|
396
|
-
it "assigns files with multiple line numbers as location filters" do
|
397
|
-
config.files_or_directories_to_run = "path/to/a_spec.rb:37", "path/to/a_spec.rb:44"
|
398
|
-
config.filter.should eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37, 44]}})
|
399
|
-
end
|
400
|
-
end
|
401
|
-
|
402
|
-
context "with multiple line numbers" do
|
403
|
-
it "assigns the file and line numbers as a location filter" do
|
404
|
-
config.files_or_directories_to_run = "path/to/a_spec.rb:1:3:5:7"
|
405
|
-
config.filter.should eq({:locations => {File.expand_path("path/to/a_spec.rb") => [1,3,5,7]}})
|
406
|
-
end
|
407
|
-
end
|
408
|
-
|
409
|
-
it "assigns the example name as the filter on description" do
|
410
|
-
config.full_description = "foo"
|
411
|
-
config.filter.should eq({:full_description => /foo/})
|
412
|
-
end
|
413
|
-
|
414
|
-
it "assigns the example names as the filter on description if description is an array" do
|
415
|
-
config.full_description = [ "foo", "bar" ]
|
416
|
-
config.filter.should eq({:full_description => Regexp.union(/foo/, /bar/)})
|
417
|
-
end
|
418
|
-
|
419
|
-
describe "#default_path" do
|
420
|
-
it 'defaults to "spec"' do
|
421
|
-
config.default_path.should eq('spec')
|
422
|
-
end
|
423
|
-
end
|
424
|
-
|
425
|
-
describe "#include" do
|
426
|
-
|
427
|
-
module InstanceLevelMethods
|
428
|
-
def you_call_this_a_blt?
|
429
|
-
"egad man, where's the mayo?!?!?"
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
it_behaves_like "metadata hash builder" do
|
434
|
-
def metadata_hash(*args)
|
435
|
-
config.include(InstanceLevelMethods, *args)
|
436
|
-
config.include_or_extend_modules.last.last
|
437
|
-
end
|
438
|
-
end
|
439
|
-
|
440
|
-
context "with no filter" do
|
441
|
-
it "includes the given module into each example group" do
|
442
|
-
RSpec.configure do |c|
|
443
|
-
c.include(InstanceLevelMethods)
|
444
|
-
end
|
445
|
-
|
446
|
-
group = ExampleGroup.describe('does like, stuff and junk', :magic_key => :include) { }
|
447
|
-
group.should_not respond_to(:you_call_this_a_blt?)
|
448
|
-
group.new.you_call_this_a_blt?.should eq("egad man, where's the mayo?!?!?")
|
449
|
-
end
|
450
|
-
end
|
451
|
-
|
452
|
-
context "with a filter" do
|
453
|
-
it "includes the given module into each matching example group" do
|
454
|
-
RSpec.configure do |c|
|
455
|
-
c.include(InstanceLevelMethods, :magic_key => :include)
|
456
|
-
end
|
457
|
-
|
458
|
-
group = ExampleGroup.describe('does like, stuff and junk', :magic_key => :include) { }
|
459
|
-
group.should_not respond_to(:you_call_this_a_blt?)
|
460
|
-
group.new.you_call_this_a_blt?.should eq("egad man, where's the mayo?!?!?")
|
461
|
-
end
|
462
|
-
end
|
463
|
-
|
464
|
-
end
|
465
|
-
|
466
|
-
describe "#extend" do
|
467
|
-
|
468
|
-
module ThatThingISentYou
|
469
|
-
def that_thing
|
470
|
-
end
|
471
|
-
end
|
472
|
-
|
473
|
-
it_behaves_like "metadata hash builder" do
|
474
|
-
def metadata_hash(*args)
|
475
|
-
config.extend(ThatThingISentYou, *args)
|
476
|
-
config.include_or_extend_modules.last.last
|
477
|
-
end
|
478
|
-
end
|
479
|
-
|
480
|
-
it "extends the given module into each matching example group" do
|
481
|
-
RSpec.configure do |c|
|
482
|
-
c.extend(ThatThingISentYou, :magic_key => :extend)
|
483
|
-
end
|
484
|
-
|
485
|
-
group = ExampleGroup.describe(ThatThingISentYou, :magic_key => :extend) { }
|
486
|
-
group.should respond_to(:that_thing)
|
487
|
-
end
|
488
|
-
|
489
|
-
end
|
490
|
-
|
491
|
-
describe "#run_all_when_everything_filtered?" do
|
492
|
-
|
493
|
-
it "defaults to false" do
|
494
|
-
config.run_all_when_everything_filtered?.should be_false
|
495
|
-
end
|
496
|
-
|
497
|
-
it "can be queried with question method" do
|
498
|
-
config.run_all_when_everything_filtered = true
|
499
|
-
config.run_all_when_everything_filtered?.should be_true
|
500
|
-
end
|
501
|
-
end
|
502
|
-
|
503
|
-
%w[color color_enabled].each do |color_option|
|
504
|
-
describe "##{color_option}=" do
|
505
|
-
context "given true" do
|
506
|
-
context "with non-tty output and no autotest" do
|
507
|
-
it "does not set color_enabled" do
|
508
|
-
config.output_stream = StringIO.new
|
509
|
-
config.output_stream.stub(:tty?) { false }
|
510
|
-
config.tty = false
|
511
|
-
config.send "#{color_option}=", true
|
512
|
-
config.send(color_option).should be_false
|
513
|
-
end
|
514
|
-
end
|
515
|
-
|
516
|
-
context "with tty output" do
|
517
|
-
it "does not set color_enabled" do
|
518
|
-
config.output_stream = StringIO.new
|
519
|
-
config.output_stream.stub(:tty?) { true }
|
520
|
-
config.tty = false
|
521
|
-
config.send "#{color_option}=", true
|
522
|
-
config.send(color_option).should be_true
|
523
|
-
end
|
524
|
-
end
|
525
|
-
|
526
|
-
context "with tty set" do
|
527
|
-
it "does not set color_enabled" do
|
528
|
-
config.output_stream = StringIO.new
|
529
|
-
config.output_stream.stub(:tty?) { false }
|
530
|
-
config.tty = true
|
531
|
-
config.send "#{color_option}=", true
|
532
|
-
config.send(color_option).should be_true
|
533
|
-
end
|
534
|
-
end
|
535
|
-
|
536
|
-
context "on windows" do
|
537
|
-
before do
|
538
|
-
@original_host = RbConfig::CONFIG['host_os']
|
539
|
-
RbConfig::CONFIG['host_os'] = 'mingw'
|
540
|
-
config.stub(:require)
|
541
|
-
config.stub(:warn)
|
542
|
-
end
|
543
|
-
|
544
|
-
after do
|
545
|
-
RbConfig::CONFIG['host_os'] = @original_host
|
546
|
-
end
|
547
|
-
|
548
|
-
context "with ANSICON available" do
|
549
|
-
before(:all) do
|
550
|
-
@original_ansicon = ENV['ANSICON']
|
551
|
-
ENV['ANSICON'] = 'ANSICON'
|
552
|
-
end
|
553
|
-
|
554
|
-
after(:all) do
|
555
|
-
ENV['ANSICON'] = @original_ansicon
|
556
|
-
end
|
557
|
-
|
558
|
-
it "enables colors" do
|
559
|
-
config.output_stream = StringIO.new
|
560
|
-
config.output_stream.stub(:tty?) { true }
|
561
|
-
config.send "#{color_option}=", true
|
562
|
-
config.send(color_option).should be_true
|
563
|
-
end
|
564
|
-
|
565
|
-
it "leaves output stream intact" do
|
566
|
-
config.output_stream = $stdout
|
567
|
-
config.stub(:require) do |what|
|
568
|
-
config.output_stream = 'foo' if what =~ /Win32/
|
569
|
-
end
|
570
|
-
config.send "#{color_option}=", true
|
571
|
-
config.output_stream.should eq($stdout)
|
572
|
-
end
|
573
|
-
end
|
574
|
-
|
575
|
-
context "with ANSICON NOT available" do
|
576
|
-
it "warns to install ANSICON" do
|
577
|
-
config.stub(:require) { raise LoadError }
|
578
|
-
config.should_receive(:warn).
|
579
|
-
with(/You must use ANSICON/)
|
580
|
-
config.send "#{color_option}=", true
|
581
|
-
end
|
582
|
-
|
583
|
-
it "sets color_enabled to false" do
|
584
|
-
config.stub(:require) { raise LoadError }
|
585
|
-
config.send "#{color_option}=", true
|
586
|
-
config.color_enabled = true
|
587
|
-
config.send(color_option).should be_false
|
588
|
-
end
|
589
|
-
end
|
590
|
-
end
|
591
|
-
end
|
592
|
-
end
|
593
|
-
|
594
|
-
it "prefers incoming cli_args" do
|
595
|
-
config.output_stream = StringIO.new
|
596
|
-
config.output_stream.stub :tty? => true
|
597
|
-
config.force :color => true
|
598
|
-
config.color = false
|
599
|
-
config.color.should be_true
|
600
|
-
end
|
601
|
-
end
|
602
|
-
|
603
|
-
describe '#formatter=' do
|
604
|
-
it "delegates to add_formatter (better API for user-facing configuration)" do
|
605
|
-
config.should_receive(:add_formatter).with('these','options')
|
606
|
-
config.add_formatter('these','options')
|
607
|
-
end
|
608
|
-
end
|
609
|
-
|
610
|
-
describe "#add_formatter" do
|
611
|
-
|
612
|
-
it "adds to the list of formatters" do
|
613
|
-
config.add_formatter :documentation
|
614
|
-
config.formatters.first.should be_an_instance_of(Formatters::DocumentationFormatter)
|
615
|
-
end
|
616
|
-
|
617
|
-
it "finds a formatter by name (w/ Symbol)" do
|
618
|
-
config.add_formatter :documentation
|
619
|
-
config.formatters.first.should be_an_instance_of(Formatters::DocumentationFormatter)
|
620
|
-
end
|
621
|
-
|
622
|
-
it "finds a formatter by name (w/ String)" do
|
623
|
-
config.add_formatter 'documentation'
|
624
|
-
config.formatters.first.should be_an_instance_of(Formatters::DocumentationFormatter)
|
625
|
-
end
|
626
|
-
|
627
|
-
it "finds a formatter by class" do
|
628
|
-
formatter_class = Class.new(Formatters::BaseTextFormatter)
|
629
|
-
config.add_formatter formatter_class
|
630
|
-
config.formatters.first.should be_an_instance_of(formatter_class)
|
631
|
-
end
|
632
|
-
|
633
|
-
it "finds a formatter by class name" do
|
634
|
-
Object.const_set("ACustomFormatter", Class.new(Formatters::BaseFormatter))
|
635
|
-
config.add_formatter "ACustomFormatter"
|
636
|
-
config.formatters.first.should be_an_instance_of(ACustomFormatter)
|
637
|
-
end
|
638
|
-
|
639
|
-
it "finds a formatter by class fully qualified name" do
|
640
|
-
RSpec.const_set("CustomFormatter", Class.new(Formatters::BaseFormatter))
|
641
|
-
config.add_formatter "RSpec::CustomFormatter"
|
642
|
-
config.formatters.first.should be_an_instance_of(RSpec::CustomFormatter)
|
643
|
-
end
|
644
|
-
|
645
|
-
it "requires a formatter file based on its fully qualified name" do
|
646
|
-
config.should_receive(:require).with('rspec/custom_formatter2') do
|
647
|
-
RSpec.const_set("CustomFormatter2", Class.new(Formatters::BaseFormatter))
|
648
|
-
end
|
649
|
-
config.add_formatter "RSpec::CustomFormatter2"
|
650
|
-
config.formatters.first.should be_an_instance_of(RSpec::CustomFormatter2)
|
651
|
-
end
|
652
|
-
|
653
|
-
it "raises NameError if class is unresolvable" do
|
654
|
-
config.should_receive(:require).with('rspec/custom_formatter3')
|
655
|
-
lambda { config.add_formatter "RSpec::CustomFormatter3" }.should raise_error(NameError)
|
656
|
-
end
|
657
|
-
|
658
|
-
it "raises ArgumentError if formatter is unknown" do
|
659
|
-
lambda { config.add_formatter :progresss }.should raise_error(ArgumentError)
|
660
|
-
end
|
661
|
-
|
662
|
-
context "with a 2nd arg defining the output" do
|
663
|
-
it "creates a file at that path and sets it as the output" do
|
664
|
-
path = File.join(Dir.tmpdir, 'output.txt')
|
665
|
-
config.add_formatter('doc', path)
|
666
|
-
config.formatters.first.output.should be_a(File)
|
667
|
-
config.formatters.first.output.path.should eq(path)
|
668
|
-
end
|
669
|
-
end
|
670
|
-
end
|
671
|
-
|
672
|
-
describe "#filter_run_including" do
|
673
|
-
it_behaves_like "metadata hash builder" do
|
674
|
-
def metadata_hash(*args)
|
675
|
-
config.filter_run_including(*args)
|
676
|
-
config.inclusion_filter
|
677
|
-
end
|
678
|
-
end
|
679
|
-
|
680
|
-
it "sets the filter with a hash" do
|
681
|
-
config.filter_run_including :foo => true
|
682
|
-
config.inclusion_filter[:foo].should be(true)
|
683
|
-
end
|
684
|
-
|
685
|
-
it "sets the filter with a symbol" do
|
686
|
-
RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
|
687
|
-
config.filter_run_including :foo
|
688
|
-
config.inclusion_filter[:foo].should be(true)
|
689
|
-
end
|
690
|
-
|
691
|
-
it "merges with existing filters" do
|
692
|
-
config.filter_run_including :foo => true
|
693
|
-
config.filter_run_including :bar => false
|
694
|
-
|
695
|
-
config.inclusion_filter[:foo].should be(true)
|
696
|
-
config.inclusion_filter[:bar].should be(false)
|
697
|
-
end
|
698
|
-
end
|
699
|
-
|
700
|
-
describe "#filter_run_excluding" do
|
701
|
-
it_behaves_like "metadata hash builder" do
|
702
|
-
def metadata_hash(*args)
|
703
|
-
config.filter_run_excluding(*args)
|
704
|
-
config.exclusion_filter
|
705
|
-
end
|
706
|
-
end
|
707
|
-
|
708
|
-
it "sets the filter" do
|
709
|
-
config.filter_run_excluding :foo => true
|
710
|
-
config.exclusion_filter[:foo].should be(true)
|
711
|
-
end
|
712
|
-
|
713
|
-
it "sets the filter using a symbol" do
|
714
|
-
RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
|
715
|
-
config.filter_run_excluding :foo
|
716
|
-
config.exclusion_filter[:foo].should be(true)
|
717
|
-
end
|
718
|
-
|
719
|
-
it "merges with existing filters" do
|
720
|
-
config.filter_run_excluding :foo => true
|
721
|
-
config.filter_run_excluding :bar => false
|
722
|
-
|
723
|
-
config.exclusion_filter[:foo].should be(true)
|
724
|
-
config.exclusion_filter[:bar].should be(false)
|
725
|
-
end
|
726
|
-
end
|
727
|
-
|
728
|
-
describe "#inclusion_filter" do
|
729
|
-
it "returns {} even if set to nil" do
|
730
|
-
config.inclusion_filter = nil
|
731
|
-
config.inclusion_filter.should eq({})
|
732
|
-
end
|
733
|
-
end
|
734
|
-
|
735
|
-
describe "#inclusion_filter=" do
|
736
|
-
it "treats symbols as hash keys with true values when told to" do
|
737
|
-
RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
|
738
|
-
config.inclusion_filter = :foo
|
739
|
-
config.inclusion_filter.should eq({:foo => true})
|
740
|
-
end
|
741
|
-
|
742
|
-
it "overrides any inclusion filters set on the command line or in configuration files" do
|
743
|
-
config.force(:inclusion_filter => { :foo => :bar })
|
744
|
-
config.inclusion_filter = {:want => :this}
|
745
|
-
config.inclusion_filter.should eq({:want => :this})
|
746
|
-
end
|
747
|
-
end
|
748
|
-
|
749
|
-
describe "#exclusion_filter" do
|
750
|
-
it "returns {} even if set to nil" do
|
751
|
-
config.exclusion_filter = nil
|
752
|
-
config.exclusion_filter.should eq({})
|
753
|
-
end
|
754
|
-
|
755
|
-
describe "the default :if filter" do
|
756
|
-
it "does not exclude a spec with { :if => true } metadata" do
|
757
|
-
config.exclusion_filter[:if].call(true).should be_false
|
758
|
-
end
|
759
|
-
|
760
|
-
it "excludes a spec with { :if => false } metadata" do
|
761
|
-
config.exclusion_filter[:if].call(false).should be_true
|
762
|
-
end
|
763
|
-
|
764
|
-
it "excludes a spec with { :if => nil } metadata" do
|
765
|
-
config.exclusion_filter[:if].call(nil).should be_true
|
766
|
-
end
|
767
|
-
end
|
768
|
-
|
769
|
-
describe "the default :unless filter" do
|
770
|
-
it "excludes a spec with { :unless => true } metadata" do
|
771
|
-
config.exclusion_filter[:unless].call(true).should be_true
|
772
|
-
end
|
773
|
-
|
774
|
-
it "does not exclude a spec with { :unless => false } metadata" do
|
775
|
-
config.exclusion_filter[:unless].call(false).should be_false
|
776
|
-
end
|
777
|
-
|
778
|
-
it "does not exclude a spec with { :unless => nil } metadata" do
|
779
|
-
config.exclusion_filter[:unless].call(nil).should be_false
|
780
|
-
end
|
781
|
-
end
|
782
|
-
end
|
783
|
-
|
784
|
-
describe "#exclusion_filter=" do
|
785
|
-
it "treats symbols as hash keys with true values when told to" do
|
786
|
-
RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
|
787
|
-
config.exclusion_filter = :foo
|
788
|
-
config.exclusion_filter.should eq({:foo => true})
|
789
|
-
end
|
790
|
-
|
791
|
-
it "overrides any exclusion filters set on the command line or in configuration files" do
|
792
|
-
config.force(:exclusion_filter => { :foo => :bar })
|
793
|
-
config.exclusion_filter = {:want => :this}
|
794
|
-
config.exclusion_filter.should eq({:want => :this})
|
795
|
-
end
|
796
|
-
end
|
797
|
-
|
798
|
-
describe "line_numbers=" do
|
799
|
-
before { config.filter_manager.stub(:warn) }
|
800
|
-
|
801
|
-
it "sets the line numbers" do
|
802
|
-
config.line_numbers = ['37']
|
803
|
-
config.filter.should eq({:line_numbers => [37]})
|
804
|
-
end
|
805
|
-
|
806
|
-
it "overrides filters" do
|
807
|
-
config.filter_run :focused => true
|
808
|
-
config.line_numbers = ['37']
|
809
|
-
config.filter.should eq({:line_numbers => [37]})
|
810
|
-
end
|
811
|
-
|
812
|
-
it "prevents subsequent filters" do
|
813
|
-
config.line_numbers = ['37']
|
814
|
-
config.filter_run :focused => true
|
815
|
-
config.filter.should eq({:line_numbers => [37]})
|
816
|
-
end
|
817
|
-
end
|
818
|
-
|
819
|
-
describe "#full_backtrace=" do
|
820
|
-
context "given true" do
|
821
|
-
it "clears the backtrace clean patterns" do
|
822
|
-
config.full_backtrace = true
|
823
|
-
config.backtrace_clean_patterns.should eq([])
|
824
|
-
end
|
825
|
-
end
|
826
|
-
|
827
|
-
context "given false" do
|
828
|
-
it "restores backtrace clean patterns" do
|
829
|
-
config.full_backtrace = false
|
830
|
-
config.backtrace_clean_patterns.should eq(RSpec::Core::Configuration::DEFAULT_BACKTRACE_PATTERNS)
|
831
|
-
end
|
832
|
-
end
|
833
|
-
|
834
|
-
it "doesn't impact other instances of config" do
|
835
|
-
config_1 = Configuration.new
|
836
|
-
config_2 = Configuration.new
|
837
|
-
|
838
|
-
config_1.full_backtrace = true
|
839
|
-
config_2.backtrace_clean_patterns.should_not be_empty
|
840
|
-
end
|
841
|
-
end
|
842
|
-
|
843
|
-
describe "#cleaned_from_backtrace? defaults" do
|
844
|
-
it "returns true for rspec files" do
|
845
|
-
config.cleaned_from_backtrace?("lib/rspec/core.rb").
|
846
|
-
should be_true
|
847
|
-
end
|
848
|
-
|
849
|
-
it "returns true for spec_helper" do
|
850
|
-
config.cleaned_from_backtrace?("spec/spec_helper.rb").
|
851
|
-
should be_true
|
852
|
-
end
|
853
|
-
|
854
|
-
it "returns true for java files (for JRuby)" do
|
855
|
-
config.cleaned_from_backtrace?("org/jruby/RubyArray.java:2336").
|
856
|
-
should be_true
|
857
|
-
end
|
858
|
-
end
|
859
|
-
|
860
|
-
describe "#debug=true" do
|
861
|
-
before do
|
862
|
-
if defined?(Debugger)
|
863
|
-
@orig_debugger = Debugger
|
864
|
-
Object.send(:remove_const, :Debugger)
|
865
|
-
else
|
866
|
-
@orig_debugger = nil
|
867
|
-
end
|
868
|
-
Object.const_set("Debugger", debugger)
|
869
|
-
end
|
870
|
-
|
871
|
-
after do
|
872
|
-
Object.send(:remove_const, :Debugger)
|
873
|
-
Object.const_set("Debugger", @orig_debugger) if @orig_debugger
|
874
|
-
end
|
875
|
-
|
876
|
-
let(:debugger) { double('Debugger').as_null_object }
|
877
|
-
|
878
|
-
it "requires 'ruby-debug'" do
|
879
|
-
config.should_receive(:require).with('ruby-debug')
|
880
|
-
config.debug = true
|
881
|
-
end
|
882
|
-
|
883
|
-
it "starts the debugger" do
|
884
|
-
config.stub(:require)
|
885
|
-
debugger.should_receive(:start)
|
886
|
-
config.debug = true
|
887
|
-
end
|
888
|
-
end
|
889
|
-
|
890
|
-
describe "#debug=false" do
|
891
|
-
it "does not require 'ruby-debug'" do
|
892
|
-
config.should_not_receive(:require).with('ruby-debug')
|
893
|
-
config.debug = false
|
894
|
-
end
|
895
|
-
end
|
896
|
-
|
897
|
-
describe "#output=" do
|
898
|
-
it "sets the output" do
|
899
|
-
output = mock("output")
|
900
|
-
config.output = output
|
901
|
-
config.output.should equal(output)
|
902
|
-
end
|
903
|
-
end
|
904
|
-
|
905
|
-
describe "#libs=" do
|
906
|
-
it "adds directories to the LOAD_PATH" do
|
907
|
-
$LOAD_PATH.should_receive(:unshift).with("a/dir")
|
908
|
-
config.libs = ["a/dir"]
|
909
|
-
end
|
910
|
-
end
|
911
|
-
|
912
|
-
describe "#requires=" do
|
913
|
-
it "requires paths" do
|
914
|
-
config.should_receive(:require).with("a/path")
|
915
|
-
config.requires = ["a/path"]
|
916
|
-
end
|
917
|
-
end
|
918
|
-
|
919
|
-
describe "#add_setting" do
|
920
|
-
describe "with no modifiers" do
|
921
|
-
context "with no additional options" do
|
922
|
-
before do
|
923
|
-
config.add_setting :custom_option
|
924
|
-
end
|
925
|
-
|
926
|
-
it "defaults to nil" do
|
927
|
-
config.custom_option.should be_nil
|
928
|
-
end
|
929
|
-
|
930
|
-
it "adds a predicate" do
|
931
|
-
config.custom_option?.should be_false
|
932
|
-
end
|
933
|
-
|
934
|
-
it "can be overridden" do
|
935
|
-
config.custom_option = "a value"
|
936
|
-
config.custom_option.should eq("a value")
|
937
|
-
end
|
938
|
-
end
|
939
|
-
|
940
|
-
context "with :default => 'a value'" do
|
941
|
-
before do
|
942
|
-
config.add_setting :custom_option, :default => 'a value'
|
943
|
-
end
|
944
|
-
|
945
|
-
it "defaults to 'a value'" do
|
946
|
-
config.custom_option.should eq("a value")
|
947
|
-
end
|
948
|
-
|
949
|
-
it "returns true for the predicate" do
|
950
|
-
config.custom_option?.should be_true
|
951
|
-
end
|
952
|
-
|
953
|
-
it "can be overridden with a truthy value" do
|
954
|
-
config.custom_option = "a new value"
|
955
|
-
config.custom_option.should eq("a new value")
|
956
|
-
end
|
957
|
-
|
958
|
-
it "can be overridden with nil" do
|
959
|
-
config.custom_option = nil
|
960
|
-
config.custom_option.should eq(nil)
|
961
|
-
end
|
962
|
-
|
963
|
-
it "can be overridden with false" do
|
964
|
-
config.custom_option = false
|
965
|
-
config.custom_option.should eq(false)
|
966
|
-
end
|
967
|
-
end
|
968
|
-
end
|
969
|
-
|
970
|
-
context "with :alias => " do
|
971
|
-
it "is deprecated" do
|
972
|
-
RSpec::should_receive(:warn).with(/deprecated/)
|
973
|
-
config.add_setting :custom_option
|
974
|
-
config.add_setting :another_custom_option, :alias => :custom_option
|
975
|
-
end
|
976
|
-
end
|
977
|
-
|
978
|
-
context "with :alias_with => " do
|
979
|
-
before do
|
980
|
-
config.add_setting :custom_option, :alias_with => :another_custom_option
|
981
|
-
end
|
982
|
-
|
983
|
-
it "delegates the getter to the other option" do
|
984
|
-
config.another_custom_option = "this value"
|
985
|
-
config.custom_option.should eq("this value")
|
986
|
-
end
|
987
|
-
|
988
|
-
it "delegates the setter to the other option" do
|
989
|
-
config.custom_option = "this value"
|
990
|
-
config.another_custom_option.should eq("this value")
|
991
|
-
end
|
992
|
-
|
993
|
-
it "delegates the predicate to the other option" do
|
994
|
-
config.custom_option = true
|
995
|
-
config.another_custom_option?.should be_true
|
996
|
-
end
|
997
|
-
end
|
998
|
-
end
|
999
|
-
|
1000
|
-
describe "#configure_group" do
|
1001
|
-
it "extends with 'extend'" do
|
1002
|
-
mod = Module.new
|
1003
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
1004
|
-
|
1005
|
-
config.extend(mod, :foo => :bar)
|
1006
|
-
config.configure_group(group)
|
1007
|
-
group.should be_a(mod)
|
1008
|
-
end
|
1009
|
-
|
1010
|
-
it "extends with 'module'" do
|
1011
|
-
mod = Module.new
|
1012
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
1013
|
-
|
1014
|
-
config.include(mod, :foo => :bar)
|
1015
|
-
config.configure_group(group)
|
1016
|
-
group.included_modules.should include(mod)
|
1017
|
-
end
|
1018
|
-
|
1019
|
-
it "requires only one matching filter" do
|
1020
|
-
mod = Module.new
|
1021
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
1022
|
-
|
1023
|
-
config.include(mod, :foo => :bar, :baz => :bam)
|
1024
|
-
config.configure_group(group)
|
1025
|
-
group.included_modules.should include(mod)
|
1026
|
-
end
|
1027
|
-
|
1028
|
-
it "includes each one before deciding whether to include the next" do
|
1029
|
-
mod1 = Module.new do
|
1030
|
-
def self.included(host)
|
1031
|
-
host.metadata[:foo] = :bar
|
1032
|
-
end
|
1033
|
-
end
|
1034
|
-
mod2 = Module.new
|
1035
|
-
|
1036
|
-
group = ExampleGroup.describe("group")
|
1037
|
-
|
1038
|
-
config.include(mod1)
|
1039
|
-
config.include(mod2, :foo => :bar)
|
1040
|
-
config.configure_group(group)
|
1041
|
-
group.included_modules.should include(mod1)
|
1042
|
-
group.included_modules.should include(mod2)
|
1043
|
-
end
|
1044
|
-
|
1045
|
-
module IncludeOrExtendMeOnce
|
1046
|
-
def self.included(host)
|
1047
|
-
raise "included again" if host.instance_methods.include?(:foobar)
|
1048
|
-
host.class_eval { def foobar; end }
|
1049
|
-
end
|
1050
|
-
|
1051
|
-
def self.extended(host)
|
1052
|
-
raise "extended again" if host.respond_to?(:foobar)
|
1053
|
-
def host.foobar; end
|
1054
|
-
end
|
1055
|
-
end
|
1056
|
-
|
1057
|
-
it "doesn't include a module when already included in ancestor" do
|
1058
|
-
config.include(IncludeOrExtendMeOnce, :foo => :bar)
|
1059
|
-
|
1060
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
1061
|
-
child = group.describe("child")
|
1062
|
-
|
1063
|
-
config.configure_group(group)
|
1064
|
-
config.configure_group(child)
|
1065
|
-
end
|
1066
|
-
|
1067
|
-
it "doesn't extend when ancestor is already extended with same module" do
|
1068
|
-
config.extend(IncludeOrExtendMeOnce, :foo => :bar)
|
1069
|
-
|
1070
|
-
group = ExampleGroup.describe("group", :foo => :bar)
|
1071
|
-
child = group.describe("child")
|
1072
|
-
|
1073
|
-
config.configure_group(group)
|
1074
|
-
config.configure_group(child)
|
1075
|
-
end
|
1076
|
-
end
|
1077
|
-
|
1078
|
-
describe "#alias_example_to" do
|
1079
|
-
it_behaves_like "metadata hash builder" do
|
1080
|
-
after do
|
1081
|
-
RSpec::Core::ExampleGroup.module_eval do
|
1082
|
-
class << self
|
1083
|
-
undef :my_example_method if method_defined? :my_example_method
|
1084
|
-
end
|
1085
|
-
end
|
1086
|
-
end
|
1087
|
-
def metadata_hash(*args)
|
1088
|
-
config.alias_example_to :my_example_method, *args
|
1089
|
-
group = ExampleGroup.describe("group")
|
1090
|
-
example = group.my_example_method("description")
|
1091
|
-
example.metadata
|
1092
|
-
end
|
1093
|
-
end
|
1094
|
-
end
|
1095
|
-
|
1096
|
-
describe "#reset" do
|
1097
|
-
it "clears the reporter" do
|
1098
|
-
config.reporter.should_not be_nil
|
1099
|
-
config.reset
|
1100
|
-
config.instance_variable_get("@reporter").should be_nil
|
1101
|
-
end
|
1102
|
-
|
1103
|
-
it "clears the formatters" do
|
1104
|
-
config.add_formatter "doc"
|
1105
|
-
config.reset
|
1106
|
-
config.formatters.should be_empty
|
1107
|
-
end
|
1108
|
-
end
|
1109
|
-
|
1110
|
-
describe "#force" do
|
1111
|
-
it "forces order" do
|
1112
|
-
config.force :order => "default"
|
1113
|
-
config.order = "rand"
|
1114
|
-
config.order.should eq("default")
|
1115
|
-
end
|
1116
|
-
|
1117
|
-
it "forces order and seed with :order => 'rand:37'" do
|
1118
|
-
config.force :order => "rand:37"
|
1119
|
-
config.order = "default"
|
1120
|
-
config.order.should eq("rand")
|
1121
|
-
config.seed.should eq(37)
|
1122
|
-
end
|
1123
|
-
|
1124
|
-
it "forces order and seed with :seed => '37'" do
|
1125
|
-
config.force :seed => "37"
|
1126
|
-
config.order = "default"
|
1127
|
-
config.seed.should eq(37)
|
1128
|
-
config.order.should eq("rand")
|
1129
|
-
end
|
1130
|
-
|
1131
|
-
it "forces 'false' value" do
|
1132
|
-
config.add_setting :custom_option
|
1133
|
-
config.custom_option = true
|
1134
|
-
config.custom_option?.should be_true
|
1135
|
-
config.force :custom_option => false
|
1136
|
-
config.custom_option?.should be_false
|
1137
|
-
config.custom_option = true
|
1138
|
-
config.custom_option?.should be_false
|
1139
|
-
end
|
1140
|
-
end
|
1141
|
-
|
1142
|
-
describe '#seed' do
|
1143
|
-
it 'returns the seed as an int' do
|
1144
|
-
config.seed = '123'
|
1145
|
-
config.seed.should eq(123)
|
1146
|
-
end
|
1147
|
-
end
|
1148
|
-
|
1149
|
-
describe '#randomize?' do
|
1150
|
-
context 'with order set to :random' do
|
1151
|
-
before { config.order = :random }
|
1152
|
-
|
1153
|
-
it 'returns true' do
|
1154
|
-
config.randomize?.should be_true
|
1155
|
-
end
|
1156
|
-
end
|
1157
|
-
|
1158
|
-
context 'with order set to nil' do
|
1159
|
-
before { config.order = nil }
|
1160
|
-
|
1161
|
-
it 'returns false' do
|
1162
|
-
config.randomize?.should be_false
|
1163
|
-
end
|
1164
|
-
end
|
1165
|
-
end
|
1166
|
-
|
1167
|
-
describe '#order=' do
|
1168
|
-
context 'given "random:123"' do
|
1169
|
-
before { config.order = 'random:123' }
|
1170
|
-
|
1171
|
-
it 'sets order to "random"' do
|
1172
|
-
config.order.should eq('random')
|
1173
|
-
end
|
1174
|
-
|
1175
|
-
it 'sets seed to 123' do
|
1176
|
-
config.seed.should eq(123)
|
1177
|
-
end
|
1178
|
-
end
|
1179
|
-
|
1180
|
-
context 'given "default"' do
|
1181
|
-
before do
|
1182
|
-
config.order = 'rand:123'
|
1183
|
-
config.order = 'default'
|
1184
|
-
end
|
1185
|
-
|
1186
|
-
it "sets the order to nil" do
|
1187
|
-
config.order.should be_nil
|
1188
|
-
end
|
1189
|
-
|
1190
|
-
it "sets the seed to nil" do
|
1191
|
-
config.seed.should be_nil
|
1192
|
-
end
|
1193
|
-
end
|
1194
|
-
end
|
1195
|
-
end
|
1196
|
-
end
|