rspec-core 2.99.2 → 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +14 -6
- checksums.yaml.gz.sig +2 -0
- data.tar.gz.sig +0 -0
- data/Changelog.md +103 -191
- data/License.txt +1 -0
- data/README.md +4 -25
- data/features/Upgrade.md +2 -14
- data/features/command_line/dry_run.feature +29 -0
- data/features/command_line/example_name_option.feature +1 -1
- data/features/command_line/fail_fast.feature +26 -0
- data/features/command_line/format_option.feature +3 -3
- data/features/command_line/line_number_option.feature +16 -11
- data/features/command_line/order.feature +2 -3
- data/features/command_line/pattern_option.feature +3 -3
- data/features/command_line/randomization.feature +63 -0
- data/features/command_line/require_option.feature +2 -2
- data/features/command_line/ruby.feature +1 -1
- data/features/configuration/alias_example_to.feature +13 -22
- data/features/configuration/{backtrace_clean_patterns.feature → backtrace_exclusion_patterns.feature} +17 -14
- data/features/configuration/custom_settings.feature +11 -11
- data/features/configuration/overriding_global_ordering.feature +93 -0
- data/features/configuration/profile.feature +13 -13
- data/features/configuration/read_options_from_file.feature +7 -7
- data/features/example_groups/basic_structure.feature +1 -1
- data/features/example_groups/shared_context.feature +8 -8
- data/features/example_groups/shared_examples.feature +6 -14
- data/features/expectation_framework_integration/configure_expectation_framework.feature +27 -122
- data/features/filtering/exclusion_filters.feature +2 -5
- data/features/filtering/inclusion_filters.feature +1 -5
- data/features/formatters/json_formatter.feature +2 -2
- data/features/formatters/text_formatter.feature +4 -4
- data/features/helper_methods/arbitrary_methods.feature +2 -2
- data/features/helper_methods/let.feature +5 -5
- data/features/helper_methods/modules.feature +5 -8
- data/features/hooks/around_hooks.feature +2 -2
- data/features/hooks/before_and_after_hooks.feature +14 -14
- data/features/hooks/filtering.feature +12 -14
- data/features/metadata/described_class.feature +1 -1
- data/features/metadata/user_defined.feature +16 -29
- data/features/mock_framework_integration/use_flexmock.feature +1 -1
- data/features/mock_framework_integration/use_mocha.feature +1 -1
- data/features/mock_framework_integration/use_rr.feature +1 -1
- data/features/mock_framework_integration/use_rspec.feature +5 -5
- data/features/pending/pending_examples.feature +5 -5
- data/features/spec_files/arbitrary_file_suffix.feature +1 -1
- data/features/step_definitions/additional_cli_steps.rb +3 -3
- data/features/subject/explicit_subject.feature +8 -8
- data/features/subject/implicit_receiver.feature +29 -0
- data/features/subject/implicit_subject.feature +4 -4
- data/features/support/env.rb +10 -3
- data/features/support/require_expect_syntax_in_aruba_specs.rb +16 -0
- data/lib/rspec/core.rb +11 -48
- data/lib/rspec/core/backport_random.rb +302 -0
- data/lib/rspec/core/backtrace_formatter.rb +65 -0
- data/lib/rspec/core/command_line.rb +7 -18
- data/lib/rspec/core/configuration.rb +202 -507
- data/lib/rspec/core/configuration_options.rb +17 -30
- data/lib/rspec/core/example.rb +29 -39
- data/lib/rspec/core/example_group.rb +166 -259
- data/lib/rspec/core/filter_manager.rb +30 -47
- data/lib/rspec/core/flat_map.rb +17 -0
- data/lib/rspec/core/formatters.rb +0 -138
- data/lib/rspec/core/formatters/base_formatter.rb +46 -1
- data/lib/rspec/core/formatters/base_text_formatter.rb +38 -61
- data/lib/rspec/core/formatters/deprecation_formatter.rb +21 -52
- data/lib/rspec/core/formatters/helpers.rb +0 -28
- data/lib/rspec/core/formatters/html_formatter.rb +1 -1
- data/lib/rspec/core/formatters/json_formatter.rb +38 -9
- data/lib/rspec/core/formatters/snippet_extractor.rb +14 -5
- data/lib/rspec/core/hooks.rb +55 -39
- data/lib/rspec/core/memoized_helpers.rb +17 -167
- data/lib/rspec/core/metadata.rb +16 -64
- data/lib/rspec/core/option_parser.rb +30 -39
- data/lib/rspec/core/ordering.rb +154 -0
- data/lib/rspec/core/pending.rb +12 -69
- data/lib/rspec/core/project_initializer.rb +12 -10
- data/lib/rspec/core/rake_task.rb +5 -108
- data/lib/rspec/core/reporter.rb +15 -18
- data/lib/rspec/core/runner.rb +16 -30
- data/lib/rspec/core/shared_context.rb +3 -5
- data/lib/rspec/core/shared_example_group.rb +3 -51
- data/lib/rspec/core/shared_example_group/collection.rb +1 -19
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/warnings.rb +22 -0
- data/lib/rspec/core/world.rb +12 -8
- data/spec/command_line/order_spec.rb +20 -23
- data/spec/rspec/core/backtrace_formatter_spec.rb +216 -0
- data/spec/rspec/core/command_line_spec.rb +32 -48
- data/spec/rspec/core/configuration_options_spec.rb +19 -50
- data/spec/rspec/core/configuration_spec.rb +142 -713
- data/spec/rspec/core/drb_command_line_spec.rb +2 -0
- data/spec/rspec/core/dsl_spec.rb +0 -1
- data/spec/rspec/core/example_group_spec.rb +192 -223
- data/spec/rspec/core/example_spec.rb +40 -16
- data/spec/rspec/core/filter_manager_spec.rb +2 -2
- data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -41
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +5 -123
- data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +2 -87
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +2 -3
- data/spec/rspec/core/formatters/{text_mate_formatted.html → html_formatted-1.8.7-jruby.html} +44 -25
- data/spec/rspec/core/formatters/html_formatted-1.8.7-rbx.html +477 -0
- data/spec/rspec/core/formatters/{html_formatted.html → html_formatted-1.8.7.html} +42 -25
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +425 -0
- data/spec/rspec/core/formatters/html_formatted-1.9.3-jruby.html +416 -0
- data/spec/rspec/core/formatters/html_formatted-1.9.3-rbx.html +477 -0
- data/spec/rspec/core/formatters/html_formatted-1.9.3.html +419 -0
- data/spec/rspec/core/formatters/html_formatted-2.0.0.html +425 -0
- data/spec/rspec/core/formatters/html_formatter_spec.rb +21 -46
- data/spec/rspec/core/formatters/json_formatter_spec.rb +97 -8
- data/spec/rspec/core/hooks_filtering_spec.rb +5 -5
- data/spec/rspec/core/hooks_spec.rb +61 -47
- data/spec/rspec/core/memoized_helpers_spec.rb +20 -322
- data/spec/rspec/core/metadata_spec.rb +1 -24
- data/spec/rspec/core/option_parser_spec.rb +20 -62
- data/spec/rspec/core/ordering_spec.rb +102 -0
- data/spec/rspec/core/pending_example_spec.rb +0 -40
- data/spec/rspec/core/project_initializer_spec.rb +1 -25
- data/spec/rspec/core/rake_task_spec.rb +5 -72
- data/spec/rspec/core/random_spec.rb +47 -0
- data/spec/rspec/core/reporter_spec.rb +23 -48
- data/spec/rspec/core/runner_spec.rb +31 -39
- data/spec/rspec/core/shared_context_spec.rb +3 -15
- data/spec/rspec/core/shared_example_group/collection_spec.rb +4 -17
- data/spec/rspec/core/shared_example_group_spec.rb +12 -45
- data/spec/rspec/core/{deprecation_spec.rb → warnings_spec.rb} +3 -1
- data/spec/rspec/core_spec.rb +4 -21
- data/spec/spec_helper.rb +41 -5
- data/spec/support/helper_methods.rb +0 -29
- data/spec/support/sandboxed_mock_space.rb +0 -16
- data/spec/support/shared_example_groups.rb +7 -36
- data/spec/support/stderr_splitter.rb +36 -0
- metadata +163 -157
- metadata.gz.sig +1 -0
- data/exe/autospec +0 -13
- data/features/Autotest.md +0 -38
- data/features/configuration/treat_symbols_as_metadata_keys_with_true_values.feature +0 -52
- data/features/subject/attribute_of_subject.feature +0 -124
- data/features/subject/one_liner_syntax.feature +0 -71
- data/lib/autotest/discover.rb +0 -10
- data/lib/autotest/rspec2.rb +0 -77
- data/lib/rspec/core/backtrace_cleaner.rb +0 -46
- data/lib/rspec/core/backward_compatibility.rb +0 -55
- data/lib/rspec/core/caller_filter.rb +0 -60
- data/lib/rspec/core/deprecated_mutable_array_proxy.rb +0 -32
- data/lib/rspec/core/deprecation.rb +0 -26
- data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
- data/lib/rspec/core/extensions/kernel.rb +0 -9
- data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
- data/lib/rspec/core/extensions/ordered.rb +0 -27
- data/lib/rspec/core/formatters/console_codes.rb +0 -42
- data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
- data/lib/rspec/core/metadata_hash_builder.rb +0 -97
- data/lib/rspec/core/minitest_assertions_adapter.rb +0 -28
- data/lib/rspec/core/test_unit_assertions_adapter.rb +0 -30
- data/spec/autotest/discover_spec.rb +0 -49
- data/spec/autotest/failed_results_re_spec.rb +0 -45
- data/spec/autotest/rspec_spec.rb +0 -133
- data/spec/rspec/core/backtrace_cleaner_spec.rb +0 -68
- data/spec/rspec/core/caller_filter_spec.rb +0 -58
- data/spec/rspec/core/deprecations_spec.rb +0 -59
- data/spec/rspec/core/formatters/console_codes_spec.rb +0 -50
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -107
- data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
- data/spec/rspec/core/pending_spec.rb +0 -27
- data/spec/support/silence_dsl_deprecations.rb +0 -32
@@ -0,0 +1,65 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
class BacktraceFormatter
|
4
|
+
# This is only used externally by rspec-expectations. Can be removed once
|
5
|
+
# rspec-expectations uses
|
6
|
+
# RSpec.configuration.backtrace_formatter.format_backtrace instead.
|
7
|
+
def self.format_backtrace(backtrace, options = {})
|
8
|
+
RSpec.configuration.backtrace_formatter.format_backtrace(backtrace, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :exclusion_patterns, :inclusion_patterns
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@full_backtrace = false
|
15
|
+
@exclusion_patterns = [] << Regexp.union(
|
16
|
+
*["/lib\d*/ruby/",
|
17
|
+
"org/jruby/",
|
18
|
+
"bin/",
|
19
|
+
"/gems/",
|
20
|
+
"lib/rspec/(core|expectations|matchers|mocks)"].
|
21
|
+
map {|s| Regexp.new(s.gsub("/", File::SEPARATOR))}
|
22
|
+
)
|
23
|
+
@inclusion_patterns = [Regexp.new(Dir.getwd)]
|
24
|
+
end
|
25
|
+
|
26
|
+
def full_backtrace=(full_backtrace)
|
27
|
+
@full_backtrace = full_backtrace
|
28
|
+
end
|
29
|
+
|
30
|
+
def full_backtrace?
|
31
|
+
@full_backtrace || @exclusion_patterns.empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
def format_backtrace(backtrace, options = {})
|
35
|
+
return backtrace if options[:full_backtrace]
|
36
|
+
backtrace.
|
37
|
+
take_while {|l| l != RSpec::Core::Runner::AT_EXIT_HOOK_BACKTRACE_LINE}.
|
38
|
+
map {|l| backtrace_line(l)}.
|
39
|
+
compact.
|
40
|
+
tap do |filtered|
|
41
|
+
if filtered.empty?
|
42
|
+
filtered.concat backtrace
|
43
|
+
filtered << ""
|
44
|
+
filtered << " Showing full backtrace because every line was filtered out."
|
45
|
+
filtered << " See docs for RSpec::Configuration#backtrace_exclusion_patterns and"
|
46
|
+
filtered << " RSpec::Configuration#backtrace_inclusion_patterns for more information."
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# @api private
|
52
|
+
def backtrace_line(line)
|
53
|
+
RSpec::Core::Metadata::relative_path(line) unless exclude?(line)
|
54
|
+
rescue SecurityError
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
|
58
|
+
# @api private
|
59
|
+
def exclude?(line)
|
60
|
+
return false if @full_backtrace
|
61
|
+
@exclusion_patterns.any? {|p| p =~ line} && @inclusion_patterns.none? {|p| p =~ line}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Core
|
3
|
-
class
|
3
|
+
class CommandLine
|
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
|
5
9
|
@options = options
|
6
10
|
@configuration = configuration
|
7
11
|
@world = world
|
@@ -18,30 +22,15 @@ module RSpec
|
|
18
22
|
@configuration.load_spec_files
|
19
23
|
@world.announce_filters
|
20
24
|
|
21
|
-
@configuration.reporter.report(@world.example_count
|
25
|
+
@configuration.reporter.report(@world.example_count) do |reporter|
|
22
26
|
begin
|
23
27
|
@configuration.run_hook(:before, :suite)
|
24
|
-
@world.
|
28
|
+
@world.ordered_example_groups.map {|g| g.run(reporter) }.all? ? 0 : @configuration.failure_exit_code
|
25
29
|
ensure
|
26
30
|
@configuration.run_hook(:after, :suite)
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
30
34
|
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
|
46
35
|
end
|
47
36
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require 'rspec/core/
|
2
|
+
require 'rspec/core/backtrace_formatter'
|
3
3
|
require 'rspec/core/ruby_project'
|
4
|
-
require 'rspec/core/deprecated_mutable_array_proxy'
|
5
4
|
require 'rspec/core/formatters/deprecation_formatter'
|
6
5
|
|
7
6
|
module RSpec
|
@@ -73,55 +72,62 @@ module RSpec
|
|
73
72
|
define_reader name
|
74
73
|
define_predicate_for name
|
75
74
|
end
|
76
|
-
|
75
|
+
Array(opts[:alias_with]).each do |alias_name|
|
77
76
|
define_aliases(name, alias_name)
|
78
77
|
end
|
79
78
|
end
|
80
79
|
|
81
80
|
# @macro [attach] add_setting
|
82
81
|
# @attribute $1
|
82
|
+
#
|
83
|
+
# @macro [attach] define_reader
|
84
|
+
# @attribute $1
|
83
85
|
|
86
|
+
# @macro add_setting
|
84
87
|
# Path to use if no path is provided to the `rspec` command (default:
|
85
88
|
# `"spec"`). Allows you to just type `rspec` instead of `rspec spec` to
|
86
89
|
# run all the examples in the `spec` directory.
|
87
90
|
add_setting :default_path
|
88
91
|
|
92
|
+
# @macro add_setting
|
89
93
|
# Run examples over DRb (default: `false`). RSpec doesn't supply the DRb
|
90
94
|
# server, but you can use tools like spork.
|
91
95
|
add_setting :drb
|
92
96
|
|
97
|
+
# @macro add_setting
|
93
98
|
# The drb_port (default: nil).
|
94
99
|
add_setting :drb_port
|
95
100
|
|
101
|
+
# @macro add_setting
|
96
102
|
# Default: `$stderr`.
|
97
103
|
add_setting :error_stream
|
98
104
|
|
105
|
+
# @macro add_setting
|
99
106
|
# Default: `$stderr`.
|
100
|
-
|
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
|
107
|
+
add_setting :deprecation_stream
|
112
108
|
|
109
|
+
# @macro add_setting
|
113
110
|
# Clean up and exit after the first failure (default: `false`).
|
114
111
|
add_setting :fail_fast
|
115
112
|
|
113
|
+
# @macro add_setting
|
114
|
+
# Prints the formatter output of your suite without running any
|
115
|
+
# examples or hooks.
|
116
|
+
add_setting :dry_run
|
117
|
+
|
118
|
+
# @macro add_setting
|
116
119
|
# The exit code to return if there are any failures (default: 1).
|
117
120
|
add_setting :failure_exit_code
|
118
121
|
|
122
|
+
# @macro define_reader
|
119
123
|
# Indicates files configured to be required
|
120
124
|
define_reader :requires
|
121
125
|
|
126
|
+
# @macro define_reader
|
122
127
|
# Returns dirs that have been prepended to the load path by #lib=
|
123
128
|
define_reader :libs
|
124
129
|
|
130
|
+
# @macro add_setting
|
125
131
|
# Default: `$stdout`.
|
126
132
|
# Also known as `output` and `out`
|
127
133
|
define_reader :output_stream
|
@@ -136,128 +142,67 @@ module RSpec
|
|
136
142
|
end
|
137
143
|
end
|
138
144
|
|
139
|
-
# @
|
140
|
-
def output
|
141
|
-
RSpec.deprecate("RSpec::Core::Configuration#output", :replacement => "RSpec::Core::Configuration#output_stream")
|
142
|
-
output_stream
|
143
|
-
end
|
144
|
-
|
145
|
-
# @deprecated use RSpec::Core::Configuration#output_stream= instead.
|
146
|
-
def output=(value)
|
147
|
-
RSpec.deprecate("RSpec::Core::Configuration#output=", :replacement => "RSpec::Core::Configuration#output_stream=")
|
148
|
-
self.output_stream = value
|
149
|
-
end
|
150
|
-
|
151
|
-
# @deprecated use RSpec::Core::Configuration#output_stream instead.
|
152
|
-
def out
|
153
|
-
RSpec.deprecate("RSpec::Core::Configuration#out", :replacement => "RSpec::Core::Configuration#output_stream")
|
154
|
-
output_stream
|
155
|
-
end
|
156
|
-
|
157
|
-
# @deprecated use RSpec::Core::Configuration#output_stream= instead.
|
158
|
-
def out=(value)
|
159
|
-
RSpec.deprecate("RSpec::Core::Configuration#out=", :replacement => "RSpec::Core::Configuration#output_stream=")
|
160
|
-
self.output_stream = value
|
161
|
-
end
|
162
|
-
|
145
|
+
# @macro add_setting
|
163
146
|
# Load files matching this pattern (default: `'**/*_spec.rb'`)
|
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
|
147
|
+
add_setting :pattern, :alias_with => :filename_pattern
|
171
148
|
|
172
149
|
def pattern= value
|
173
150
|
if @spec_files_loaded
|
174
|
-
|
151
|
+
RSpec.warning "Configuring `pattern` to #{value} has no effect since RSpec has already loaded the spec files."
|
175
152
|
end
|
176
153
|
@pattern = value
|
177
154
|
end
|
155
|
+
alias :filename_pattern= :pattern=
|
178
156
|
|
179
|
-
|
180
|
-
RSpec.deprecate "`RSpec::Core::Configuration#filename_pattern=`",
|
181
|
-
:replacement => "`RSpec::Core::Configuration#pattern=`"
|
182
|
-
self.pattern = value
|
183
|
-
end
|
184
|
-
|
185
|
-
|
157
|
+
# @macro add_setting
|
186
158
|
# Report the times for the slowest examples (default: `false`).
|
187
159
|
# Use this to specify the number of examples to include in the profile.
|
188
160
|
add_setting :profile_examples
|
189
161
|
|
162
|
+
# @macro add_setting
|
190
163
|
# Run all examples if none match the configured filters (default: `false`).
|
191
164
|
add_setting :run_all_when_everything_filtered
|
192
165
|
|
193
|
-
#
|
194
|
-
#
|
166
|
+
# @macro add_setting
|
167
|
+
# Color to use to indicate success.
|
168
|
+
# @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
|
195
169
|
add_setting :success_color
|
170
|
+
|
171
|
+
# @macro add_setting
|
172
|
+
# Color to use to print pending examples.
|
173
|
+
# @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
|
196
174
|
add_setting :pending_color
|
175
|
+
|
176
|
+
# @macro add_setting
|
177
|
+
# Color to use to indicate failure.
|
178
|
+
# @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
|
197
179
|
add_setting :failure_color
|
180
|
+
|
181
|
+
# @macro add_setting
|
182
|
+
# The default output color.
|
183
|
+
# @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
|
198
184
|
add_setting :default_color
|
185
|
+
|
186
|
+
# @macro add_setting
|
187
|
+
# Color used when a pending example is fixed.
|
188
|
+
# @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
|
199
189
|
add_setting :fixed_color
|
200
|
-
add_setting :detail_color
|
201
190
|
|
202
|
-
#
|
203
|
-
#
|
204
|
-
#
|
205
|
-
|
206
|
-
# you're using RSpec's built-in formatters). If you discover an ordering
|
207
|
-
# dependency (i.e. examples fail intermittently depending on order), set
|
208
|
-
# this (on Configuration or on the command line with `--seed`) to run
|
209
|
-
# using the same seed while you debug the issue.
|
210
|
-
#
|
211
|
-
# We recommend, actually, that you use the command line approach so you
|
212
|
-
# don't accidentally leave the seed encoded.
|
213
|
-
define_reader :seed
|
191
|
+
# @macro add_setting
|
192
|
+
# Color used to print details.
|
193
|
+
# @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
|
194
|
+
add_setting :detail_color
|
214
195
|
|
196
|
+
# @macro add_setting
|
215
197
|
# When a block passed to pending fails (as expected), display the failure
|
216
198
|
# without reporting it as a failure (default: false).
|
217
|
-
|
218
|
-
RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\|/, ''))
|
219
|
-
|RSpec.configuration.show_failures_in_pending_blocks is being removed
|
220
|
-
|with no replacement. Called from #{CallerFilter.first_non_rspec_line}.
|
221
|
-
EOS
|
222
|
-
|
223
|
-
@show_failures_in_pending_blocks = value
|
224
|
-
end
|
225
|
-
|
226
|
-
def show_failures_in_pending_blocks
|
227
|
-
RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\|/, ''))
|
228
|
-
|RSpec.configuration.show_failures_in_pending_blocks is being removed
|
229
|
-
|with no replacement. Called from #{CallerFilter.first_non_rspec_line}.
|
230
|
-
EOS
|
231
|
-
|
232
|
-
@show_failures_in_pending_blocks
|
233
|
-
end
|
234
|
-
|
235
|
-
def show_failures_in_pending_blocks?
|
236
|
-
!!show_failures_in_pending_blocks
|
237
|
-
end
|
238
|
-
|
239
|
-
# Convert symbols to hashes with the symbol as a key with a value of
|
240
|
-
# `true` (default: false).
|
241
|
-
#
|
242
|
-
# This allows you to tag a group or example like this:
|
243
|
-
#
|
244
|
-
# describe "something slow", :slow do
|
245
|
-
# # ...
|
246
|
-
# end
|
247
|
-
#
|
248
|
-
# ... instead of having to type:
|
249
|
-
#
|
250
|
-
# describe "something slow", :slow => true do
|
251
|
-
# # ...
|
252
|
-
# end
|
253
|
-
add_setting :treat_symbols_as_metadata_keys_with_true_values
|
199
|
+
add_setting :show_failures_in_pending_blocks
|
254
200
|
|
201
|
+
# Deprecated. This config option was added in RSpec 2 to pave the way
|
202
|
+
# for this being the default behavior in RSpec 3. Now this option is
|
203
|
+
# a no-op.
|
255
204
|
def treat_symbols_as_metadata_keys_with_true_values=(value)
|
256
|
-
|
257
|
-
RSpec.deprecate("RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values = false")
|
258
|
-
end
|
259
|
-
|
260
|
-
@treat_symbols_as_metadata_keys_with_true_values = value
|
205
|
+
RSpec.deprecate("RSpec::Core::Configuration#treat_symbols_as_metadata_keys_with_true_values=")
|
261
206
|
end
|
262
207
|
|
263
208
|
# @private
|
@@ -270,36 +215,34 @@ module RSpec
|
|
270
215
|
add_setting :expecting_with_rspec
|
271
216
|
# @private
|
272
217
|
attr_accessor :filter_manager
|
218
|
+
# @private
|
219
|
+
attr_reader :backtrace_formatter, :ordering_manager
|
273
220
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
:replacement => "`RSpec::Core::Configuration#backtrace_formatter`"
|
279
|
-
@backtrace_formatter
|
280
|
-
end
|
221
|
+
# Alias for rspec-2.x's backtrace_cleaner (now backtrace_formatter)
|
222
|
+
#
|
223
|
+
# TODO: consider deprecating and removing this rather than aliasing in rspec-3?
|
224
|
+
alias backtrace_cleaner backtrace_formatter
|
281
225
|
|
282
226
|
def initialize
|
283
227
|
@expectation_frameworks = []
|
284
228
|
@include_or_extend_modules = []
|
285
229
|
@mock_framework = nil
|
286
230
|
@files_to_run = []
|
231
|
+
@formatters = []
|
287
232
|
@color = false
|
288
|
-
@order = nil
|
289
233
|
@pattern = '**/*_spec.rb'
|
290
234
|
@failure_exit_code = 1
|
291
235
|
@spec_files_loaded = false
|
292
236
|
|
293
|
-
@backtrace_formatter =
|
237
|
+
@backtrace_formatter = BacktraceFormatter.new
|
294
238
|
|
295
239
|
@default_path = 'spec'
|
296
240
|
@deprecation_stream = $stderr
|
297
241
|
@output_stream = $stdout
|
298
242
|
@reporter = nil
|
299
243
|
@filter_manager = FilterManager.new
|
244
|
+
@ordering_manager = Ordering::ConfigurationManager.new
|
300
245
|
@preferred_options = {}
|
301
|
-
@seed = srand % 0xFFFF
|
302
|
-
@ordering_already_forced = false
|
303
246
|
@failure_color = :red
|
304
247
|
@success_color = :green
|
305
248
|
@pending_color = :yellow
|
@@ -309,18 +252,13 @@ module RSpec
|
|
309
252
|
@profile_examples = false
|
310
253
|
@requires = []
|
311
254
|
@libs = []
|
312
|
-
@show_failures_in_pending_blocks = false
|
313
255
|
end
|
314
256
|
|
315
257
|
# @private
|
316
258
|
#
|
317
259
|
# Used to set higher priority option values from the command line.
|
318
260
|
def force(hash)
|
319
|
-
|
320
|
-
hash[:order], hash[:seed] = order_and_seed_from_seed(hash[:seed], true)
|
321
|
-
elsif hash.has_key?(:order)
|
322
|
-
set_order_and_seed(hash, true)
|
323
|
-
end
|
261
|
+
ordering_manager.force(hash)
|
324
262
|
@preferred_options.merge!(hash)
|
325
263
|
self.warnings = value_for :warnings, nil
|
326
264
|
end
|
@@ -329,7 +267,7 @@ module RSpec
|
|
329
267
|
def reset
|
330
268
|
@spec_files_loaded = false
|
331
269
|
@reporter = nil
|
332
|
-
@
|
270
|
+
@formatters.clear
|
333
271
|
end
|
334
272
|
|
335
273
|
# @overload add_setting(name)
|
@@ -386,36 +324,33 @@ module RSpec
|
|
386
324
|
mock_with framework
|
387
325
|
end
|
388
326
|
|
389
|
-
#
|
390
|
-
# Configuration#backtrace_exclusion_patterns instead
|
327
|
+
# Regexps used to exclude lines from backtraces.
|
391
328
|
#
|
392
|
-
#
|
329
|
+
# Excludes lines from ruby (and jruby) source, installed gems, anything
|
330
|
+
# in any "bin" directory, and any of the rspec libs (outside gem
|
331
|
+
# installs) by default.
|
393
332
|
#
|
394
|
-
#
|
395
|
-
# getter
|
333
|
+
# You can modify the list via the getter, or replace it with the setter.
|
396
334
|
#
|
397
335
|
# To override this behaviour and display a full backtrace, use
|
398
336
|
# `--backtrace`on the command line, in a `.rspec` file, or in the
|
399
337
|
# `rspec_options` attribute of RSpec's rake task.
|
400
|
-
def
|
401
|
-
RSpec.deprecate("RSpec::Core::Configuration#backtrace_clean_patterns",
|
402
|
-
:replacement => "RSpec::Core::Configuration#backtrace_exclusion_patterns")
|
338
|
+
def backtrace_exclusion_patterns
|
403
339
|
@backtrace_formatter.exclusion_patterns
|
404
340
|
end
|
405
341
|
|
406
|
-
def
|
407
|
-
RSpec.deprecate("RSpec::Core::Configuration#backtrace_clean_patterns",
|
408
|
-
:replacement => "RSpec::Core::Configuration#backtrace_exclusion_patterns")
|
342
|
+
def backtrace_exclusion_patterns=(patterns)
|
409
343
|
@backtrace_formatter.exclusion_patterns = patterns
|
410
344
|
end
|
411
345
|
|
412
|
-
#
|
346
|
+
# Regexps used to include lines in backtraces.
|
413
347
|
#
|
414
|
-
# Defaults to [Regexp.new Dir.getwd]
|
415
|
-
# matches any of the exclusion patterns. Otherwise it defaults to empty.
|
348
|
+
# Defaults to [Regexp.new Dir.getwd].
|
416
349
|
#
|
417
|
-
#
|
418
|
-
#
|
350
|
+
# Lines that match an exclusion _and_ an inclusion pattern
|
351
|
+
# will be included.
|
352
|
+
#
|
353
|
+
# You can modify the list via the getter, or replace it with the setter.
|
419
354
|
def backtrace_inclusion_patterns
|
420
355
|
@backtrace_formatter.inclusion_patterns
|
421
356
|
end
|
@@ -424,24 +359,6 @@ module RSpec
|
|
424
359
|
@backtrace_formatter.inclusion_patterns = patterns
|
425
360
|
end
|
426
361
|
|
427
|
-
# The patterns to discard from backtraces.
|
428
|
-
#
|
429
|
-
# Defaults to RSpec::Core::BacktraceCleaner::DEFAULT_EXCLUSION_PATTERNS
|
430
|
-
#
|
431
|
-
# One can replace the list by using the setter or modify it through the
|
432
|
-
# getter
|
433
|
-
#
|
434
|
-
# To override this behaviour and display a full backtrace, use
|
435
|
-
# `--backtrace`on the command line, in a `.rspec` file, or in the
|
436
|
-
# `rspec_options` attribute of RSpec's rake task.
|
437
|
-
def backtrace_exclusion_patterns
|
438
|
-
@backtrace_formatter.exclusion_patterns
|
439
|
-
end
|
440
|
-
|
441
|
-
def backtrace_exclusion_patterns=(patterns)
|
442
|
-
@backtrace_formatter.exclusion_patterns = patterns
|
443
|
-
end
|
444
|
-
|
445
362
|
# Sets the mock framework adapter module.
|
446
363
|
#
|
447
364
|
# `framework` can be a Symbol or a Module.
|
@@ -478,19 +395,14 @@ module RSpec
|
|
478
395
|
when String, Symbol
|
479
396
|
require case framework.to_s
|
480
397
|
when /rspec/i
|
481
|
-
deprecate_unless_mock_adapter_name_is_exact(framework, :rspec)
|
482
398
|
'rspec/core/mocking/with_rspec'
|
483
399
|
when /mocha/i
|
484
|
-
deprecate_unless_mock_adapter_name_is_exact(framework, :mocha)
|
485
400
|
'rspec/core/mocking/with_mocha'
|
486
401
|
when /rr/i
|
487
|
-
deprecate_unless_mock_adapter_name_is_exact(framework, :rr)
|
488
402
|
'rspec/core/mocking/with_rr'
|
489
403
|
when /flexmock/i
|
490
|
-
deprecate_unless_mock_adapter_name_is_exact(framework, :flexmock)
|
491
404
|
'rspec/core/mocking/with_flexmock'
|
492
405
|
else
|
493
|
-
deprecate_unless_mock_adapter_name_is_exact(framework, :nothing)
|
494
406
|
'rspec/core/mocking/with_absolutely_nothing'
|
495
407
|
end
|
496
408
|
RSpec::Core::MockFrameworkAdapter
|
@@ -526,17 +438,16 @@ module RSpec
|
|
526
438
|
# Sets the expectation framework module(s) to be included in each example
|
527
439
|
# group.
|
528
440
|
#
|
529
|
-
# `frameworks` can be `:rspec`, `:
|
530
|
-
#
|
441
|
+
# `frameworks` can be `:rspec`, `:stdlib`, a custom module, or any
|
442
|
+
# combination thereof:
|
531
443
|
#
|
532
444
|
# config.expect_with :rspec
|
533
|
-
# config.expect_with :
|
534
|
-
# config.expect_with :
|
535
|
-
# config.expect_with :rspec, :minitest
|
445
|
+
# config.expect_with :stdlib
|
446
|
+
# config.expect_with :rspec, :stdlib
|
536
447
|
# config.expect_with OtherExpectationFramework
|
537
448
|
#
|
538
|
-
# RSpec will translate `:rspec
|
539
|
-
#
|
449
|
+
# RSpec will translate `:rspec` and `:stdlib` into the appropriate
|
450
|
+
# modules.
|
540
451
|
#
|
541
452
|
# ## Configuration
|
542
453
|
#
|
@@ -556,15 +467,8 @@ module RSpec
|
|
556
467
|
self.expecting_with_rspec = true
|
557
468
|
::RSpec::Matchers
|
558
469
|
when :stdlib
|
559
|
-
RSpec.deprecate ':stdlib', :replacement => ":test_unit or :minitest"
|
560
470
|
require 'test/unit/assertions'
|
561
471
|
::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
|
568
472
|
else
|
569
473
|
raise ArgumentError, "#{framework.inspect} is not supported"
|
570
474
|
end
|
@@ -591,32 +495,18 @@ module RSpec
|
|
591
495
|
@backtrace_formatter.full_backtrace = true_or_false
|
592
496
|
end
|
593
497
|
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
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
|
612
|
-
|
613
|
-
color_enabled? output
|
498
|
+
def color(output=output_stream)
|
499
|
+
# rspec's built-in formatters all call this with the output argument,
|
500
|
+
# but defaulting to output_stream for backward compatibility with
|
501
|
+
# formatters in extension libs
|
502
|
+
return false unless output_to_tty?(output)
|
503
|
+
value_for(:color, @color)
|
614
504
|
end
|
615
505
|
|
616
506
|
def color=(bool)
|
617
507
|
if bool
|
618
508
|
if RSpec.windows_os? and not ENV['ANSICON']
|
619
|
-
|
509
|
+
RSpec.warning "You must use ANSICON 1.31 or later (http://adoxa.3eeweb.com/ansicon/) to use colour on Windows"
|
620
510
|
@color = false
|
621
511
|
else
|
622
512
|
@color = true
|
@@ -624,31 +514,11 @@ module RSpec
|
|
624
514
|
end
|
625
515
|
end
|
626
516
|
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
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
|
517
|
+
# TODO - deprecate color_enabled - probably not until the last 2.x
|
518
|
+
# release before 3.0
|
519
|
+
alias_method :color_enabled, :color
|
520
|
+
alias_method :color_enabled=, :color=
|
521
|
+
define_predicate_for :color_enabled, :color
|
652
522
|
|
653
523
|
def libs=(libs)
|
654
524
|
libs.map do |lib|
|
@@ -664,49 +534,6 @@ module RSpec
|
|
664
534
|
@requires += paths
|
665
535
|
end
|
666
536
|
|
667
|
-
def debug=(bool)
|
668
|
-
if bool == :cli
|
669
|
-
RSpec.deprecate("RSpec's built-in debugger support",
|
670
|
-
:replacement => "a CLI option like `-rruby-debug` or `-rdebugger`",
|
671
|
-
:call_site => nil)
|
672
|
-
bool = true
|
673
|
-
elsif bool
|
674
|
-
RSpec.deprecate("RSpec::Core::Configuration#debug=",
|
675
|
-
:replacement => "a CLI option like `-rruby-debug` or `-rdebugger`")
|
676
|
-
else
|
677
|
-
# ...but the only way to call this with a false value is to
|
678
|
-
# call it directly, so here we mention the method name.
|
679
|
-
# There's no replacement for it since it's a no-op, though.
|
680
|
-
RSpec.deprecate("RSpec::Core::Configuration#debug=")
|
681
|
-
end
|
682
|
-
|
683
|
-
return unless bool
|
684
|
-
begin
|
685
|
-
require 'ruby-debug'
|
686
|
-
Debugger.start
|
687
|
-
rescue LoadError => e
|
688
|
-
raise <<-EOM
|
689
|
-
|
690
|
-
#{'*'*50}
|
691
|
-
#{e.message}
|
692
|
-
|
693
|
-
If you have it installed as a ruby gem, then you need to either require
|
694
|
-
'rubygems' or configure the RUBYOPT environment variable with the value
|
695
|
-
'rubygems'.
|
696
|
-
|
697
|
-
#{e.backtrace.join("\n")}
|
698
|
-
#{'*'*50}
|
699
|
-
EOM
|
700
|
-
end
|
701
|
-
end
|
702
|
-
|
703
|
-
def debug?
|
704
|
-
RSpec.deprecate("RSpec::Core::Configuration#debug?",
|
705
|
-
:replacement => "defined?(Debugger)")
|
706
|
-
|
707
|
-
!!defined?(Debugger)
|
708
|
-
end
|
709
|
-
|
710
537
|
# Run examples defined on `line_numbers` in all files to run.
|
711
538
|
def line_numbers=(line_numbers)
|
712
539
|
filter_run :line_numbers => line_numbers.map{|l| l.to_i}
|
@@ -736,27 +563,27 @@ EOM
|
|
736
563
|
# and paths to use for output streams, but you should consider that a
|
737
564
|
# private api that may change at any time without notice.
|
738
565
|
def add_formatter(formatter_to_use, *paths)
|
566
|
+
formatter_class =
|
567
|
+
built_in_formatter(formatter_to_use) ||
|
568
|
+
custom_formatter(formatter_to_use) ||
|
569
|
+
(raise ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?.")
|
570
|
+
|
739
571
|
paths << output_stream if paths.empty?
|
740
|
-
|
572
|
+
formatters << formatter_class.new(*paths.map {|p| String === p ? file_at(p) : p})
|
741
573
|
end
|
574
|
+
|
742
575
|
alias_method :formatter=, :add_formatter
|
743
576
|
|
744
577
|
def formatters
|
745
|
-
|
746
|
-
end
|
747
|
-
|
748
|
-
# @private
|
749
|
-
def formatter_loader
|
750
|
-
@formatter_loader ||= Formatters::Loader.new(Reporter.new)
|
578
|
+
@formatters ||= []
|
751
579
|
end
|
752
580
|
|
753
|
-
# @private
|
754
581
|
def reporter
|
755
|
-
@reporter ||=
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
582
|
+
@reporter ||= begin
|
583
|
+
add_formatter('progress') if formatters.empty?
|
584
|
+
add_formatter(RSpec::Core::Formatters::DeprecationFormatter, deprecation_stream, output_stream)
|
585
|
+
Reporter.new(self, *formatters)
|
586
|
+
end
|
760
587
|
end
|
761
588
|
|
762
589
|
# @api private
|
@@ -801,8 +628,8 @@ EOM
|
|
801
628
|
# end
|
802
629
|
# end
|
803
630
|
def alias_example_to(new_name, *args)
|
804
|
-
extra_options =
|
805
|
-
RSpec::Core::ExampleGroup.
|
631
|
+
extra_options = Metadata.build_hash_from(args)
|
632
|
+
RSpec::Core::ExampleGroup.alias_example_to(new_name, extra_options)
|
806
633
|
end
|
807
634
|
|
808
635
|
# Define an alias for it_should_behave_like that allows different
|
@@ -827,15 +654,14 @@ EOM
|
|
827
654
|
# has behavior: sortability
|
828
655
|
# # sortability examples here
|
829
656
|
def alias_it_behaves_like_to(new_name, report_label = '')
|
830
|
-
RSpec::Core::ExampleGroup.
|
657
|
+
RSpec::Core::ExampleGroup.alias_it_behaves_like_to(new_name, report_label)
|
831
658
|
end
|
832
659
|
|
833
660
|
alias_method :alias_it_should_behave_like_to, :alias_it_behaves_like_to
|
834
661
|
|
835
|
-
# Adds key/value pairs to the `inclusion_filter`. If
|
836
|
-
#
|
837
|
-
#
|
838
|
-
# each symbol is treated as a key in the hash with the value `true`.
|
662
|
+
# Adds key/value pairs to the `inclusion_filter`. If `args`
|
663
|
+
# includes any symbols that are not part of the hash, each symbol
|
664
|
+
# is treated as a key in the hash with the value `true`.
|
839
665
|
#
|
840
666
|
# ### Note
|
841
667
|
#
|
@@ -861,15 +687,12 @@ EOM
|
|
861
687
|
# # and the metadata itself e.g.
|
862
688
|
# config.filter_run_including :foo => lambda {|v,m| m[:foo] == 'bar'}
|
863
689
|
#
|
864
|
-
# # with treat_symbols_as_metadata_keys_with_true_values = true
|
865
690
|
# filter_run_including :foo # same as filter_run_including :foo => true
|
866
691
|
def filter_run_including(*args)
|
867
|
-
|
692
|
+
filter_manager.include_with_low_priority Metadata.build_hash_from(args)
|
868
693
|
end
|
869
694
|
|
870
|
-
|
871
|
-
__filter_run(__method__, *args)
|
872
|
-
end
|
695
|
+
alias_method :filter_run, :filter_run_including
|
873
696
|
|
874
697
|
# Clears and reassigns the `inclusion_filter`. Set to `nil` if you don't
|
875
698
|
# want any inclusion filter at all.
|
@@ -879,7 +702,7 @@ EOM
|
|
879
702
|
# This overrides any inclusion filters/tags set on the command line or in
|
880
703
|
# configuration files.
|
881
704
|
def inclusion_filter=(filter)
|
882
|
-
filter_manager.
|
705
|
+
filter_manager.include! Metadata.build_hash_from([filter])
|
883
706
|
end
|
884
707
|
|
885
708
|
alias_method :filter=, :inclusion_filter=
|
@@ -892,10 +715,9 @@ EOM
|
|
892
715
|
|
893
716
|
alias_method :filter, :inclusion_filter
|
894
717
|
|
895
|
-
# Adds key/value pairs to the `exclusion_filter`. If
|
896
|
-
#
|
897
|
-
#
|
898
|
-
# each symbol is treated as a key in the hash with the value `true`.
|
718
|
+
# Adds key/value pairs to the `exclusion_filter`. If `args`
|
719
|
+
# includes any symbols that are not part of the hash, each symbol
|
720
|
+
# is treated as a key in the hash with the value `true`.
|
899
721
|
#
|
900
722
|
# ### Note
|
901
723
|
#
|
@@ -921,10 +743,9 @@ EOM
|
|
921
743
|
# # and the metadata itself e.g.
|
922
744
|
# config.filter_run_excluding :foo => lambda {|v,m| m[:foo] == 'bar'}
|
923
745
|
#
|
924
|
-
# # with treat_symbols_as_metadata_keys_with_true_values = true
|
925
746
|
# filter_run_excluding :foo # same as filter_run_excluding :foo => true
|
926
747
|
def filter_run_excluding(*args)
|
927
|
-
filter_manager.exclude_with_low_priority
|
748
|
+
filter_manager.exclude_with_low_priority Metadata.build_hash_from(args)
|
928
749
|
end
|
929
750
|
|
930
751
|
# Clears and reassigns the `exclusion_filter`. Set to `nil` if you don't
|
@@ -935,7 +756,7 @@ EOM
|
|
935
756
|
# This overrides any exclusion filters/tags set on the command line or in
|
936
757
|
# configuration files.
|
937
758
|
def exclusion_filter=(filter)
|
938
|
-
filter_manager.
|
759
|
+
filter_manager.exclude! Metadata.build_hash_from([filter])
|
939
760
|
end
|
940
761
|
|
941
762
|
# Returns the `exclusion_filter`. If none has been set, returns an empty
|
@@ -977,7 +798,7 @@ EOM
|
|
977
798
|
#
|
978
799
|
# @see #extend
|
979
800
|
def include(mod, *filters)
|
980
|
-
include_or_extend_modules << [:include, mod,
|
801
|
+
include_or_extend_modules << [:include, mod, Metadata.build_hash_from(filters)]
|
981
802
|
end
|
982
803
|
|
983
804
|
# Tells RSpec to extend example groups with `mod`. Methods defined in
|
@@ -1010,7 +831,7 @@ EOM
|
|
1010
831
|
#
|
1011
832
|
# @see #include
|
1012
833
|
def extend(mod, *filters)
|
1013
|
-
include_or_extend_modules << [:extend, mod,
|
834
|
+
include_or_extend_modules << [:extend, mod, Metadata.build_hash_from(filters)]
|
1014
835
|
end
|
1015
836
|
|
1016
837
|
# @private
|
@@ -1064,7 +885,6 @@ EOM
|
|
1064
885
|
def load_spec_files
|
1065
886
|
files_to_run.uniq.each {|f| load File.expand_path(f) }
|
1066
887
|
@spec_files_loaded = true
|
1067
|
-
raise_if_rspec_1_is_loaded
|
1068
888
|
end
|
1069
889
|
|
1070
890
|
# @private
|
@@ -1086,131 +906,47 @@ EOM
|
|
1086
906
|
@format_docstrings_block ||= DEFAULT_FORMATTER
|
1087
907
|
end
|
1088
908
|
|
1089
|
-
# @api
|
1090
|
-
#
|
1091
|
-
# Sets the seed value and sets `order='rand'`
|
1092
|
-
def seed=(seed)
|
1093
|
-
order_and_seed_from_seed(seed)
|
1094
|
-
end
|
1095
|
-
|
1096
|
-
# @api
|
1097
|
-
#
|
1098
|
-
# Sets the order and, if order is `'rand:<seed>'`, also sets the seed.
|
1099
|
-
def order=(type)
|
1100
|
-
order_and_seed_from_order(type)
|
1101
|
-
end
|
1102
|
-
|
1103
|
-
# Determines the order in which examples are run (default: OS standard
|
1104
|
-
# load order for files, declaration order for groups and examples).
|
1105
|
-
def order
|
1106
|
-
RSpec.warn_deprecation(
|
1107
|
-
"RSpec::Core::Configuration#order is deprecated with no replacement. " +
|
1108
|
-
"In RSpec 3 individal example groups can use a particular ordering, " +
|
1109
|
-
"so `order` is no longer a global property of the entire suite. " +
|
1110
|
-
"Called from #{CallerFilter.first_non_rspec_line}."
|
1111
|
-
)
|
1112
|
-
|
1113
|
-
value_for(:order, @order)
|
1114
|
-
end
|
1115
|
-
|
1116
|
-
def randomize?
|
1117
|
-
RSpec.warn_deprecation(
|
1118
|
-
"RSpec::Core::Configuration#randomize? is deprecated with no replacement. " +
|
1119
|
-
"In RSpec 3 individal example groups can use a particular ordering, " +
|
1120
|
-
"so `randomize?` is no longer a binary property of the entire suite. " +
|
1121
|
-
"Called from #{CallerFilter.first_non_rspec_line}."
|
1122
|
-
)
|
1123
|
-
|
1124
|
-
value_for(:order, @order).to_s.match(/rand/)
|
1125
|
-
end
|
1126
|
-
|
1127
|
-
# @private
|
1128
|
-
DEFAULT_ORDERING = lambda { |list| list }
|
1129
|
-
|
1130
909
|
# @private
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
910
|
+
def self.delegate_to_ordering_manager(*methods)
|
911
|
+
methods.each do |method|
|
912
|
+
define_method method do |*args, &block|
|
913
|
+
ordering_manager.__send__(method, *args, &block)
|
914
|
+
end
|
915
|
+
end
|
1136
916
|
end
|
1137
917
|
|
1138
|
-
#
|
918
|
+
# @macro delegate_to_ordering_manager
|
1139
919
|
#
|
1140
|
-
#
|
1141
|
-
|
1142
|
-
# config.order_examples do |examples|
|
1143
|
-
# examples.reverse
|
1144
|
-
# end
|
1145
|
-
# end
|
1146
|
-
#
|
1147
|
-
# @see #order_groups
|
1148
|
-
# @see #order_groups_and_examples
|
1149
|
-
# @see #order=
|
1150
|
-
# @see #seed=
|
1151
|
-
def order_examples(&block)
|
1152
|
-
RSpec.deprecate("RSpec::Configuration#order_examples", :replacement => "RSpec::Configuration#register_ordering(:global)")
|
1153
|
-
@example_ordering_block = block
|
1154
|
-
@order = "custom" unless built_in_orderer?(block)
|
1155
|
-
end
|
1156
|
-
|
1157
|
-
# @private
|
1158
|
-
def example_ordering_block
|
1159
|
-
@example_ordering_block ||= DEFAULT_ORDERING
|
1160
|
-
end
|
920
|
+
# Sets the seed value and sets the default global ordering to random.
|
921
|
+
delegate_to_ordering_manager :seed=
|
1161
922
|
|
1162
|
-
#
|
923
|
+
# @macro delegate_to_ordering_manager
|
924
|
+
# Seed for random ordering (default: generated randomly each run).
|
1163
925
|
#
|
1164
|
-
#
|
1165
|
-
#
|
1166
|
-
#
|
1167
|
-
#
|
1168
|
-
#
|
1169
|
-
#
|
926
|
+
# When you run specs with `--order random`, RSpec generates a random seed
|
927
|
+
# for the randomization and prints it to the `output_stream` (assuming
|
928
|
+
# you're using RSpec's built-in formatters). If you discover an ordering
|
929
|
+
# dependency (i.e. examples fail intermittently depending on order), set
|
930
|
+
# this (on Configuration or on the command line with `--seed`) to run
|
931
|
+
# using the same seed while you debug the issue.
|
1170
932
|
#
|
1171
|
-
#
|
1172
|
-
#
|
1173
|
-
|
1174
|
-
# @see #seed=
|
1175
|
-
def order_groups(&block)
|
1176
|
-
RSpec.deprecate("RSpec::Configuration#order_groups", :replacement => "RSpec::Configuration#register_ordering(:global)")
|
1177
|
-
@group_ordering_block = block
|
1178
|
-
@order = "custom" unless built_in_orderer?(block)
|
1179
|
-
end
|
1180
|
-
|
1181
|
-
# @private
|
1182
|
-
def group_ordering_block
|
1183
|
-
@group_ordering_block ||= DEFAULT_ORDERING
|
1184
|
-
end
|
933
|
+
# We recommend, actually, that you use the command line approach so you
|
934
|
+
# don't accidentally leave the seed encoded.
|
935
|
+
delegate_to_ordering_manager :seed
|
1185
936
|
|
1186
|
-
#
|
937
|
+
# @macro delegate_to_ordering_manager
|
1187
938
|
#
|
1188
|
-
#
|
1189
|
-
|
1190
|
-
# config.order_groups_and_examples do |groups_or_examples|
|
1191
|
-
# groups_or_examples.reverse
|
1192
|
-
# end
|
1193
|
-
# end
|
1194
|
-
#
|
1195
|
-
# @see #order_groups
|
1196
|
-
# @see #order_examples
|
1197
|
-
# @see #order=
|
1198
|
-
# @see #seed=
|
1199
|
-
def order_groups_and_examples(&block)
|
1200
|
-
order_groups(&block)
|
1201
|
-
order_examples(&block)
|
1202
|
-
end
|
939
|
+
# Sets the default global order and, if order is `'rand:<seed>'`, also sets the seed.
|
940
|
+
delegate_to_ordering_manager :order=
|
1203
941
|
|
1204
|
-
#
|
942
|
+
# @macro delegate_to_ordering_manager
|
943
|
+
# Registers a named ordering strategy that can later be
|
1205
944
|
# used to order an example group's subgroups by adding
|
1206
945
|
# `:order => <name>` metadata to the example group.
|
1207
946
|
#
|
1208
|
-
# In RSpec 2.99, only `register_ordering(:global)` is supported,
|
1209
|
-
# to set the global ordering.
|
1210
|
-
#
|
1211
947
|
# @param name [Symbol] The name of the ordering.
|
1212
948
|
# @yield Block that will order the given examples or example groups
|
1213
|
-
# @yieldparam list [Array<RSpec::Core::Example>, Array<RSpec::Core::
|
949
|
+
# @yieldparam list [Array<RSpec::Core::Example>, Array<RSpec::Core::ExampleGroup>] The examples or groups to order
|
1214
950
|
# @yieldreturn [Array<RSpec::Core::Example>, Array<RSpec::Core::ExampleGroup>] The re-ordered examples or groups
|
1215
951
|
#
|
1216
952
|
# @example
|
@@ -1227,33 +963,18 @@ EOM
|
|
1227
963
|
# @note Pass the symbol `:global` to set the ordering strategy that
|
1228
964
|
# will be used to order the top-level example groups and any example
|
1229
965
|
# groups that do not have declared `:order` metadata.
|
1230
|
-
|
1231
|
-
unless name == :global
|
1232
|
-
raise ArgumentError,
|
1233
|
-
"Ordering name `#{name.inspect}` given, `:global` expected. " +
|
1234
|
-
"RSpec 3 will support named orderings (that can be used for " +
|
1235
|
-
"individual example groups) but 2.99 only supports using this " +
|
1236
|
-
"to set the global order."
|
1237
|
-
end
|
966
|
+
delegate_to_ordering_manager :register_ordering
|
1238
967
|
|
1239
|
-
|
1240
|
-
|
1241
|
-
@order = "custom"
|
1242
|
-
end
|
968
|
+
# @private
|
969
|
+
delegate_to_ordering_manager :seed_used?, :ordering_registry
|
1243
970
|
|
1244
971
|
# Set Ruby warnings on or off
|
1245
972
|
def warnings= value
|
1246
973
|
$VERBOSE = !!value
|
1247
974
|
end
|
1248
975
|
|
1249
|
-
def warnings?
|
1250
|
-
$VERBOSE
|
1251
|
-
end
|
1252
|
-
|
1253
976
|
def warnings
|
1254
|
-
|
1255
|
-
:replacement => "`RSpec::Core::Configuration#warnings?`")
|
1256
|
-
warnings?
|
977
|
+
$VERBOSE
|
1257
978
|
end
|
1258
979
|
|
1259
980
|
# Exposes the current running example via the named
|
@@ -1305,15 +1026,11 @@ EOM
|
|
1305
1026
|
|
1306
1027
|
private
|
1307
1028
|
|
1308
|
-
def _randomize?
|
1309
|
-
value_for(:order, @order).to_s.match(/rand/)
|
1310
|
-
end
|
1311
|
-
|
1312
1029
|
def get_files_to_run(paths)
|
1313
|
-
paths
|
1030
|
+
FlatMap.flat_map(paths) do |path|
|
1314
1031
|
path = path.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
1315
1032
|
File.directory?(path) ? gather_directories(path) : extract_location(path)
|
1316
|
-
end.
|
1033
|
+
end.sort
|
1317
1034
|
end
|
1318
1035
|
|
1319
1036
|
def gather_directories(path)
|
@@ -1347,88 +1064,66 @@ EOM
|
|
1347
1064
|
end
|
1348
1065
|
end
|
1349
1066
|
|
1350
|
-
def raise_if_rspec_1_is_loaded
|
1351
|
-
if defined?(Spec) && defined?(Spec::VERSION::MAJOR) && Spec::VERSION::MAJOR == 1
|
1352
|
-
raise <<-MESSAGE
|
1353
|
-
|
1354
|
-
#{'*'*80}
|
1355
|
-
You are running rspec-2, but it seems as though rspec-1 has been loaded as
|
1356
|
-
well. This is likely due to a statement like this somewhere in the specs:
|
1357
|
-
|
1358
|
-
require 'spec'
|
1359
|
-
|
1360
|
-
Please locate that statement, remove it, and try again.
|
1361
|
-
#{'*'*80}
|
1362
|
-
MESSAGE
|
1363
|
-
end
|
1364
|
-
end
|
1365
|
-
|
1366
1067
|
def output_to_tty?(output=output_stream)
|
1367
1068
|
tty? || (output.respond_to?(:tty?) && output.tty?)
|
1368
1069
|
end
|
1369
1070
|
|
1370
|
-
def
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1071
|
+
def built_in_formatter(key)
|
1072
|
+
case key.to_s
|
1073
|
+
when 'd', 'doc', 'documentation', 's', 'n', 'spec', 'nested'
|
1074
|
+
require 'rspec/core/formatters/documentation_formatter'
|
1075
|
+
RSpec::Core::Formatters::DocumentationFormatter
|
1076
|
+
when 'h', 'html'
|
1077
|
+
require 'rspec/core/formatters/html_formatter'
|
1078
|
+
RSpec::Core::Formatters::HtmlFormatter
|
1079
|
+
when 'p', 'progress'
|
1080
|
+
require 'rspec/core/formatters/progress_formatter'
|
1081
|
+
RSpec::Core::Formatters::ProgressFormatter
|
1082
|
+
when 'j', 'json'
|
1083
|
+
require 'rspec/core/formatters/json_formatter'
|
1084
|
+
RSpec::Core::Formatters::JsonFormatter
|
1085
|
+
end
|
1377
1086
|
end
|
1378
1087
|
|
1379
|
-
def
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
if order == 'default'
|
1388
|
-
RSpec.deprecate("RSpec::Core::Configuration#order = 'default'",
|
1389
|
-
:replacement => "RSpec::Core::Configuration#order = 'defined'")
|
1088
|
+
def custom_formatter(formatter_ref)
|
1089
|
+
if Class === formatter_ref
|
1090
|
+
formatter_ref
|
1091
|
+
elsif string_const?(formatter_ref)
|
1092
|
+
begin
|
1093
|
+
formatter_ref.gsub(/^::/,'').split('::').inject(Object) { |const,string| const.const_get string }
|
1094
|
+
rescue NameError
|
1095
|
+
require( path_for(formatter_ref) ) ? retry : raise
|
1390
1096
|
end
|
1391
|
-
|
1392
|
-
@order, @seed = nil, nil
|
1393
|
-
ordering = DEFAULT_ORDERING
|
1394
|
-
end
|
1395
|
-
|
1396
|
-
unless @ordering_already_forced
|
1397
|
-
@group_ordering_block = ordering
|
1398
|
-
@example_ordering_block = ordering
|
1399
1097
|
end
|
1400
|
-
@ordering_already_forced = true if force
|
1401
|
-
|
1402
|
-
return order, seed
|
1403
1098
|
end
|
1404
1099
|
|
1405
|
-
def
|
1406
|
-
|
1100
|
+
def string_const?(str)
|
1101
|
+
str.is_a?(String) && /\A[A-Z][a-zA-Z0-9_:]*\z/ =~ str
|
1407
1102
|
end
|
1408
1103
|
|
1409
|
-
def
|
1410
|
-
|
1411
|
-
RSpec.deprecate("`config.mock_with #{name.inspect}`", :replacement => "`config.mock_with :#{expected}`")
|
1104
|
+
def path_for(const_ref)
|
1105
|
+
underscore_with_fix_for_non_standard_rspec_naming(const_ref)
|
1412
1106
|
end
|
1413
1107
|
|
1414
|
-
def
|
1415
|
-
|
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
|
1108
|
+
def underscore_with_fix_for_non_standard_rspec_naming(string)
|
1109
|
+
underscore(string).sub(%r{(^|/)r_spec($|/)}, '\\1rspec\\2')
|
1110
|
+
end
|
1428
1111
|
|
1429
|
-
|
1112
|
+
# activesupport/lib/active_support/inflector/methods.rb, line 48
|
1113
|
+
def underscore(camel_cased_word)
|
1114
|
+
word = camel_cased_word.to_s.dup
|
1115
|
+
word.gsub!(/::/, '/')
|
1116
|
+
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
1117
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
1118
|
+
word.tr!("-", "_")
|
1119
|
+
word.downcase!
|
1120
|
+
word
|
1430
1121
|
end
|
1431
1122
|
|
1123
|
+
def file_at(path)
|
1124
|
+
FileUtils.mkdir_p(File.dirname(path))
|
1125
|
+
File.new(path, 'w')
|
1126
|
+
end
|
1432
1127
|
end
|
1433
1128
|
end
|
1434
1129
|
end
|