rspec-core 3.0.0.beta1 → 3.0.0.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/Changelog.md +137 -0
- data/README.md +2 -2
- data/exe/rspec +2 -23
- data/features/README.md +1 -5
- data/features/command_line/README.md +7 -10
- data/features/command_line/exit_status.feature +1 -1
- data/features/command_line/format_option.feature +1 -1
- data/features/command_line/init.feature +40 -1
- data/features/command_line/line_number_option.feature +2 -2
- data/features/command_line/ruby.feature +5 -4
- data/features/configuration/enable_global_dsl.feature +54 -0
- data/features/example_groups/aliasing.feature +48 -0
- data/features/example_groups/basic_structure.feature +1 -1
- data/features/expectation_framework_integration/configure_expectation_framework.feature +1 -1
- data/features/filtering/if_and_unless.feature +0 -30
- data/features/formatters/custom_formatter.feature +32 -0
- data/features/formatters/regression_tests.feature +95 -0
- data/features/hooks/around_hooks.feature +1 -0
- data/features/hooks/before_and_after_hooks.feature +2 -2
- data/features/mock_framework_integration/use_flexmock.feature +11 -13
- data/features/mock_framework_integration/use_mocha.feature +11 -13
- data/features/mock_framework_integration/use_rr.feature +11 -13
- data/features/mock_framework_integration/use_rspec.feature +11 -13
- data/features/pending_and_skipped_examples/README.md +3 -0
- data/features/pending_and_skipped_examples/pending_examples.feature +118 -0
- data/features/pending_and_skipped_examples/skipped_examples.feature +106 -0
- data/features/step_definitions/additional_cli_steps.rb +34 -0
- data/features/subject/explicit_subject.feature +1 -1
- data/features/subject/one_liner_syntax.feature +71 -0
- data/lib/rspec/core.rb +6 -14
- data/lib/rspec/core/backtrace_formatter.rb +16 -4
- data/lib/rspec/core/command_line.rb +2 -3
- data/lib/rspec/core/configuration.rb +114 -125
- data/lib/rspec/core/configuration_options.rb +32 -18
- data/lib/rspec/core/dsl.rb +80 -18
- data/lib/rspec/core/example.rb +84 -33
- data/lib/rspec/core/example_group.rb +95 -43
- data/lib/rspec/core/filter_manager.rb +31 -40
- data/lib/rspec/core/formatters.rb +137 -0
- data/lib/rspec/core/formatters/base_formatter.rb +28 -41
- data/lib/rspec/core/formatters/base_text_formatter.rb +26 -37
- data/lib/rspec/core/formatters/deprecation_formatter.rb +48 -27
- data/lib/rspec/core/formatters/documentation_formatter.rb +27 -22
- data/lib/rspec/core/formatters/html_formatter.rb +48 -56
- data/lib/rspec/core/formatters/html_printer.rb +11 -18
- data/lib/rspec/core/formatters/json_formatter.rb +18 -22
- data/lib/rspec/core/formatters/legacy_formatter.rb +227 -0
- data/lib/rspec/core/formatters/progress_formatter.rb +7 -10
- data/lib/rspec/core/hooks.rb +250 -217
- data/lib/rspec/core/memoized_helpers.rb +43 -9
- 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 +28 -0
- data/lib/rspec/core/mocking_adapters/rspec.rb +30 -0
- data/lib/rspec/core/notifications.rb +100 -0
- data/lib/rspec/core/option_parser.rb +11 -18
- data/lib/rspec/core/pending.rb +78 -47
- data/lib/rspec/core/project_initializer.rb +2 -49
- data/lib/rspec/core/project_initializer/dot_rspec +3 -0
- data/lib/rspec/core/project_initializer/spec_helper.rb +82 -0
- data/lib/rspec/core/rake_task.rb +5 -14
- data/lib/rspec/core/reporter.rb +24 -32
- data/lib/rspec/core/ruby_project.rb +1 -1
- data/lib/rspec/core/runner.rb +14 -4
- data/lib/rspec/core/shared_example_group.rb +40 -13
- data/lib/rspec/core/version.rb +1 -1
- data/spec/command_line/order_spec.rb +15 -15
- data/spec/rspec/core/backtrace_formatter_spec.rb +15 -1
- data/spec/rspec/core/command_line_spec.rb +18 -17
- data/spec/rspec/core/configuration_options_spec.rb +57 -34
- data/spec/rspec/core/configuration_spec.rb +162 -184
- data/spec/rspec/core/drb_command_line_spec.rb +5 -7
- data/spec/rspec/core/drb_options_spec.rb +2 -2
- data/spec/rspec/core/dsl_spec.rb +79 -15
- data/spec/rspec/core/example_group_spec.rb +253 -39
- data/spec/rspec/core/example_spec.rb +149 -33
- data/spec/rspec/core/filter_manager_spec.rb +9 -26
- data/spec/rspec/core/formatters/base_formatter_spec.rb +2 -5
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +42 -145
- data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +64 -34
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +15 -28
- data/spec/rspec/core/formatters/helpers_spec.rb +2 -2
- data/spec/rspec/core/formatters/{html_formatted-1.8.7.html → html_formatted-2.1.0.html} +22 -44
- data/spec/rspec/core/formatters/{html_formatted-1.8.7-jruby.html → html_formatted.html} +30 -49
- data/spec/rspec/core/formatters/html_formatter_spec.rb +35 -19
- data/spec/rspec/core/formatters/json_formatter_spec.rb +42 -40
- data/spec/rspec/core/formatters/legacy_formatter_spec.rb +137 -0
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +38 -25
- data/spec/rspec/core/formatters/snippet_extractor_spec.rb +1 -1
- data/spec/rspec/core/formatters_spec.rb +120 -0
- data/spec/rspec/core/hooks_filtering_spec.rb +1 -1
- data/spec/rspec/core/hooks_spec.rb +13 -2
- data/spec/rspec/core/memoized_helpers_spec.rb +17 -8
- data/spec/rspec/core/metadata_spec.rb +3 -3
- data/spec/rspec/core/option_parser_spec.rb +53 -46
- data/spec/rspec/core/ordering_spec.rb +4 -4
- data/spec/rspec/core/pending_example_spec.rb +23 -126
- data/spec/rspec/core/pending_spec.rb +8 -0
- data/spec/rspec/core/project_initializer_spec.rb +8 -41
- data/spec/rspec/core/rake_task_spec.rb +15 -4
- data/spec/rspec/core/random_spec.rb +1 -1
- data/spec/rspec/core/reporter_spec.rb +50 -37
- data/spec/rspec/core/resources/formatter_specs.rb +9 -11
- data/spec/rspec/core/rspec_matchers_spec.rb +1 -1
- data/spec/rspec/core/ruby_project_spec.rb +3 -3
- data/spec/rspec/core/runner_spec.rb +65 -23
- data/spec/rspec/core/shared_context_spec.rb +4 -4
- data/spec/rspec/core/shared_example_group/collection_spec.rb +1 -1
- data/spec/rspec/core/shared_example_group_spec.rb +20 -11
- data/spec/rspec/core/warnings_spec.rb +1 -1
- data/spec/rspec/core/world_spec.rb +10 -10
- data/spec/rspec/core_spec.rb +2 -2
- data/spec/spec_helper.rb +12 -24
- data/spec/support/config_options_helper.rb +1 -3
- data/spec/support/formatter_support.rb +83 -0
- data/spec/support/isolate_load_path_mutation.rb +1 -2
- data/spec/support/isolated_directory.rb +1 -1
- data/spec/support/isolated_home_directory.rb +1 -1
- data/spec/support/legacy_formatter_using_sub_classing_example.rb +87 -0
- data/spec/support/matchers.rb +20 -0
- data/spec/support/mathn_integration_support.rb +2 -2
- data/spec/support/old_style_formatter_example.rb +69 -0
- data/spec/support/shared_example_groups.rb +1 -1
- data/spec/support/spec_files.rb +3 -3
- metadata +192 -69
- metadata.gz.sig +3 -1
- checksums.yaml +0 -15
- checksums.yaml.gz.sig +0 -2
- data/features/configuration/show_failures_in_pending_blocks.feature +0 -61
- data/features/pending/pending_examples.feature +0 -229
- data/features/subject/implicit_receiver.feature +0 -29
- 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/spec/rspec/core/formatters/html_formatted-1.8.7-rbx.html +0 -477
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +0 -425
- data/spec/rspec/core/formatters/html_formatted-1.9.3-jruby.html +0 -416
- data/spec/rspec/core/formatters/html_formatted-1.9.3-rbx.html +0 -477
- data/spec/rspec/core/formatters/html_formatted-1.9.3.html +0 -419
- data/spec/rspec/core/formatters/html_formatted-2.0.0.html +0 -425
- data/spec/support/in_sub_process.rb +0 -37
- data/spec/support/sandboxed_mock_space.rb +0 -100
|
@@ -4,7 +4,7 @@ require 'rspec/core/formatters/snippet_extractor'
|
|
|
4
4
|
module RSpec
|
|
5
5
|
module Core
|
|
6
6
|
module Formatters
|
|
7
|
-
describe SnippetExtractor do
|
|
7
|
+
RSpec.describe SnippetExtractor do
|
|
8
8
|
it "falls back on a default message when it doesn't understand a line" do
|
|
9
9
|
expect(RSpec::Core::Formatters::SnippetExtractor.new.snippet_for("blech")).to eq(["# Couldn't get snippet for blech", 1])
|
|
10
10
|
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module RSpec::Core::Formatters
|
|
4
|
+
describe Loader do
|
|
5
|
+
|
|
6
|
+
describe "#add(formatter)" do
|
|
7
|
+
let(:loader) { Loader.new reporter }
|
|
8
|
+
let(:output) { StringIO.new }
|
|
9
|
+
let(:path) { File.join(Dir.tmpdir, 'output.txt') }
|
|
10
|
+
let(:reporter) { double "reporter", :register_listener => nil }
|
|
11
|
+
|
|
12
|
+
it "adds to the list of formatters" do
|
|
13
|
+
loader.add :documentation, output
|
|
14
|
+
expect(loader.formatters.first).to be_an_instance_of(DocumentationFormatter)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "finds a formatter by name (w/ Symbol)" do
|
|
18
|
+
loader.add :documentation, output
|
|
19
|
+
expect(loader.formatters.first).to be_an_instance_of(DocumentationFormatter)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "finds a formatter by name (w/ String)" do
|
|
23
|
+
loader.add 'documentation', output
|
|
24
|
+
expect(loader.formatters.first).to be_an_instance_of(DocumentationFormatter)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "finds a formatter by class" do
|
|
28
|
+
formatter_class = Class.new(BaseTextFormatter)
|
|
29
|
+
Loader.formatters[formatter_class] = []
|
|
30
|
+
loader.add formatter_class, output
|
|
31
|
+
expect(loader.formatters.first).to be_an_instance_of(formatter_class)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "finds a formatter by class name" do
|
|
35
|
+
stub_const("CustomFormatter", Class.new(BaseFormatter))
|
|
36
|
+
Loader.formatters[CustomFormatter] = []
|
|
37
|
+
loader.add "CustomFormatter", output
|
|
38
|
+
expect(loader.formatters.first).to be_an_instance_of(CustomFormatter)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "handles formatters that dont implement notifications" do
|
|
42
|
+
formatter_class = Struct.new(:output)
|
|
43
|
+
loader.add formatter_class, output
|
|
44
|
+
expect(loader.formatters.first).to be_an_instance_of(RSpec::Core::Formatters::LegacyFormatter)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "when a legacy formatter is added" do
|
|
48
|
+
formatter_class = Struct.new(:output)
|
|
49
|
+
|
|
50
|
+
it "issues a deprecation" do
|
|
51
|
+
expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 2,
|
|
52
|
+
/The #{formatter_class} formatter uses the deprecated formatter interface/)
|
|
53
|
+
loader.add formatter_class, output
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "does not mistakenly add in the progress formatter" do
|
|
57
|
+
# When we issue a deprecation warning it triggers `setup_defaults`,
|
|
58
|
+
# which adds the progress formatter if it thinks no formatter has been
|
|
59
|
+
# added yet.
|
|
60
|
+
allow(RSpec).to receive(:warn_deprecation) do
|
|
61
|
+
loader.setup_default(StringIO.new, StringIO.new)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
loader.add formatter_class, output
|
|
65
|
+
|
|
66
|
+
expect(loader.formatters.grep(RSpec::Core::Formatters::ProgressFormatter)).to eq([])
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "finds a formatter by class fully qualified name" do
|
|
71
|
+
stub_const("RSpec::CustomFormatter", (Class.new(BaseFormatter)))
|
|
72
|
+
Loader.formatters[RSpec::CustomFormatter] = []
|
|
73
|
+
loader.add "RSpec::CustomFormatter", output
|
|
74
|
+
expect(loader.formatters.first).to be_an_instance_of(RSpec::CustomFormatter)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "requires a formatter file based on its fully qualified name" do
|
|
78
|
+
expect(loader).to receive(:require).with('rspec/custom_formatter') do
|
|
79
|
+
stub_const("RSpec::CustomFormatter", (Class.new(BaseFormatter)))
|
|
80
|
+
Loader.formatters[RSpec::CustomFormatter] = []
|
|
81
|
+
end
|
|
82
|
+
loader.add "RSpec::CustomFormatter", output
|
|
83
|
+
expect(loader.formatters.first).to be_an_instance_of(RSpec::CustomFormatter)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "raises NameError if class is unresolvable" do
|
|
87
|
+
expect(loader).to receive(:require).with('rspec/custom_formatter3')
|
|
88
|
+
expect { loader.add "RSpec::CustomFormatter3", output }.to raise_error(NameError)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "raises ArgumentError if formatter is unknown" do
|
|
92
|
+
expect { loader.add :progresss, output }.to raise_error(ArgumentError)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
context "with a 2nd arg defining the output" do
|
|
96
|
+
it "creates a file at that path and sets it as the output" do
|
|
97
|
+
loader.add('doc', path)
|
|
98
|
+
expect(loader.formatters.first.output).to be_a(File)
|
|
99
|
+
expect(loader.formatters.first.output.path).to eq(path)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
context "when a duplicate formatter exists" do
|
|
104
|
+
before { loader.add :documentation, output }
|
|
105
|
+
|
|
106
|
+
it "doesn't add the formatter for the same output target" do
|
|
107
|
+
expect {
|
|
108
|
+
loader.add :documentation, output
|
|
109
|
+
}.not_to change { loader.formatters.length }
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "adds the formatter for different output targets" do
|
|
113
|
+
expect {
|
|
114
|
+
loader.add :documentation, path
|
|
115
|
+
}.to change { loader.formatters.length }
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
3
|
module RSpec::Core
|
|
4
|
-
describe Hooks do
|
|
4
|
+
RSpec.describe Hooks do
|
|
5
5
|
class HooksHost
|
|
6
6
|
include Hooks
|
|
7
7
|
|
|
@@ -69,7 +69,7 @@ module RSpec::Core
|
|
|
69
69
|
|
|
70
70
|
expect { |b|
|
|
71
71
|
instance.send(type, scope, &b)
|
|
72
|
-
instance.
|
|
72
|
+
instance.hooks.run(type, scope)
|
|
73
73
|
}.not_to yield_control
|
|
74
74
|
end
|
|
75
75
|
end
|
|
@@ -279,5 +279,16 @@ module RSpec::Core
|
|
|
279
279
|
expect(messages).to eq ["hook 1", "hook 2", "example"]
|
|
280
280
|
end
|
|
281
281
|
end
|
|
282
|
+
|
|
283
|
+
it "only defines methods that are intended to be part of RSpec's public API (+ `hooks`)" do
|
|
284
|
+
expect(Hooks.private_instance_methods).to eq([])
|
|
285
|
+
|
|
286
|
+
expect(Hooks.instance_methods.map(&:to_sym)).to match_array([
|
|
287
|
+
:before, :after, :around,
|
|
288
|
+
:append_before, :append_after,
|
|
289
|
+
:prepend_before, :prepend_after,
|
|
290
|
+
:hooks
|
|
291
|
+
])
|
|
292
|
+
end
|
|
282
293
|
end
|
|
283
294
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module RSpec::Core
|
|
4
|
-
describe MemoizedHelpers do
|
|
4
|
+
RSpec.describe MemoizedHelpers do
|
|
5
5
|
before(:each) { RSpec.configuration.configure_expectation_framework }
|
|
6
6
|
|
|
7
7
|
def subject_value_for(describe_arg, &block)
|
|
@@ -73,7 +73,7 @@ module RSpec::Core
|
|
|
73
73
|
it "is evaluated once per example" do
|
|
74
74
|
group = ExampleGroup.describe(Array)
|
|
75
75
|
group.before do
|
|
76
|
-
Object.
|
|
76
|
+
expect(Object).to receive(:this_question?).once.and_return(falsy_value)
|
|
77
77
|
end
|
|
78
78
|
group.subject do
|
|
79
79
|
Object.this_question?
|
|
@@ -298,7 +298,16 @@ module RSpec::Core
|
|
|
298
298
|
it { should_not be_not_ok }
|
|
299
299
|
end
|
|
300
300
|
|
|
301
|
-
expect(group.run).to
|
|
301
|
+
expect(group.run).to be true
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
it 'supports a new expect-based syntax' do
|
|
305
|
+
group = ExampleGroup.describe([1, 2, 3]) do
|
|
306
|
+
it { is_expected.to be_an Array }
|
|
307
|
+
it { is_expected.not_to include 4 }
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
expect(group.run).to be true
|
|
302
311
|
end
|
|
303
312
|
end
|
|
304
313
|
|
|
@@ -316,7 +325,7 @@ module RSpec::Core
|
|
|
316
325
|
end
|
|
317
326
|
end
|
|
318
327
|
|
|
319
|
-
describe "#let" do
|
|
328
|
+
RSpec.describe "#let" do
|
|
320
329
|
let(:counter) do
|
|
321
330
|
Class.new do
|
|
322
331
|
def initialize
|
|
@@ -434,7 +443,7 @@ module RSpec::Core
|
|
|
434
443
|
end
|
|
435
444
|
end
|
|
436
445
|
|
|
437
|
-
describe "#let!" do
|
|
446
|
+
RSpec.describe "#let!" do
|
|
438
447
|
subject { [1,2,3] }
|
|
439
448
|
let!(:popped) { subject.pop }
|
|
440
449
|
|
|
@@ -447,7 +456,7 @@ module RSpec::Core
|
|
|
447
456
|
end
|
|
448
457
|
end
|
|
449
458
|
|
|
450
|
-
describe 'using subject in before and let blocks' do
|
|
459
|
+
RSpec.describe 'using subject in before and let blocks' do
|
|
451
460
|
shared_examples_for 'a subject' do
|
|
452
461
|
let(:subject_id_in_let) { subject.object_id }
|
|
453
462
|
before { @subject_id_in_before = subject.object_id }
|
|
@@ -456,7 +465,7 @@ module RSpec::Core
|
|
|
456
465
|
expect(subject_id_in_let).to eq(@subject_id_in_before)
|
|
457
466
|
end
|
|
458
467
|
|
|
459
|
-
it {
|
|
468
|
+
it { is_expected.to eq(subject) }
|
|
460
469
|
end
|
|
461
470
|
|
|
462
471
|
describe Object do
|
|
@@ -476,7 +485,7 @@ module RSpec::Core
|
|
|
476
485
|
end
|
|
477
486
|
end
|
|
478
487
|
|
|
479
|
-
describe 'Module#define_method' do
|
|
488
|
+
RSpec.describe 'Module#define_method' do
|
|
480
489
|
it 'is still a private method' do
|
|
481
490
|
a_module = Module.new
|
|
482
491
|
expect { a_module.define_method(:name) { "implementation" } }.to raise_error NoMethodError
|
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
module RSpec
|
|
4
4
|
module Core
|
|
5
|
-
describe Metadata do
|
|
5
|
+
RSpec.describe Metadata do
|
|
6
6
|
|
|
7
7
|
describe '.relative_path' do
|
|
8
8
|
let(:here) { File.expand_path(".") }
|
|
@@ -50,7 +50,7 @@ module RSpec
|
|
|
50
50
|
let(:next_example_metadata) { group_metadata.for_example('next_example', :caller => ["foo_spec.rb:#{example_line_number + 2}"]) }
|
|
51
51
|
let(:world) { World.new }
|
|
52
52
|
|
|
53
|
-
before { RSpec.
|
|
53
|
+
before { allow(RSpec).to receive(:world) { world } }
|
|
54
54
|
|
|
55
55
|
shared_examples_for "matching by line number" do
|
|
56
56
|
let(:preceeding_declaration_lines) {{
|
|
@@ -61,7 +61,7 @@ module RSpec
|
|
|
61
61
|
(example_metadata[:line_number] + 2) => example_metadata[:line_number] + 2,
|
|
62
62
|
}}
|
|
63
63
|
before do
|
|
64
|
-
world.
|
|
64
|
+
expect(world).to receive(:preceding_declaration_line).at_least(:once) do |v|
|
|
65
65
|
preceeding_declaration_lines[v]
|
|
66
66
|
end
|
|
67
67
|
end
|
|
@@ -1,53 +1,60 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
3
|
module RSpec::Core
|
|
4
|
-
describe OptionParser do
|
|
4
|
+
RSpec.describe OptionParser do
|
|
5
5
|
let(:output_file){ mock File }
|
|
6
6
|
|
|
7
7
|
before do
|
|
8
|
-
RSpec.
|
|
9
|
-
File.
|
|
8
|
+
allow(RSpec).to receive(:deprecate)
|
|
9
|
+
allow(File).to receive(:open).with("foo.txt",'w') { (output_file) }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it "does not parse empty args" do
|
|
13
13
|
parser = Parser.new
|
|
14
|
-
OptionParser.
|
|
15
|
-
parser.parse
|
|
14
|
+
expect(OptionParser).not_to receive(:new)
|
|
15
|
+
parser.parse([])
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it "proposes you to use --help and returns an error on incorrect argument" do
|
|
19
19
|
parser = Parser.new
|
|
20
20
|
option = "--my_wrong_arg"
|
|
21
21
|
|
|
22
|
-
parser.
|
|
22
|
+
expect(parser).to receive(:abort) do |msg|
|
|
23
23
|
expect(msg).to include('use --help', option)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
parser.parse
|
|
26
|
+
parser.parse([option])
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
{
|
|
30
|
+
'--init' => ['-i','--I'],
|
|
31
|
+
'--default-path' => ['-d'],
|
|
32
|
+
'--dry-run' => ['-d'],
|
|
33
|
+
'--drb-port' => ['-d'],
|
|
34
|
+
}.each do |long, shorts|
|
|
35
|
+
shorts.each do |option|
|
|
36
|
+
it "won't parse #{option} as a shorthand for #{long}" do
|
|
37
|
+
parser = Parser.new
|
|
38
|
+
|
|
39
|
+
expect(parser).to receive(:abort) do |msg|
|
|
40
|
+
expect(msg).to include('use --help', option)
|
|
41
|
+
end
|
|
34
42
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
expect(options[:formatters].first).to eq(["doc"])
|
|
43
|
+
parser.parse([option])
|
|
44
|
+
end
|
|
38
45
|
end
|
|
39
46
|
end
|
|
40
47
|
|
|
41
48
|
describe "--default_path" do
|
|
42
49
|
it "gets converted to --default-path" do
|
|
43
|
-
options = Parser.parse
|
|
50
|
+
options = Parser.parse(%w[--default_path foo])
|
|
44
51
|
expect(options[:default_path]).to eq "foo"
|
|
45
52
|
end
|
|
46
53
|
end
|
|
47
54
|
|
|
48
55
|
describe "--line_number" do
|
|
49
56
|
it "gets converted to --line-number" do
|
|
50
|
-
options = Parser.parse
|
|
57
|
+
options = Parser.parse(%w[--line_number 3])
|
|
51
58
|
expect(options[:line_numbers]).to eq ["3"]
|
|
52
59
|
end
|
|
53
60
|
end
|
|
@@ -55,7 +62,7 @@ module RSpec::Core
|
|
|
55
62
|
|
|
56
63
|
describe "--default-path" do
|
|
57
64
|
it "sets the default path where RSpec looks for examples" do
|
|
58
|
-
options = Parser.parse
|
|
65
|
+
options = Parser.parse(%w[--default-path foo])
|
|
59
66
|
expect(options[:default_path]).to eq "foo"
|
|
60
67
|
end
|
|
61
68
|
end
|
|
@@ -63,7 +70,7 @@ module RSpec::Core
|
|
|
63
70
|
%w[--line-number -l].each do |option|
|
|
64
71
|
describe option do
|
|
65
72
|
it "sets the line number of an example to run" do
|
|
66
|
-
options = Parser.parse
|
|
73
|
+
options = Parser.parse([option, "3"])
|
|
67
74
|
expect(options[:line_numbers]).to eq ["3"]
|
|
68
75
|
end
|
|
69
76
|
end
|
|
@@ -72,7 +79,7 @@ module RSpec::Core
|
|
|
72
79
|
%w[--format -f].each do |option|
|
|
73
80
|
describe option do
|
|
74
81
|
it "defines the formatter" do
|
|
75
|
-
options = Parser.parse
|
|
82
|
+
options = Parser.parse([option, 'doc'])
|
|
76
83
|
expect(options[:formatters].first).to eq(["doc"])
|
|
77
84
|
end
|
|
78
85
|
end
|
|
@@ -80,7 +87,7 @@ module RSpec::Core
|
|
|
80
87
|
|
|
81
88
|
%w[--out -o].each do |option|
|
|
82
89
|
describe option do
|
|
83
|
-
let(:options) { Parser.parse
|
|
90
|
+
let(:options) { Parser.parse([option, 'out.txt']) }
|
|
84
91
|
|
|
85
92
|
it "sets the output stream for the formatter" do
|
|
86
93
|
expect(options[:formatters].last).to eq(['progress', 'out.txt'])
|
|
@@ -89,7 +96,7 @@ module RSpec::Core
|
|
|
89
96
|
context "with multiple formatters" do
|
|
90
97
|
context "after last formatter" do
|
|
91
98
|
it "sets the output stream for the last formatter" do
|
|
92
|
-
options = Parser.parse
|
|
99
|
+
options = Parser.parse(['-f', 'progress', '-f', 'doc', option, 'out.txt'])
|
|
93
100
|
expect(options[:formatters][0]).to eq(['progress'])
|
|
94
101
|
expect(options[:formatters][1]).to eq(['doc', 'out.txt'])
|
|
95
102
|
end
|
|
@@ -97,7 +104,7 @@ module RSpec::Core
|
|
|
97
104
|
|
|
98
105
|
context "after first formatter" do
|
|
99
106
|
it "sets the output stream for the first formatter" do
|
|
100
|
-
options = Parser.parse
|
|
107
|
+
options = Parser.parse(['-f', 'progress', option, 'out.txt', '-f', 'doc'])
|
|
101
108
|
expect(options[:formatters][0]).to eq(['progress', 'out.txt'])
|
|
102
109
|
expect(options[:formatters][1]).to eq(['doc'])
|
|
103
110
|
end
|
|
@@ -109,7 +116,7 @@ module RSpec::Core
|
|
|
109
116
|
%w[--example -e].each do |option|
|
|
110
117
|
describe option do
|
|
111
118
|
it "escapes the arg" do
|
|
112
|
-
options = Parser.parse
|
|
119
|
+
options = Parser.parse([option, "this (and that)"])
|
|
113
120
|
expect(options[:full_description].length).to eq(1)
|
|
114
121
|
expect("this (and that)").to match(options[:full_description].first)
|
|
115
122
|
end
|
|
@@ -119,7 +126,7 @@ module RSpec::Core
|
|
|
119
126
|
%w[--pattern -P].each do |option|
|
|
120
127
|
describe option do
|
|
121
128
|
it "sets the filename pattern" do
|
|
122
|
-
options = Parser.parse
|
|
129
|
+
options = Parser.parse([option, 'spec/**/*.spec'])
|
|
123
130
|
expect(options[:pattern]).to eq('spec/**/*.spec')
|
|
124
131
|
end
|
|
125
132
|
end
|
|
@@ -129,69 +136,69 @@ module RSpec::Core
|
|
|
129
136
|
describe option do
|
|
130
137
|
context "without ~" do
|
|
131
138
|
it "treats no value as true" do
|
|
132
|
-
options = Parser.parse
|
|
139
|
+
options = Parser.parse([option, 'foo'])
|
|
133
140
|
expect(options[:inclusion_filter]).to eq(:foo => true)
|
|
134
141
|
end
|
|
135
142
|
|
|
136
143
|
it "treats 'true' as true" do
|
|
137
|
-
options = Parser.parse
|
|
144
|
+
options = Parser.parse([option, 'foo:true'])
|
|
138
145
|
expect(options[:inclusion_filter]).to eq(:foo => true)
|
|
139
146
|
end
|
|
140
147
|
|
|
141
148
|
it "treats 'nil' as nil" do
|
|
142
|
-
options = Parser.parse
|
|
149
|
+
options = Parser.parse([option, 'foo:nil'])
|
|
143
150
|
expect(options[:inclusion_filter]).to eq(:foo => nil)
|
|
144
151
|
end
|
|
145
152
|
|
|
146
153
|
it "treats 'false' as false" do
|
|
147
|
-
options = Parser.parse
|
|
154
|
+
options = Parser.parse([option, 'foo:false'])
|
|
148
155
|
expect(options[:inclusion_filter]).to eq(:foo => false)
|
|
149
156
|
end
|
|
150
157
|
|
|
151
158
|
it "merges muliple invocations" do
|
|
152
|
-
options = Parser.parse
|
|
159
|
+
options = Parser.parse([option, 'foo:false', option, 'bar:true', option, 'foo:true'])
|
|
153
160
|
expect(options[:inclusion_filter]).to eq(:foo => true, :bar => true)
|
|
154
161
|
end
|
|
155
162
|
|
|
156
163
|
it "treats 'any_string' as 'any_string'" do
|
|
157
|
-
options = Parser.parse
|
|
164
|
+
options = Parser.parse([option, 'foo:any_string'])
|
|
158
165
|
expect(options[:inclusion_filter]).to eq(:foo => 'any_string')
|
|
159
166
|
end
|
|
160
167
|
|
|
161
168
|
it "treats ':any_sym' as :any_sym" do
|
|
162
|
-
options = Parser.parse
|
|
169
|
+
options = Parser.parse([option, 'foo::any_sym'])
|
|
163
170
|
expect(options[:inclusion_filter]).to eq(:foo => :any_sym)
|
|
164
171
|
end
|
|
165
172
|
|
|
166
173
|
it "treats '42' as 42" do
|
|
167
|
-
options = Parser.parse
|
|
174
|
+
options = Parser.parse([option, 'foo:42'])
|
|
168
175
|
expect(options[:inclusion_filter]).to eq(:foo => 42)
|
|
169
176
|
end
|
|
170
177
|
|
|
171
178
|
it "treats '3.146' as 3.146" do
|
|
172
|
-
options = Parser.parse
|
|
179
|
+
options = Parser.parse([option, 'foo:3.146'])
|
|
173
180
|
expect(options[:inclusion_filter]).to eq(:foo => 3.146)
|
|
174
181
|
end
|
|
175
182
|
end
|
|
176
183
|
|
|
177
184
|
context "with ~" do
|
|
178
185
|
it "treats no value as true" do
|
|
179
|
-
options = Parser.parse
|
|
186
|
+
options = Parser.parse([option, '~foo'])
|
|
180
187
|
expect(options[:exclusion_filter]).to eq(:foo => true)
|
|
181
188
|
end
|
|
182
189
|
|
|
183
190
|
it "treats 'true' as true" do
|
|
184
|
-
options = Parser.parse
|
|
191
|
+
options = Parser.parse([option, '~foo:true'])
|
|
185
192
|
expect(options[:exclusion_filter]).to eq(:foo => true)
|
|
186
193
|
end
|
|
187
194
|
|
|
188
195
|
it "treats 'nil' as nil" do
|
|
189
|
-
options = Parser.parse
|
|
196
|
+
options = Parser.parse([option, '~foo:nil'])
|
|
190
197
|
expect(options[:exclusion_filter]).to eq(:foo => nil)
|
|
191
198
|
end
|
|
192
199
|
|
|
193
200
|
it "treats 'false' as false" do
|
|
194
|
-
options = Parser.parse
|
|
201
|
+
options = Parser.parse([option, '~foo:false'])
|
|
195
202
|
expect(options[:exclusion_filter]).to eq(:foo => false)
|
|
196
203
|
end
|
|
197
204
|
end
|
|
@@ -200,13 +207,13 @@ module RSpec::Core
|
|
|
200
207
|
|
|
201
208
|
describe "--order" do
|
|
202
209
|
it "is nil by default" do
|
|
203
|
-
expect(Parser.parse
|
|
210
|
+
expect(Parser.parse([])[:order]).to be_nil
|
|
204
211
|
end
|
|
205
212
|
|
|
206
213
|
%w[rand random].each do |option|
|
|
207
214
|
context "with #{option}" do
|
|
208
215
|
it "defines the order as random" do
|
|
209
|
-
options = Parser.parse
|
|
216
|
+
options = Parser.parse(['--order', option])
|
|
210
217
|
expect(options[:order]).to eq(option)
|
|
211
218
|
end
|
|
212
219
|
end
|
|
@@ -215,38 +222,38 @@ module RSpec::Core
|
|
|
215
222
|
|
|
216
223
|
describe "--seed" do
|
|
217
224
|
it "sets the order to rand:SEED" do
|
|
218
|
-
options = Parser.parse
|
|
225
|
+
options = Parser.parse(%w[--seed 123])
|
|
219
226
|
expect(options[:order]).to eq("rand:123")
|
|
220
227
|
end
|
|
221
228
|
end
|
|
222
229
|
|
|
223
230
|
describe '--profile' do
|
|
224
231
|
it 'sets profile_examples to true by default' do
|
|
225
|
-
options = Parser.parse
|
|
232
|
+
options = Parser.parse(%w[--profile])
|
|
226
233
|
expect(options[:profile_examples]).to eq true
|
|
227
234
|
end
|
|
228
235
|
|
|
229
236
|
it 'sets profile_examples to supplied int' do
|
|
230
|
-
options = Parser.parse
|
|
237
|
+
options = Parser.parse(%w[--profile 10])
|
|
231
238
|
expect(options[:profile_examples]).to eq 10
|
|
232
239
|
end
|
|
233
240
|
|
|
234
241
|
it 'sets profile_examples to true when accidentally combined with path' do
|
|
235
242
|
allow_warning
|
|
236
|
-
options = Parser.parse
|
|
243
|
+
options = Parser.parse(%w[--profile some/path])
|
|
237
244
|
expect(options[:profile_examples]).to eq true
|
|
238
245
|
end
|
|
239
246
|
|
|
240
247
|
it 'warns when accidentally combined with path' do
|
|
241
248
|
expect_warning_without_call_site "Non integer specified as profile count"
|
|
242
|
-
options = Parser.parse
|
|
249
|
+
options = Parser.parse(%w[--profile some/path])
|
|
243
250
|
expect(options[:profile_examples]).to eq true
|
|
244
251
|
end
|
|
245
252
|
end
|
|
246
253
|
|
|
247
254
|
describe '--warning' do
|
|
248
255
|
it 'enables warnings' do
|
|
249
|
-
options = Parser.parse
|
|
256
|
+
options = Parser.parse(%w[--warnings])
|
|
250
257
|
expect(options[:warnings]).to eq true
|
|
251
258
|
end
|
|
252
259
|
end
|