rspec-core 2.99.0.beta2 → 2.99.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Changelog.md +122 -43
- data/features/command_line/line_number_option.feature +6 -11
- data/features/configuration/read_options_from_file.feature +2 -2
- data/features/expectation_framework_integration/configure_expectation_framework.feature +120 -25
- data/lib/autotest/discover.rb +10 -1
- data/lib/autotest/rspec2.rb +1 -1
- data/lib/rspec/core/command_line.rb +16 -5
- data/lib/rspec/core/configuration.rb +151 -119
- data/lib/rspec/core/deprecated_mutable_array_proxy.rb +32 -0
- data/lib/rspec/core/example.rb +3 -1
- data/lib/rspec/core/example_group.rb +174 -125
- data/lib/rspec/core/filter_manager.rb +48 -10
- data/lib/rspec/core/formatters.rb +137 -0
- data/lib/rspec/core/formatters/base_text_formatter.rb +25 -29
- data/lib/rspec/core/formatters/console_codes.rb +42 -0
- data/lib/rspec/core/formatters/deprecation_formatter.rb +14 -5
- data/lib/rspec/core/formatters/helpers.rb +1 -1
- data/lib/rspec/core/memoized_helpers.rb +2 -1
- data/lib/rspec/core/metadata.rb +63 -1
- data/lib/rspec/core/minitest_assertions_adapter.rb +28 -0
- data/lib/rspec/core/option_parser.rb +20 -1
- data/lib/rspec/core/pending.rb +26 -4
- data/lib/rspec/core/reporter.rb +1 -1
- data/lib/rspec/core/runner.rb +2 -2
- data/lib/rspec/core/shared_example_group.rb +11 -4
- data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/world.rb +2 -2
- data/spec/autotest/discover_spec.rb +38 -8
- data/spec/rspec/core/command_line_spec.rb +47 -29
- data/spec/rspec/core/configuration_options_spec.rb +1 -1
- data/spec/rspec/core/configuration_spec.rb +223 -37
- data/spec/rspec/core/example_group_spec.rb +116 -6
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +24 -4
- data/spec/rspec/core/formatters/console_codes_spec.rb +50 -0
- data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +20 -3
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +1 -0
- data/spec/rspec/core/formatters/html_formatted.html +3 -4
- data/spec/rspec/core/formatters/html_formatter_spec.rb +10 -4
- data/spec/rspec/core/formatters/text_mate_formatted.html +3 -4
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +9 -3
- data/spec/rspec/core/hooks_filtering_spec.rb +5 -5
- data/spec/rspec/core/memoized_helpers_spec.rb +38 -0
- data/spec/rspec/core/metadata_spec.rb +24 -1
- data/spec/rspec/core/option_parser_spec.rb +39 -2
- data/spec/rspec/core/pending_example_spec.rb +14 -0
- data/spec/rspec/core/pending_spec.rb +27 -0
- data/spec/rspec/core/runner_spec.rb +3 -3
- data/spec/rspec/core/shared_context_spec.rb +1 -1
- data/spec/rspec/core/shared_example_group_spec.rb +18 -0
- data/spec/support/helper_methods.rb +4 -0
- metadata +105 -106
@@ -27,17 +27,13 @@ Feature: --line_number option
|
|
27
27
|
|
28
28
|
end
|
29
29
|
"""
|
30
|
-
When I run `rspec example_spec.rb --line_number 5
|
30
|
+
When I run `rspec example_spec.rb --line_number 5`
|
31
31
|
Then the examples should all pass
|
32
|
-
And the output should contain "
|
33
|
-
But the output should not contain "should be < 10"
|
34
|
-
And the output should not contain "should be 3*3"
|
32
|
+
And the output should contain "1 example"
|
35
33
|
|
36
|
-
When I run `rspec example_spec.rb --line_number 5 --line_number 9
|
34
|
+
When I run `rspec example_spec.rb --line_number 5 --line_number 9`
|
37
35
|
Then the examples should all pass
|
38
|
-
And the output should contain "
|
39
|
-
And the output should contain "should be < 10"
|
40
|
-
But the output should not contain "should be 3*3"
|
36
|
+
And the output should contain "2 examples"
|
41
37
|
|
42
38
|
Scenario: one liner
|
43
39
|
Given a file named "example_spec.rb" with:
|
@@ -52,7 +48,6 @@ Feature: --line_number option
|
|
52
48
|
|
53
49
|
end
|
54
50
|
"""
|
55
|
-
When I run `rspec example_spec.rb --line_number 5
|
51
|
+
When I run `rspec example_spec.rb --line_number 5`
|
56
52
|
Then the examples should all pass
|
57
|
-
|
58
|
-
But the output should not contain "should be < 10"
|
53
|
+
And the output should contain "1 example"
|
@@ -19,7 +19,7 @@ Feature: read command line configuration options from files
|
|
19
19
|
"""
|
20
20
|
And a file named "spec/example_spec.rb" with:
|
21
21
|
"""ruby
|
22
|
-
describe "
|
22
|
+
describe "color" do
|
23
23
|
context "when set with RSpec.configure" do
|
24
24
|
before do
|
25
25
|
# color is disabled for non-tty output, so stub the output stream
|
@@ -66,7 +66,7 @@ Feature: read command line configuration options from files
|
|
66
66
|
"""ruby
|
67
67
|
describe "custom options file" do
|
68
68
|
it "causes .rspec to be ignored" do
|
69
|
-
RSpec.configuration.
|
69
|
+
RSpec.configuration.color.should be_falsey
|
70
70
|
end
|
71
71
|
end
|
72
72
|
"""
|
@@ -4,16 +4,16 @@ Feature: configure expectation framework
|
|
4
4
|
desired outcomes. You can also configure RSpec to use:
|
5
5
|
|
6
6
|
* rspec/expectations (explicitly)
|
7
|
-
* stdlib assertions
|
8
|
-
|
9
|
-
|
10
|
-
*
|
7
|
+
* stdlib assertions **DEPRECATED: Use test/unit or minitest explicitly**
|
8
|
+
* test/unit assertions
|
9
|
+
* minitest assertions
|
10
|
+
* any combination of the above libraries
|
11
11
|
|
12
|
-
Note that when you do not use rspec-expectations, you must explicitly
|
13
|
-
|
14
|
-
|
12
|
+
Note that when you do not use rspec-expectations, you must explicitly provide
|
13
|
+
a description to every example. You cannot rely on the generated descriptions
|
14
|
+
provided by rspec-expectations.
|
15
15
|
|
16
|
-
Scenario: rspec-expectations
|
16
|
+
Scenario: Default configuration uses rspec-expectations
|
17
17
|
Given a file named "example_spec.rb" with:
|
18
18
|
"""ruby
|
19
19
|
RSpec::Matchers.define :be_a_multiple_of do |factor|
|
@@ -29,7 +29,7 @@ Feature: configure expectation framework
|
|
29
29
|
When I run `rspec example_spec.rb`
|
30
30
|
Then the examples should all pass
|
31
31
|
|
32
|
-
Scenario:
|
32
|
+
Scenario: Configure rspec-expectations (explicitly)
|
33
33
|
Given a file named "example_spec.rb" with:
|
34
34
|
"""ruby
|
35
35
|
RSpec.configure do |config|
|
@@ -45,7 +45,8 @@ Feature: configure expectation framework
|
|
45
45
|
When I run `rspec example_spec.rb`
|
46
46
|
Then the examples should all pass
|
47
47
|
|
48
|
-
|
48
|
+
@deprecated
|
49
|
+
Scenario: Configure 'stdlib' assertions
|
49
50
|
Given a file named "example_spec.rb" with:
|
50
51
|
"""ruby
|
51
52
|
RSpec.configure do |config|
|
@@ -58,45 +59,139 @@ Feature: configure expectation framework
|
|
58
59
|
end
|
59
60
|
|
60
61
|
specify { assert 5 < 6 }
|
62
|
+
|
63
|
+
it "is greater than 6 (no it isn't!)" do
|
64
|
+
assert 5 > 6, "errantly expected 5 to be greater than 5"
|
65
|
+
end
|
61
66
|
end
|
62
67
|
"""
|
63
68
|
When I run `rspec example_spec.rb`
|
64
|
-
Then the output should
|
69
|
+
Then the output should match:
|
70
|
+
"""
|
71
|
+
(Test::Unit::AssertionFailedError|Mini(T|t)est::Assertion):
|
72
|
+
errantly expected 5 to be greater than 5
|
73
|
+
"""
|
74
|
+
And the output should contain "3 examples, 1 failure"
|
75
|
+
And the output should contain ":stdlib is deprecated. Use :test_unit or :minitest instead"
|
65
76
|
|
66
|
-
Scenario:
|
77
|
+
Scenario: Configure test/unit assertions
|
67
78
|
Given a file named "example_spec.rb" with:
|
68
79
|
"""ruby
|
69
80
|
RSpec.configure do |config|
|
70
|
-
config.expect_with :
|
81
|
+
config.expect_with :test_unit
|
71
82
|
end
|
72
83
|
|
73
|
-
describe
|
74
|
-
it "is
|
75
|
-
|
84
|
+
RSpec.describe [1] do
|
85
|
+
it "is equal to [1]" do
|
86
|
+
assert_equal [1], [1], "expected [1] to equal [1]"
|
76
87
|
end
|
77
88
|
|
78
|
-
specify {
|
89
|
+
specify { assert_not_equal [1], [] }
|
90
|
+
|
91
|
+
it "is equal to [2] (intentional failure)" do
|
92
|
+
assert [1] == [2], "errantly expected [2] to equal [1]"
|
93
|
+
end
|
79
94
|
end
|
80
95
|
"""
|
81
96
|
When I run `rspec example_spec.rb`
|
82
|
-
Then the output should
|
97
|
+
Then the output should match:
|
98
|
+
"""
|
99
|
+
(Test::Unit::AssertionFailedError|Mini(T|t)est::Assertion):
|
100
|
+
errantly expected \[2\] to equal \[1\]
|
101
|
+
"""
|
102
|
+
And the output should contain "3 examples, 1 failure"
|
83
103
|
|
84
|
-
Scenario:
|
104
|
+
Scenario: Configure minitest assertions
|
85
105
|
Given a file named "example_spec.rb" with:
|
86
106
|
"""ruby
|
87
107
|
RSpec.configure do |config|
|
88
|
-
config.expect_with :
|
108
|
+
config.expect_with :minitest
|
89
109
|
end
|
90
110
|
|
91
|
-
describe
|
92
|
-
it "is
|
93
|
-
|
111
|
+
RSpec.describe "Object identity" do
|
112
|
+
it "the an object is the same as itself" do
|
113
|
+
x = [1]
|
114
|
+
assert_same x, x, "expected x to be the same x"
|
94
115
|
end
|
95
116
|
|
96
|
-
|
97
|
-
|
117
|
+
specify { refute_same [1], [1] }
|
118
|
+
|
119
|
+
it "is empty (intentional failure)" do
|
120
|
+
assert_empty [1], "errantly expected [1] to be empty"
|
98
121
|
end
|
99
122
|
end
|
100
123
|
"""
|
124
|
+
When I run `rspec -b example_spec.rb`
|
125
|
+
Then the output should match:
|
126
|
+
"""
|
127
|
+
MiniT|test::Assertion:
|
128
|
+
errantly expected \[1\] to be empty
|
129
|
+
"""
|
130
|
+
And the output should contain "3 examples, 1 failure"
|
131
|
+
And the output should not contain "Warning: you should require 'minitest/autorun' instead."
|
132
|
+
|
133
|
+
Scenario: Configure rspec/expectations AND test/unit assertions
|
134
|
+
Given a file named "example_spec.rb" with:
|
135
|
+
"""ruby
|
136
|
+
RSpec.configure do |config|
|
137
|
+
config.expect_with :rspec, :test_unit
|
138
|
+
end
|
139
|
+
|
140
|
+
RSpec.describe [1] do
|
141
|
+
it "is equal to [1]" do
|
142
|
+
assert_equal [1], [1], "expected [1] to equal [1]"
|
143
|
+
end
|
144
|
+
|
145
|
+
it "matches array [1]" do
|
146
|
+
is_expected.to match_array([1])
|
147
|
+
end
|
148
|
+
end
|
149
|
+
"""
|
150
|
+
When I run `rspec example_spec.rb`
|
151
|
+
Then the examples should all pass
|
152
|
+
|
153
|
+
Scenario: Configure rspec/expecations AND minitest assertions
|
154
|
+
Given a file named "example_spec.rb" with:
|
155
|
+
"""ruby
|
156
|
+
RSpec.configure do |config|
|
157
|
+
config.expect_with :rspec, :minitest
|
158
|
+
end
|
159
|
+
|
160
|
+
RSpec.describe "Object identity" do
|
161
|
+
it "two arrays are not the same object" do
|
162
|
+
refute_same [1], [1]
|
163
|
+
end
|
164
|
+
|
165
|
+
it "an array is itself" do
|
166
|
+
array = [1]
|
167
|
+
expect(array).to be array
|
168
|
+
end
|
169
|
+
end
|
170
|
+
"""
|
171
|
+
When I run `rspec example_spec.rb`
|
172
|
+
Then the examples should all pass
|
173
|
+
|
174
|
+
Scenario: Configure test/unit and minitest assertions
|
175
|
+
Given a file named "example_spec.rb" with:
|
176
|
+
"""ruby
|
177
|
+
RSpec.configure do |config|
|
178
|
+
config.expect_with :test_unit, :minitest
|
179
|
+
end
|
180
|
+
|
181
|
+
RSpec.describe [1] do
|
182
|
+
it "is equal to [1]" do
|
183
|
+
assert_equal [1], [1], "expected [1] to equal [1]"
|
184
|
+
end
|
185
|
+
|
186
|
+
specify { assert_not_equal [1], [] }
|
187
|
+
|
188
|
+
it "the an object is the same as itself" do
|
189
|
+
x = [1]
|
190
|
+
assert_same x, x, "expected x to be the same x"
|
191
|
+
end
|
192
|
+
|
193
|
+
specify { refute_same [1], [1] }
|
194
|
+
end
|
195
|
+
"""
|
101
196
|
When I run `rspec example_spec.rb`
|
102
197
|
Then the examples should all pass
|
data/lib/autotest/discover.rb
CHANGED
@@ -1 +1,10 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
# try to load rspec/autotest so we can check if the constant is defined below.
|
3
|
+
require 'rspec/autotest'
|
4
|
+
rescue LoadError
|
5
|
+
# ignore. We print a deprecation warning later.
|
6
|
+
end
|
7
|
+
|
8
|
+
if File.exist?("./.rspec") && !defined?(::RSpec::Autotest)
|
9
|
+
Autotest.add_discovery { "rspec2" }
|
10
|
+
end
|
data/lib/autotest/rspec2.rb
CHANGED
@@ -73,5 +73,5 @@ rescue LoadError
|
|
73
73
|
File.exist?('./Gemfile')
|
74
74
|
end
|
75
75
|
end
|
76
|
-
Autotest.add_hook(:ran_command) { warn "\n\e[
|
76
|
+
Autotest.add_hook(:ran_command) { warn "\n\e[31mrspec-core's built in autotest support is deprecated and will be removed in RSpec 3. Please switch to the rspec-autotest gem.\e[0m" }
|
77
77
|
end
|
@@ -1,11 +1,7 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Core
|
3
|
-
class
|
3
|
+
class Runner
|
4
4
|
def initialize(options, configuration=RSpec::configuration, world=RSpec::world)
|
5
|
-
if Array === options
|
6
|
-
options = ConfigurationOptions.new(options)
|
7
|
-
options.parse_options
|
8
|
-
end
|
9
5
|
@options = options
|
10
6
|
@configuration = configuration
|
11
7
|
@world = world
|
@@ -32,5 +28,20 @@ module RSpec
|
|
32
28
|
end
|
33
29
|
end
|
34
30
|
end
|
31
|
+
|
32
|
+
class CommandLine < Runner
|
33
|
+
def initialize(options, configuration=RSpec.configuration, world=RSpec.world)
|
34
|
+
if Array === options
|
35
|
+
RSpec.deprecate("Instantiating a `RSpec::Core::CommandLine` with an array of options",
|
36
|
+
:replacement => "Instantiate a `RSpec::Core::Runner` with a `RSpec::Core::ConfigurationOptions` instance")
|
37
|
+
options = ConfigurationOptions.new(options)
|
38
|
+
options.parse_options
|
39
|
+
else
|
40
|
+
RSpec.deprecate("`RSpec::Core::CommandLine`", :replacement => "`RSpec::Core::Runner`")
|
41
|
+
end
|
42
|
+
|
43
|
+
super
|
44
|
+
end
|
45
|
+
end
|
35
46
|
end
|
36
47
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'rspec/core/backtrace_cleaner'
|
3
3
|
require 'rspec/core/ruby_project'
|
4
|
+
require 'rspec/core/deprecated_mutable_array_proxy'
|
4
5
|
require 'rspec/core/formatters/deprecation_formatter'
|
5
6
|
|
6
7
|
module RSpec
|
@@ -96,7 +97,18 @@ module RSpec
|
|
96
97
|
add_setting :error_stream
|
97
98
|
|
98
99
|
# Default: `$stderr`.
|
99
|
-
|
100
|
+
define_reader :deprecation_stream
|
101
|
+
def deprecation_stream=(value)
|
102
|
+
if @reporter && !value.equal?(@deprecation_stream)
|
103
|
+
warn "RSpec's reporter has already been initialized with " +
|
104
|
+
"#{deprecation_stream.inspect} as the deprecation stream, so your change to "+
|
105
|
+
"`deprecation_stream` will be ignored. You should configure it earlier for " +
|
106
|
+
"it to take effect, or use the `--deprecation-out` CLI option. " +
|
107
|
+
"(Called from #{CallerFilter.first_non_rspec_line})"
|
108
|
+
else
|
109
|
+
@deprecation_stream = value
|
110
|
+
end
|
111
|
+
end
|
100
112
|
|
101
113
|
# Clean up and exit after the first failure (default: `false`).
|
102
114
|
add_setting :fail_fast
|
@@ -149,7 +161,13 @@ module RSpec
|
|
149
161
|
end
|
150
162
|
|
151
163
|
# Load files matching this pattern (default: `'**/*_spec.rb'`)
|
152
|
-
add_setting :pattern
|
164
|
+
add_setting :pattern
|
165
|
+
|
166
|
+
def filename_pattern
|
167
|
+
RSpec.deprecate "`RSpec::Core::Configuration#filename_pattern`",
|
168
|
+
:replacement => "`RSpec::Core::Configuration#pattern`"
|
169
|
+
pattern
|
170
|
+
end
|
153
171
|
|
154
172
|
def pattern= value
|
155
173
|
if @spec_files_loaded
|
@@ -157,7 +175,13 @@ module RSpec
|
|
157
175
|
end
|
158
176
|
@pattern = value
|
159
177
|
end
|
160
|
-
|
178
|
+
|
179
|
+
def filename_pattern=(value)
|
180
|
+
RSpec.deprecate "`RSpec::Core::Configuration#filename_pattern=`",
|
181
|
+
:replacement => "`RSpec::Core::Configuration#pattern=`"
|
182
|
+
self.pattern = value
|
183
|
+
end
|
184
|
+
|
161
185
|
|
162
186
|
# Report the times for the slowest examples (default: `false`).
|
163
187
|
# Use this to specify the number of examples to include in the profile.
|
@@ -247,21 +271,26 @@ module RSpec
|
|
247
271
|
# @private
|
248
272
|
attr_accessor :filter_manager
|
249
273
|
|
250
|
-
attr_reader :
|
274
|
+
attr_reader :backtrace_formatter
|
275
|
+
|
276
|
+
def backtrace_cleaner
|
277
|
+
RSpec.deprecate "`RSpec::Core::Configuration#backtrace_cleaner`",
|
278
|
+
:replacement => "`RSpec::Core::Configuration#backtrace_formatter`"
|
279
|
+
@backtrace_formatter
|
280
|
+
end
|
251
281
|
|
252
282
|
def initialize
|
253
283
|
@expectation_frameworks = []
|
254
284
|
@include_or_extend_modules = []
|
255
285
|
@mock_framework = nil
|
256
286
|
@files_to_run = []
|
257
|
-
@formatters = []
|
258
287
|
@color = false
|
259
288
|
@order = nil
|
260
289
|
@pattern = '**/*_spec.rb'
|
261
290
|
@failure_exit_code = 1
|
262
291
|
@spec_files_loaded = false
|
263
292
|
|
264
|
-
@
|
293
|
+
@backtrace_formatter = BacktraceCleaner.new
|
265
294
|
|
266
295
|
@default_path = 'spec'
|
267
296
|
@deprecation_stream = $stderr
|
@@ -280,6 +309,7 @@ module RSpec
|
|
280
309
|
@profile_examples = false
|
281
310
|
@requires = []
|
282
311
|
@libs = []
|
312
|
+
@show_failures_in_pending_blocks = false
|
283
313
|
end
|
284
314
|
|
285
315
|
# @private
|
@@ -299,7 +329,7 @@ module RSpec
|
|
299
329
|
def reset
|
300
330
|
@spec_files_loaded = false
|
301
331
|
@reporter = nil
|
302
|
-
@
|
332
|
+
@formatter_loader = nil
|
303
333
|
end
|
304
334
|
|
305
335
|
# @overload add_setting(name)
|
@@ -370,13 +400,13 @@ module RSpec
|
|
370
400
|
def backtrace_clean_patterns
|
371
401
|
RSpec.deprecate("RSpec::Core::Configuration#backtrace_clean_patterns",
|
372
402
|
:replacement => "RSpec::Core::Configuration#backtrace_exclusion_patterns")
|
373
|
-
@
|
403
|
+
@backtrace_formatter.exclusion_patterns
|
374
404
|
end
|
375
405
|
|
376
406
|
def backtrace_clean_patterns=(patterns)
|
377
407
|
RSpec.deprecate("RSpec::Core::Configuration#backtrace_clean_patterns",
|
378
408
|
:replacement => "RSpec::Core::Configuration#backtrace_exclusion_patterns")
|
379
|
-
@
|
409
|
+
@backtrace_formatter.exclusion_patterns = patterns
|
380
410
|
end
|
381
411
|
|
382
412
|
# The patterns to always include to backtraces.
|
@@ -387,11 +417,11 @@ module RSpec
|
|
387
417
|
# One can replace the list by using the setter or modify it through the
|
388
418
|
# getter
|
389
419
|
def backtrace_inclusion_patterns
|
390
|
-
@
|
420
|
+
@backtrace_formatter.inclusion_patterns
|
391
421
|
end
|
392
422
|
|
393
423
|
def backtrace_inclusion_patterns=(patterns)
|
394
|
-
@
|
424
|
+
@backtrace_formatter.inclusion_patterns = patterns
|
395
425
|
end
|
396
426
|
|
397
427
|
# The patterns to discard from backtraces.
|
@@ -405,11 +435,11 @@ module RSpec
|
|
405
435
|
# `--backtrace`on the command line, in a `.rspec` file, or in the
|
406
436
|
# `rspec_options` attribute of RSpec's rake task.
|
407
437
|
def backtrace_exclusion_patterns
|
408
|
-
@
|
438
|
+
@backtrace_formatter.exclusion_patterns
|
409
439
|
end
|
410
440
|
|
411
441
|
def backtrace_exclusion_patterns=(patterns)
|
412
|
-
@
|
442
|
+
@backtrace_formatter.exclusion_patterns = patterns
|
413
443
|
end
|
414
444
|
|
415
445
|
# Sets the mock framework adapter module.
|
@@ -496,16 +526,17 @@ module RSpec
|
|
496
526
|
# Sets the expectation framework module(s) to be included in each example
|
497
527
|
# group.
|
498
528
|
#
|
499
|
-
# `frameworks` can be `:rspec`, `:
|
500
|
-
# combination thereof:
|
529
|
+
# `frameworks` can be `:rspec`, `:test_unit`, `:minitest`, a custom
|
530
|
+
# module, or any combination thereof:
|
501
531
|
#
|
502
532
|
# config.expect_with :rspec
|
503
|
-
# config.expect_with :
|
504
|
-
# config.expect_with :
|
533
|
+
# config.expect_with :test_unit
|
534
|
+
# config.expect_with :minitest
|
535
|
+
# config.expect_with :rspec, :minitest
|
505
536
|
# config.expect_with OtherExpectationFramework
|
506
537
|
#
|
507
|
-
# RSpec will translate `:rspec
|
508
|
-
# modules.
|
538
|
+
# RSpec will translate `:rspec`, `:minitest`, and `:test_unit` into the
|
539
|
+
# appropriate modules.
|
509
540
|
#
|
510
541
|
# ## Configuration
|
511
542
|
#
|
@@ -525,8 +556,15 @@ module RSpec
|
|
525
556
|
self.expecting_with_rspec = true
|
526
557
|
::RSpec::Matchers
|
527
558
|
when :stdlib
|
559
|
+
RSpec.deprecate ':stdlib', :replacement => ":test_unit or :minitest"
|
528
560
|
require 'test/unit/assertions'
|
529
561
|
::Test::Unit::Assertions
|
562
|
+
when :test_unit
|
563
|
+
require 'rspec/core/test_unit_assertions_adapter'
|
564
|
+
::RSpec::Core::TestUnitAssertionsAdapter
|
565
|
+
when :minitest
|
566
|
+
require 'rspec/core/minitest_assertions_adapter'
|
567
|
+
::RSpec::Core::MinitestAssertionsAdapter
|
530
568
|
else
|
531
569
|
raise ArgumentError, "#{framework.inspect} is not supported"
|
532
570
|
end
|
@@ -546,19 +584,33 @@ module RSpec
|
|
546
584
|
end
|
547
585
|
|
548
586
|
def full_backtrace?
|
549
|
-
@
|
587
|
+
@backtrace_formatter.full_backtrace?
|
550
588
|
end
|
551
589
|
|
552
590
|
def full_backtrace=(true_or_false)
|
553
|
-
@
|
554
|
-
end
|
591
|
+
@backtrace_formatter.full_backtrace = true_or_false
|
592
|
+
end
|
593
|
+
|
594
|
+
NoArgument = "No such argument"
|
595
|
+
def color(output = NoArgument)
|
596
|
+
if output == NoArgument
|
597
|
+
output = output_stream
|
598
|
+
if !output_to_tty?(output) && value_for(:color, @color)
|
599
|
+
RSpec.warn_deprecation <<-MSG.gsub(/\s+|/,'')
|
600
|
+
| Calling `RSpec::Core::Configuration#color` in RSpec 3 will
|
601
|
+
| return the value of the configuration setting, in RSpec 2
|
602
|
+
| this value is `false` as your output doesn't support color.
|
603
|
+
| Use `RSpec::Core::Configuration#color_enabled?` if you depend
|
604
|
+
| on this behavior.
|
605
|
+
| Called from #{CallerFilter.first_non_rspec_line}.
|
606
|
+
MSG
|
607
|
+
end
|
608
|
+
else
|
609
|
+
RSpec.deprecate '`RSpec::Core::Configuration#color(output)`',
|
610
|
+
:replacement => '`RSpec::Core::Configuration#color_enabled?(output)`'
|
611
|
+
end
|
555
612
|
|
556
|
-
|
557
|
-
# rspec's built-in formatters all call this with the output argument,
|
558
|
-
# but defaulting to output_stream for backward compatibility with
|
559
|
-
# formatters in extension libs
|
560
|
-
return false unless output_to_tty?(output)
|
561
|
-
value_for(:color, @color)
|
613
|
+
color_enabled? output
|
562
614
|
end
|
563
615
|
|
564
616
|
def color=(bool)
|
@@ -572,11 +624,31 @@ module RSpec
|
|
572
624
|
end
|
573
625
|
end
|
574
626
|
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
627
|
+
def color_enabled?(output=output_stream)
|
628
|
+
output_to_tty?(output) && value_for(:color, @color)
|
629
|
+
end
|
630
|
+
|
631
|
+
def color_enabled(output=output_stream)
|
632
|
+
RSpec.deprecate "`RSpec::Core::Configuration#color_enabled`",
|
633
|
+
:replacement =>
|
634
|
+
"`RSpec::Core::Configuration#color` if you want the configuration " +
|
635
|
+
"value, or `RSpec::Core::Configuration#color_enabled?(output)` if " +
|
636
|
+
" you want to know if color output is supported."
|
637
|
+
|
638
|
+
color_enabled? output
|
639
|
+
end
|
640
|
+
|
641
|
+
def color_enabled=(bool)
|
642
|
+
RSpec.deprecate "RSpec::Core::Configuration#color_enabled=",
|
643
|
+
:replacement => "RSpec::Core::Configuration#color="
|
644
|
+
self.color = bool
|
645
|
+
end
|
646
|
+
|
647
|
+
def color?(output=output_stream)
|
648
|
+
RSpec.deprecate "RSpec::Core::Configuration#color?",
|
649
|
+
:replacement => "RSpec::Core::Configuration#color_enabled?"
|
650
|
+
color_enabled? output_stream
|
651
|
+
end
|
580
652
|
|
581
653
|
def libs=(libs)
|
582
654
|
libs.map do |lib|
|
@@ -664,27 +736,27 @@ EOM
|
|
664
736
|
# and paths to use for output streams, but you should consider that a
|
665
737
|
# private api that may change at any time without notice.
|
666
738
|
def add_formatter(formatter_to_use, *paths)
|
667
|
-
formatter_class =
|
668
|
-
built_in_formatter(formatter_to_use) ||
|
669
|
-
custom_formatter(formatter_to_use) ||
|
670
|
-
(raise ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?.")
|
671
|
-
|
672
739
|
paths << output_stream if paths.empty?
|
673
|
-
|
740
|
+
formatter_loader.add formatter_to_use, *paths
|
674
741
|
end
|
675
|
-
|
676
742
|
alias_method :formatter=, :add_formatter
|
677
743
|
|
678
744
|
def formatters
|
679
|
-
|
745
|
+
DeprecatedMutableArrayProxy.new(formatter_loader.formatters)
|
680
746
|
end
|
681
747
|
|
748
|
+
# @private
|
749
|
+
def formatter_loader
|
750
|
+
@formatter_loader ||= Formatters::Loader.new(Reporter.new)
|
751
|
+
end
|
752
|
+
|
753
|
+
# @private
|
682
754
|
def reporter
|
683
|
-
@reporter ||=
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
755
|
+
@reporter ||=
|
756
|
+
begin
|
757
|
+
formatter_loader.setup_default output_stream, deprecation_stream
|
758
|
+
formatter_loader.reporter
|
759
|
+
end
|
688
760
|
end
|
689
761
|
|
690
762
|
# @api private
|
@@ -730,7 +802,7 @@ EOM
|
|
730
802
|
# end
|
731
803
|
def alias_example_to(new_name, *args)
|
732
804
|
extra_options = build_metadata_hash_from(args)
|
733
|
-
RSpec::Core::ExampleGroup.
|
805
|
+
RSpec::Core::ExampleGroup.define_example_method(new_name, extra_options)
|
734
806
|
end
|
735
807
|
|
736
808
|
# Define an alias for it_should_behave_like that allows different
|
@@ -755,7 +827,7 @@ EOM
|
|
755
827
|
# has behavior: sortability
|
756
828
|
# # sortability examples here
|
757
829
|
def alias_it_behaves_like_to(new_name, report_label = '')
|
758
|
-
RSpec::Core::ExampleGroup.
|
830
|
+
RSpec::Core::ExampleGroup.define_nested_shared_group_method(new_name, report_label)
|
759
831
|
end
|
760
832
|
|
761
833
|
alias_method :alias_it_should_behave_like_to, :alias_it_behaves_like_to
|
@@ -792,10 +864,12 @@ EOM
|
|
792
864
|
# # with treat_symbols_as_metadata_keys_with_true_values = true
|
793
865
|
# filter_run_including :foo # same as filter_run_including :foo => true
|
794
866
|
def filter_run_including(*args)
|
795
|
-
|
867
|
+
__filter_run(__method__, *args)
|
796
868
|
end
|
797
869
|
|
798
|
-
|
870
|
+
def filter_run(*args)
|
871
|
+
__filter_run(__method__, *args)
|
872
|
+
end
|
799
873
|
|
800
874
|
# Clears and reassigns the `inclusion_filter`. Set to `nil` if you don't
|
801
875
|
# want any inclusion filter at all.
|
@@ -805,7 +879,7 @@ EOM
|
|
805
879
|
# This overrides any inclusion filters/tags set on the command line or in
|
806
880
|
# configuration files.
|
807
881
|
def inclusion_filter=(filter)
|
808
|
-
filter_manager.
|
882
|
+
filter_manager.include_only build_metadata_hash_from([filter])
|
809
883
|
end
|
810
884
|
|
811
885
|
alias_method :filter=, :inclusion_filter=
|
@@ -861,7 +935,7 @@ EOM
|
|
861
935
|
# This overrides any exclusion filters/tags set on the command line or in
|
862
936
|
# configuration files.
|
863
937
|
def exclusion_filter=(filter)
|
864
|
-
filter_manager.
|
938
|
+
filter_manager.exclude_only build_metadata_hash_from([filter])
|
865
939
|
end
|
866
940
|
|
867
941
|
# Returns the `exclusion_filter`. If none has been set, returns an empty
|
@@ -1172,10 +1246,16 @@ EOM
|
|
1172
1246
|
$VERBOSE = !!value
|
1173
1247
|
end
|
1174
1248
|
|
1175
|
-
def warnings
|
1249
|
+
def warnings?
|
1176
1250
|
$VERBOSE
|
1177
1251
|
end
|
1178
1252
|
|
1253
|
+
def warnings
|
1254
|
+
RSpec.deprecate("`RSpec::Core::Configuration#warnings`",
|
1255
|
+
:replacement => "`RSpec::Core::Configuration#warnings?`")
|
1256
|
+
warnings?
|
1257
|
+
end
|
1258
|
+
|
1179
1259
|
# Exposes the current running example via the named
|
1180
1260
|
# helper method. RSpec 2.x exposed this via `example`,
|
1181
1261
|
# but in RSpec 3.0, the example is instead exposed via
|
@@ -1287,72 +1367,6 @@ MESSAGE
|
|
1287
1367
|
tty? || (output.respond_to?(:tty?) && output.tty?)
|
1288
1368
|
end
|
1289
1369
|
|
1290
|
-
def built_in_formatter(key)
|
1291
|
-
case key.to_s
|
1292
|
-
when 'd', 'doc', 'documentation'
|
1293
|
-
require 'rspec/core/formatters/documentation_formatter'
|
1294
|
-
RSpec::Core::Formatters::DocumentationFormatter
|
1295
|
-
when 's', 'n', 'spec', 'nested'
|
1296
|
-
RSpec.deprecate "Using `#{key.to_s}` as a shortcut for the DocumentationFormatter",
|
1297
|
-
:replacement => "`d`, `doc`, or `documentation`"
|
1298
|
-
require 'rspec/core/formatters/documentation_formatter'
|
1299
|
-
RSpec::Core::Formatters::DocumentationFormatter
|
1300
|
-
when 'h', 'html'
|
1301
|
-
require 'rspec/core/formatters/html_formatter'
|
1302
|
-
RSpec::Core::Formatters::HtmlFormatter
|
1303
|
-
when 't', 'textmate'
|
1304
|
-
require 'rspec/core/formatters/text_mate_formatter'
|
1305
|
-
RSpec::Core::Formatters::TextMateFormatter
|
1306
|
-
when 'p', 'progress'
|
1307
|
-
require 'rspec/core/formatters/progress_formatter'
|
1308
|
-
RSpec::Core::Formatters::ProgressFormatter
|
1309
|
-
when 'j', 'json'
|
1310
|
-
require 'rspec/core/formatters/json_formatter'
|
1311
|
-
RSpec::Core::Formatters::JsonFormatter
|
1312
|
-
end
|
1313
|
-
end
|
1314
|
-
|
1315
|
-
def custom_formatter(formatter_ref)
|
1316
|
-
if Class === formatter_ref
|
1317
|
-
formatter_ref
|
1318
|
-
elsif string_const?(formatter_ref)
|
1319
|
-
begin
|
1320
|
-
eval(formatter_ref)
|
1321
|
-
rescue NameError
|
1322
|
-
require path_for(formatter_ref)
|
1323
|
-
eval(formatter_ref)
|
1324
|
-
end
|
1325
|
-
end
|
1326
|
-
end
|
1327
|
-
|
1328
|
-
def string_const?(str)
|
1329
|
-
str.is_a?(String) && /\A[A-Z][a-zA-Z0-9_:]*\z/ =~ str
|
1330
|
-
end
|
1331
|
-
|
1332
|
-
def path_for(const_ref)
|
1333
|
-
underscore_with_fix_for_non_standard_rspec_naming(const_ref)
|
1334
|
-
end
|
1335
|
-
|
1336
|
-
def underscore_with_fix_for_non_standard_rspec_naming(string)
|
1337
|
-
underscore(string).sub(%r{(^|/)r_spec($|/)}, '\\1rspec\\2')
|
1338
|
-
end
|
1339
|
-
|
1340
|
-
# activesupport/lib/active_support/inflector/methods.rb, line 48
|
1341
|
-
def underscore(camel_cased_word)
|
1342
|
-
word = camel_cased_word.to_s.dup
|
1343
|
-
word.gsub!(/::/, '/')
|
1344
|
-
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
1345
|
-
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
1346
|
-
word.tr!("-", "_")
|
1347
|
-
word.downcase!
|
1348
|
-
word
|
1349
|
-
end
|
1350
|
-
|
1351
|
-
def file_at(path)
|
1352
|
-
FileUtils.mkdir_p(File.dirname(path))
|
1353
|
-
File.new(path, 'w')
|
1354
|
-
end
|
1355
|
-
|
1356
1370
|
def order_and_seed_from_seed(value, force = false)
|
1357
1371
|
order_and_seed_from_order "rand:#{value}", force
|
1358
1372
|
end
|
@@ -1397,6 +1411,24 @@ MESSAGE
|
|
1397
1411
|
RSpec.deprecate("`config.mock_with #{name.inspect}`", :replacement => "`config.mock_with :#{expected}`")
|
1398
1412
|
end
|
1399
1413
|
|
1414
|
+
def __filter_run(method_name, *args)
|
1415
|
+
metadata_hash = build_metadata_hash_from(args)
|
1416
|
+
|
1417
|
+
if metadata_hash[:focused]
|
1418
|
+
RSpec.warn_deprecation(<<-EOS.gsub(/^\s*\|/, ''))
|
1419
|
+
|In RSpec 2.x, `config.#{method_name} :focused => true` filters
|
1420
|
+
|examples defined using `focus` or `fit` since those example aliases
|
1421
|
+
|have attached `:focus => true, :focused => true` metadata. In RSpec 3,
|
1422
|
+
|the metadata for those example aliases will only have `:focus => true`,
|
1423
|
+
|so if you want to continue filtering examples defined with those example
|
1424
|
+
|aliases you should update to `config.#{method_name} :focus => true`.
|
1425
|
+
|(Called from #{CallerFilter.first_non_rspec_line}).
|
1426
|
+
EOS
|
1427
|
+
end
|
1428
|
+
|
1429
|
+
filter_manager.include_with_low_priority metadata_hash
|
1430
|
+
end
|
1431
|
+
|
1400
1432
|
end
|
1401
1433
|
end
|
1402
1434
|
end
|