rspec-core 2.3.1 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.markdown +22 -0
- data/Rakefile +2 -2
- data/features/command_line/README.md +6 -0
- data/features/command_line/configure.feature +16 -14
- data/features/command_line/example_name_option.feature +3 -3
- data/features/command_line/format_option.feature +73 -0
- data/features/command_line/line_number_appended_to_path.feature +1 -1
- data/features/command_line/line_number_option.feature +2 -2
- data/features/command_line/tag.feature +7 -7
- data/features/configuration/read_options_from_file.feature +29 -16
- data/features/hooks/before_and_after_hooks.feature +9 -14
- data/features/hooks/filtering.feature +174 -0
- data/features/step_definitions/additional_cli_steps.rb +4 -0
- data/features/subject/attribute_of_subject.feature +68 -18
- data/lib/rspec/core/command_line_configuration.rb +16 -16
- data/lib/rspec/core/configuration.rb +14 -15
- data/lib/rspec/core/configuration_options.rb +46 -22
- data/lib/rspec/core/example.rb +16 -6
- data/lib/rspec/core/example_group.rb +11 -11
- data/lib/rspec/core/formatters/base_text_formatter.rb +2 -1
- data/lib/rspec/core/hooks.rb +8 -8
- data/lib/rspec/core/option_parser.rb +13 -3
- data/lib/rspec/core/pending.rb +2 -0
- data/lib/rspec/core/rake_task.rb +1 -1
- data/lib/rspec/core/subject.rb +2 -0
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/world.rb +2 -2
- data/spec/rspec/core/configuration_options_spec.rb +147 -151
- data/spec/rspec/core/configuration_spec.rb +67 -19
- data/spec/rspec/core/example_spec.rb +12 -10
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +25 -1
- data/spec/rspec/core/formatters/html_formatted-1.8.6.html +5 -5
- data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +37 -24
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +5 -5
- data/spec/rspec/core/formatters/html_formatted-1.9.1.html +5 -5
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +5 -5
- data/spec/rspec/core/formatters/html_formatter_spec.rb +7 -7
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +19 -19
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +51 -33
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +19 -19
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +26 -26
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +26 -26
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +7 -7
- data/spec/rspec/core/hooks_filtering_spec.rb +54 -0
- data/spec/rspec/core/option_parser_spec.rb +53 -17
- data/spec/rspec/core/rake_task_spec.rb +21 -0
- data/spec/spec_helper.rb +1 -1
- metadata +14 -8
@@ -147,7 +147,8 @@ module RSpec
|
|
147
147
|
exception = example.execution_result[:exception]
|
148
148
|
output.puts "#{short_padding}#{index.next}) #{example.full_description}"
|
149
149
|
output.puts "#{long_padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
|
150
|
-
|
150
|
+
output.puts "#{long_padding}#{red(exception.class.name << ":")}" unless exception.class.name =~ /RSpec/
|
151
|
+
exception.message.split("\n").each { |line| output.puts "#{long_padding} #{red(line)}" }
|
151
152
|
|
152
153
|
example.example_group.ancestors.push(example.example_group).each do |group|
|
153
154
|
if group.metadata[:shared_group_name]
|
data/lib/rspec/core/hooks.rb
CHANGED
@@ -10,8 +10,8 @@ module RSpec
|
|
10
10
|
@block = block
|
11
11
|
end
|
12
12
|
|
13
|
-
def options_apply?(
|
14
|
-
!
|
13
|
+
def options_apply?(example_or_group)
|
14
|
+
!example_or_group || example_or_group.apply?(:all?, options)
|
15
15
|
end
|
16
16
|
|
17
17
|
def to_proc
|
@@ -50,8 +50,8 @@ module RSpec
|
|
50
50
|
end
|
51
51
|
|
52
52
|
class HookCollection < Array
|
53
|
-
def find_hooks_for(
|
54
|
-
|
53
|
+
def find_hooks_for(example_or_group)
|
54
|
+
self.class.new(select {|hook| hook.options_apply?(example_or_group)})
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -112,12 +112,12 @@ module RSpec
|
|
112
112
|
hooks[hook][scope].run_all!(example_group_instance)
|
113
113
|
end
|
114
114
|
|
115
|
-
def run_hook_filtered(hook, scope, group, example_group_instance)
|
116
|
-
find_hook(hook, scope, group).run_all(example_group_instance)
|
115
|
+
def run_hook_filtered(hook, scope, group, example_group_instance, example = nil)
|
116
|
+
find_hook(hook, scope, group, example).run_all(example_group_instance)
|
117
117
|
end
|
118
118
|
|
119
|
-
def find_hook(hook, scope, example_group_class)
|
120
|
-
hooks[hook][scope].find_hooks_for(example_group_class)
|
119
|
+
def find_hook(hook, scope, example_group_class, example = nil)
|
120
|
+
hooks[hook][scope].find_hooks_for(example || example_group_class)
|
121
121
|
end
|
122
122
|
|
123
123
|
private
|
@@ -48,11 +48,17 @@ module RSpec::Core
|
|
48
48
|
' [h]tml',
|
49
49
|
' [t]extmate',
|
50
50
|
' custom formatter class name') do |o|
|
51
|
-
options[:
|
51
|
+
options[:formatters] ||= []
|
52
|
+
options[:formatters] << [o]
|
52
53
|
end
|
53
54
|
|
54
|
-
parser.on('-o', '--out FILE',
|
55
|
-
|
55
|
+
parser.on('-o', '--out FILE',
|
56
|
+
'Write output to a file instead of STDOUT. This option applies',
|
57
|
+
'to the previously specified --format, or the default format if',
|
58
|
+
'no format is specified.'
|
59
|
+
) do |o|
|
60
|
+
options[:formatters] ||= [['progress']]
|
61
|
+
options[:formatters].last << o
|
56
62
|
end
|
57
63
|
|
58
64
|
parser.on_tail('-h', '--help', "You're looking at it.") do
|
@@ -69,6 +75,10 @@ module RSpec::Core
|
|
69
75
|
options[:line_number] = o
|
70
76
|
end
|
71
77
|
|
78
|
+
parser.on('-O', '--options PATH', 'Specify the path to an options file') do |path|
|
79
|
+
options[:custom_options_file] = path
|
80
|
+
end
|
81
|
+
|
72
82
|
parser.on('-p', '--profile', 'Enable profiling of examples with output of the top 10 slowest examples') do |o|
|
73
83
|
options[:profile_examples] = o
|
74
84
|
end
|
data/lib/rspec/core/pending.rb
CHANGED
data/lib/rspec/core/rake_task.rb
CHANGED
data/lib/rspec/core/subject.rb
CHANGED
data/lib/rspec/core/version.rb
CHANGED
data/lib/rspec/core/world.rb
CHANGED
@@ -81,8 +81,8 @@ module RSpec
|
|
81
81
|
|
82
82
|
include RSpec::Core::Hooks
|
83
83
|
|
84
|
-
def find_hook(hook, scope, group)
|
85
|
-
@configuration.find_hook(hook, scope, group)
|
84
|
+
def find_hook(hook, scope, group, example = nil)
|
85
|
+
@configuration.find_hook(hook, scope, group, example)
|
86
86
|
end
|
87
87
|
|
88
88
|
private
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
|
3
2
|
require 'ostruct'
|
3
|
+
require 'tmpdir'
|
4
4
|
|
5
5
|
describe RSpec::Core::ConfigurationOptions do
|
6
6
|
|
@@ -10,7 +10,7 @@ describe RSpec::Core::ConfigurationOptions do
|
|
10
10
|
coo
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def parse_options(*args)
|
14
14
|
config_options_object(*args).options
|
15
15
|
end
|
16
16
|
|
@@ -27,114 +27,108 @@ describe RSpec::Core::ConfigurationOptions do
|
|
27
27
|
opts = config_options_object(*%w[--require a/path -f a/formatter])
|
28
28
|
config = double("config").as_null_object
|
29
29
|
config.should_receive(:requires=).ordered
|
30
|
-
config.should_receive(:
|
30
|
+
config.should_receive(:add_formatter).ordered
|
31
31
|
opts.configure(config)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
describe "-c, --color, and --colour" do
|
36
|
+
it "sets :color_enabled => true" do
|
37
|
+
parse_options('-c').should include(:color_enabled => true)
|
38
|
+
parse_options('--color').should include(:color_enabled => true)
|
39
|
+
parse_options('--colour').should include(:color_enabled => true)
|
40
40
|
end
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
describe "--no-color" do
|
44
|
+
it "sets :color_enabled => false" do
|
45
|
+
parse_options('--no-color').should include(:color_enabled => false)
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
47
|
-
describe
|
48
|
-
example "
|
49
|
-
|
49
|
+
describe "-I" do
|
50
|
+
example "adds to :libs" do
|
51
|
+
parse_options('-I', 'a_dir').should include(:libs => ['a_dir'])
|
50
52
|
end
|
51
|
-
example "
|
52
|
-
|
53
|
+
example "can be used more than once" do
|
54
|
+
parse_options('-I', 'dir_1', '-I', 'dir_2').should include(:libs => ['dir_1','dir_2'])
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
58
|
describe '--require' do
|
57
|
-
example "
|
58
|
-
|
59
|
+
example "requires files" do
|
60
|
+
parse_options('--require', 'a/path').should include(:requires => ['a/path'])
|
59
61
|
end
|
60
|
-
example "
|
61
|
-
|
62
|
+
example "can be used more than once" do
|
63
|
+
parse_options('--require', 'path/1', '--require', 'path/2').should include(:requires => ['path/1','path/2'])
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
65
|
-
describe
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
describe "--format, -f" do
|
68
|
+
it "sets :formatter" do
|
69
|
+
parse_options('--format', 'd').should include(:formatters => [['d']])
|
70
|
+
parse_options('-f', 'd').should include(:formatters => [['d']])
|
71
|
+
parse_options('-fd').should include(:formatters => [['d']])
|
70
72
|
end
|
71
73
|
|
72
|
-
example "
|
73
|
-
|
74
|
+
example "can accept a class name" do
|
75
|
+
parse_options('-fSome::Formatter::Class').should include(:formatters => [['Some::Formatter::Class']])
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
77
|
-
describe
|
78
|
-
|
79
|
-
|
80
|
-
|
79
|
+
describe "--profile, -p" do
|
80
|
+
it "sets :profile_examples => true" do
|
81
|
+
parse_options('-p').should include(:profile_examples => true)
|
82
|
+
parse_options('--profile').should include(:profile_examples => true)
|
81
83
|
end
|
82
84
|
end
|
83
85
|
|
84
|
-
describe 'line_number' do
|
85
|
-
it "
|
86
|
-
|
87
|
-
|
86
|
+
describe '--line_number' do
|
87
|
+
it "sets :line_number" do
|
88
|
+
parse_options('-l','3').should include(:line_number => '3')
|
89
|
+
parse_options('--line_number','3').should include(:line_number => '3')
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
91
|
-
describe "example" do
|
92
|
-
it "
|
93
|
-
|
94
|
-
|
93
|
+
describe "--example" do
|
94
|
+
it "sets :full_description" do
|
95
|
+
parse_options('--example','foo').should include(:full_description => /foo/)
|
96
|
+
parse_options('-e','bar').should include(:full_description => /bar/)
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
98
|
-
describe "
|
99
|
-
it "
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
it "parses dir from 'dir'" do
|
104
|
-
options_from_args("dir").should include(:files_or_directories_to_run => ["dir"])
|
105
|
-
end
|
106
|
-
|
107
|
-
it "parses dir and files from 'spec/file1_spec.rb, spec/file2_spec.rb'" do
|
108
|
-
options_from_args("dir", "spec/file1_spec.rb", "spec/file2_spec.rb").should include(:files_or_directories_to_run => ["dir", "spec/file1_spec.rb", "spec/file2_spec.rb"])
|
100
|
+
describe "--backtrace, -b" do
|
101
|
+
it "sets full_backtrace on config" do
|
102
|
+
parse_options("--backtrace").should include(:full_backtrace => true)
|
103
|
+
parse_options("-b").should include(:full_backtrace => true)
|
109
104
|
end
|
105
|
+
end
|
110
106
|
|
111
|
-
|
112
|
-
|
113
|
-
|
107
|
+
describe "--debug, -d" do
|
108
|
+
it "sets :debug => true" do
|
109
|
+
parse_options("--debug").should include(:debug => true)
|
110
|
+
parse_options("-d").should include(:debug => true)
|
114
111
|
end
|
112
|
+
end
|
115
113
|
|
116
|
-
|
117
|
-
|
118
|
-
|
114
|
+
describe "--fail-fast" do
|
115
|
+
it "defaults to false" do
|
116
|
+
parse_options[:fail_fast].should be_false
|
119
117
|
end
|
120
118
|
|
121
|
-
|
122
|
-
|
123
|
-
describe "--backtrace (-b)" do
|
124
|
-
it "sets full_backtrace on config" do
|
125
|
-
options_from_args("--backtrace").should include(:full_backtrace => true)
|
126
|
-
options_from_args("-b").should include(:full_backtrace => true)
|
119
|
+
it "sets fail_fast on config" do
|
120
|
+
parse_options("--fail-fast")[:fail_fast].should be_true
|
127
121
|
end
|
128
122
|
end
|
129
123
|
|
130
|
-
describe "--
|
131
|
-
it "sets
|
132
|
-
|
133
|
-
|
124
|
+
describe "--options" do
|
125
|
+
it "sets :custom_options_file" do
|
126
|
+
parse_options(*%w[-O my.opts]).should include(:custom_options_file => "my.opts")
|
127
|
+
parse_options(*%w[--options my.opts]).should include(:custom_options_file => "my.opts")
|
134
128
|
end
|
135
129
|
end
|
136
130
|
|
137
|
-
describe "--drb
|
131
|
+
describe "--drb, -X" do
|
138
132
|
context "combined with --debug" do
|
139
133
|
it "turns off the debugger if --drb is specified first" do
|
140
134
|
config_options_object("--drb", "--debug").drb_argv.should_not include("--debug")
|
@@ -170,8 +164,32 @@ describe RSpec::Core::ConfigurationOptions do
|
|
170
164
|
end
|
171
165
|
end
|
172
166
|
|
167
|
+
describe "files_or_directories_to_run" do
|
168
|
+
it "parses files from '-c file.rb dir/file.rb'" do
|
169
|
+
parse_options("-c", "file.rb", "dir/file.rb").should include(:files_or_directories_to_run => ["file.rb", "dir/file.rb"])
|
170
|
+
end
|
171
|
+
|
172
|
+
it "parses dir from 'dir'" do
|
173
|
+
parse_options("dir").should include(:files_or_directories_to_run => ["dir"])
|
174
|
+
end
|
175
|
+
|
176
|
+
it "parses dir and files from 'spec/file1_spec.rb, spec/file2_spec.rb'" do
|
177
|
+
parse_options("dir", "spec/file1_spec.rb", "spec/file2_spec.rb").should include(:files_or_directories_to_run => ["dir", "spec/file1_spec.rb", "spec/file2_spec.rb"])
|
178
|
+
end
|
179
|
+
|
180
|
+
it "provides no files or directories if spec directory does not exist" do
|
181
|
+
FileTest.stub(:directory?).with("spec").and_return false
|
182
|
+
parse_options().should include(:files_or_directories_to_run => [])
|
183
|
+
end
|
184
|
+
|
185
|
+
it "parses dir and files from 'spec/file1_spec.rb, spec/file2_spec.rb'" do
|
186
|
+
parse_options("dir", "spec/file1_spec.rb", "spec/file2_spec.rb").should include(:files_or_directories_to_run => ["dir", "spec/file1_spec.rb", "spec/file2_spec.rb"])
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
173
192
|
# TODO ensure all options are output
|
174
|
-
# TODO check if we need to spec that the short options are "expanded" ("-v" becomes "--version" currently)
|
175
193
|
describe "#drb_argv" do
|
176
194
|
it "preserves extra arguments" do
|
177
195
|
File.stub(:exist?) { false }
|
@@ -182,10 +200,14 @@ describe RSpec::Core::ConfigurationOptions do
|
|
182
200
|
config_options_object(*%w[--fail-fast]).drb_argv.should include("--fail-fast")
|
183
201
|
end
|
184
202
|
|
203
|
+
it "includes --options" do
|
204
|
+
config_options_object(*%w[--options custom.opts]).drb_argv.should include("--options", "custom.opts")
|
205
|
+
end
|
206
|
+
|
185
207
|
context "--drb specified in ARGV" do
|
186
208
|
it "renders all the original arguments except --drb" do
|
187
209
|
config_options_object(*%w[ --drb --color --format s --line_number 1 --example pattern --profile --backtrace -I path/a -I path/b --require path/c --require path/d]).
|
188
|
-
drb_argv.should eq(%w[ --color --profile --backtrace --
|
210
|
+
drb_argv.should eq(%w[ --color --profile --backtrace --line_number 1 --example pattern --format s -I path/a -I path/b --require path/c --require path/d])
|
189
211
|
end
|
190
212
|
end
|
191
213
|
|
@@ -194,7 +216,7 @@ describe RSpec::Core::ConfigurationOptions do
|
|
194
216
|
File.stub(:exist?) { true }
|
195
217
|
IO.stub(:read) { "--drb --color" }
|
196
218
|
config_options_object(*%w[ --tty --format s --line_number 1 --example pattern --profile --backtrace ]).
|
197
|
-
drb_argv.should eq(%w[ --color --profile --backtrace --tty --
|
219
|
+
drb_argv.should eq(%w[ --color --profile --backtrace --tty --line_number 1 --example pattern --format s])
|
198
220
|
end
|
199
221
|
end
|
200
222
|
|
@@ -203,7 +225,7 @@ describe RSpec::Core::ConfigurationOptions do
|
|
203
225
|
File.stub(:exist?) { true }
|
204
226
|
IO.stub(:read) { "--drb --color" }
|
205
227
|
config_options_object(*%w[ --drb --format s --line_number 1 --example pattern --profile --backtrace]).
|
206
|
-
drb_argv.should eq(%w[ --color --profile --backtrace --
|
228
|
+
drb_argv.should eq(%w[ --color --profile --backtrace --line_number 1 --example pattern --format s])
|
207
229
|
end
|
208
230
|
end
|
209
231
|
|
@@ -212,102 +234,76 @@ describe RSpec::Core::ConfigurationOptions do
|
|
212
234
|
File.stub(:exist?) { true }
|
213
235
|
IO.stub(:read) { "--drb --color" }
|
214
236
|
config_options_object(*%w[ --drb --format s --line_number 1 --example pattern --profile --backtrace]).
|
215
|
-
drb_argv.should eq(%w[ --color --profile --backtrace --
|
237
|
+
drb_argv.should eq(%w[ --color --profile --backtrace --line_number 1 --example pattern --format s ])
|
216
238
|
end
|
217
239
|
end
|
218
240
|
end
|
219
241
|
|
220
|
-
describe "
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
end
|
225
|
-
|
226
|
-
describe "options file (override)" do
|
227
|
-
let(:config) { OpenStruct.new }
|
228
|
-
|
229
|
-
it "loads automatically" do
|
230
|
-
File.stub(:exist?) { true }
|
231
|
-
IO.stub(:read) { "--format doc" }
|
232
|
-
|
233
|
-
config_options = RSpec::Core::ConfigurationOptions.new([])
|
234
|
-
config_options.parse_options
|
235
|
-
config_options.configure(config)
|
236
|
-
config.formatter.should == 'doc'
|
237
|
-
end
|
238
|
-
|
239
|
-
it "merges options from the global and local .rspec and the command line" do
|
240
|
-
File.stub(:exist?){ true }
|
241
|
-
IO.stub(:read) do |path|
|
242
|
-
case path
|
243
|
-
when ".rspec"
|
244
|
-
"--format documentation"
|
245
|
-
when /\.rspec/
|
246
|
-
"--line 37"
|
247
|
-
else
|
248
|
-
raise "Unexpected path: #{path}"
|
249
|
-
end
|
250
|
-
end
|
251
|
-
config_options = RSpec::Core::ConfigurationOptions.new(["--no-color"])
|
252
|
-
config_options.parse_options
|
253
|
-
|
254
|
-
config_options.configure(config)
|
255
|
-
|
256
|
-
config.formatter.should == "documentation"
|
257
|
-
config.line_number.should == "37"
|
258
|
-
config.color_enabled.should be_false
|
259
|
-
end
|
260
|
-
|
261
|
-
it "prefers local options over global" do
|
262
|
-
File.stub(:exist?){ true }
|
263
|
-
IO.stub(:read) do |path|
|
264
|
-
case path
|
265
|
-
when ".rspec"
|
266
|
-
"--format local"
|
267
|
-
when /\.rspec/
|
268
|
-
"--format global"
|
269
|
-
else
|
270
|
-
raise "Unexpected path: #{path}"
|
271
|
-
end
|
272
|
-
end
|
273
|
-
config_options = RSpec::Core::ConfigurationOptions.new([])
|
274
|
-
config_options.parse_options
|
275
|
-
|
276
|
-
config_options.configure(config)
|
242
|
+
describe "sources: ~/.rspec, ./.rspec, custom, SPEC_OPTS, and CLI" do
|
243
|
+
let(:local_options_file) { File.join(Dir.tmpdir, ".rspec-local") }
|
244
|
+
let(:global_options_file) { File.join(Dir.tmpdir, ".rspec-global") }
|
245
|
+
let(:custom_options_file) { File.join(Dir.tmpdir, "custom.options") }
|
277
246
|
|
278
|
-
|
247
|
+
before do
|
248
|
+
@orig_spec_opts = ENV["SPEC_OPTS"]
|
249
|
+
@orig_global_options_file = RSpec::Core::ConfigurationOptions::GLOBAL_OPTIONS_FILE
|
250
|
+
@orig_local_options_file = RSpec::Core::ConfigurationOptions::LOCAL_OPTIONS_FILE
|
251
|
+
RSpec::Core::ConfigurationOptions::__send__ :remove_const, :GLOBAL_OPTIONS_FILE
|
252
|
+
RSpec::Core::ConfigurationOptions::__send__ :remove_const, :LOCAL_OPTIONS_FILE
|
253
|
+
RSpec::Core::ConfigurationOptions::GLOBAL_OPTIONS_FILE = global_options_file
|
254
|
+
RSpec::Core::ConfigurationOptions::LOCAL_OPTIONS_FILE = local_options_file
|
255
|
+
FileUtils.rm local_options_file if File.exist? local_options_file
|
256
|
+
FileUtils.rm global_options_file if File.exist? global_options_file
|
257
|
+
FileUtils.rm custom_options_file if File.exist? custom_options_file
|
279
258
|
end
|
280
259
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
260
|
+
after do
|
261
|
+
ENV["SPEC_OPTS"] = @orig_spec_opts
|
262
|
+
RSpec::Core::ConfigurationOptions::__send__ :remove_const, :GLOBAL_OPTIONS_FILE
|
263
|
+
RSpec::Core::ConfigurationOptions::__send__ :remove_const, :LOCAL_OPTIONS_FILE
|
264
|
+
RSpec::Core::ConfigurationOptions::GLOBAL_OPTIONS_FILE = @orig_global_options_file
|
265
|
+
RSpec::Core::ConfigurationOptions::LOCAL_OPTIONS_FILE = @orig_local_options_file
|
266
|
+
end
|
287
267
|
|
288
|
-
|
268
|
+
def write_options(scope, options)
|
269
|
+
File.open(send("#{scope}_options_file"), 'w') { |f| f.write(options) }
|
289
270
|
end
|
290
271
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
272
|
+
it "merges global, local, SPEC_OPTS, and CLI" do
|
273
|
+
write_options(:global, "--color")
|
274
|
+
write_options(:local, "--line 37")
|
275
|
+
ENV["SPEC_OPTS"] = "--debug"
|
276
|
+
options = parse_options("--drb")
|
277
|
+
options[:color_enabled].should be_true
|
278
|
+
options[:line_number].should eq("37")
|
279
|
+
options[:debug].should be_true
|
280
|
+
options[:drb].should be_true
|
281
|
+
end
|
295
282
|
|
296
|
-
|
297
|
-
|
298
|
-
|
283
|
+
it "prefers CLI over SPEC_OPTS" do
|
284
|
+
ENV["SPEC_OPTS"] = "--format spec_opts"
|
285
|
+
parse_options("--format", "cli")[:formatters].should eq([['cli']])
|
286
|
+
end
|
299
287
|
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
288
|
+
it "prefers SPEC_OPTS over file options" do
|
289
|
+
write_options(:local, "--format local")
|
290
|
+
write_options(:global, "--format global")
|
291
|
+
ENV["SPEC_OPTS"] = "--format spec_opts"
|
292
|
+
parse_options[:formatters].should eq([['spec_opts']])
|
293
|
+
end
|
304
294
|
|
305
|
-
|
306
|
-
|
295
|
+
it "prefers local file options over global" do
|
296
|
+
write_options(:local, "--format local")
|
297
|
+
write_options(:global, "--format global")
|
298
|
+
parse_options[:formatters].should eq([['local']])
|
299
|
+
end
|
307
300
|
|
308
|
-
|
301
|
+
context "with custom options file" do
|
302
|
+
it "ignores local and global options files" do
|
303
|
+
write_options(:local, "--color")
|
304
|
+
write_options(:global, "--color")
|
305
|
+
parse_options("-O", custom_options_file)[:color_enabled].should be_false
|
309
306
|
end
|
310
307
|
end
|
311
308
|
end
|
312
309
|
end
|
313
|
-
|