rspec-core 2.8.0.rc1 → 2.8.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/License.txt +24 -0
- data/README.md +197 -37
- data/features/command_line/format_option.feature +3 -3
- data/features/command_line/init.feature +18 -0
- data/features/example_groups/shared_examples.feature +1 -1
- data/features/hooks/around_hooks.feature +4 -4
- data/features/pending/pending_examples.feature +5 -5
- data/features/support/env.rb +8 -1
- data/lib/autotest/rspec2.rb +2 -6
- data/lib/rspec/core.rb +48 -158
- data/lib/rspec/core/backward_compatibility.rb +2 -0
- data/lib/rspec/core/command_line.rb +4 -0
- data/lib/rspec/core/configuration.rb +201 -106
- data/lib/rspec/core/configuration_options.rb +2 -1
- data/lib/rspec/core/deprecation.rb +2 -3
- data/lib/rspec/core/drb_options.rb +69 -58
- data/lib/rspec/core/dsl.rb +12 -0
- data/lib/rspec/core/example.rb +53 -18
- data/lib/rspec/core/example_group.rb +144 -54
- data/lib/rspec/core/extensions.rb +4 -4
- data/lib/rspec/core/extensions/instance_eval_with_args.rb +5 -0
- data/lib/rspec/core/extensions/kernel.rb +1 -1
- data/lib/rspec/core/extensions/module_eval_with_args.rb +4 -0
- data/lib/rspec/core/extensions/ordered.rb +7 -2
- data/lib/rspec/core/filter_manager.rb +69 -36
- data/lib/rspec/core/formatters/base_text_formatter.rb +1 -1
- data/lib/rspec/core/formatters/html_formatter.rb +10 -4
- data/lib/rspec/core/hooks.rb +93 -34
- data/lib/rspec/core/let.rb +62 -61
- data/lib/rspec/core/metadata.rb +103 -80
- data/lib/rspec/core/metadata_hash_builder.rb +4 -0
- data/lib/rspec/core/option_parser.rb +42 -44
- data/lib/rspec/core/pending.rb +25 -3
- data/lib/rspec/core/project_initializer.rb +62 -0
- data/lib/rspec/core/rake_task.rb +7 -13
- data/lib/rspec/core/runner.rb +2 -2
- data/lib/rspec/core/shared_context.rb +1 -1
- data/lib/rspec/core/shared_example_group.rb +11 -5
- data/lib/rspec/core/subject.rb +3 -3
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/monkey.rb +1 -1
- data/lib/rspec/monkey/spork/test_framework/rspec.rb +2 -0
- data/spec/command_line/order_spec.rb +19 -13
- data/spec/rspec/core/command_line_spec.rb +1 -5
- data/spec/rspec/core/configuration_options_spec.rb +22 -27
- data/spec/rspec/core/configuration_spec.rb +32 -14
- data/spec/rspec/core/drb_command_line_spec.rb +20 -37
- data/spec/rspec/core/drb_options_spec.rb +51 -3
- data/spec/rspec/core/example_group_spec.rb +101 -84
- data/spec/rspec/core/example_spec.rb +14 -0
- data/spec/rspec/core/filter_manager_spec.rb +114 -33
- data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +17 -69
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +14 -4
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +14 -4
- data/spec/rspec/core/formatters/html_formatted-1.9.3.html +14 -4
- data/spec/rspec/core/formatters/html_formatter_spec.rb +1 -1
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +20 -72
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +24 -14
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +29 -19
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +29 -19
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +1 -2
- data/spec/rspec/core/metadata_spec.rb +77 -45
- data/spec/rspec/core/option_parser_spec.rb +5 -0
- data/spec/rspec/core/pending_example_spec.rb +44 -12
- data/spec/rspec/core/project_initializer_spec.rb +130 -0
- data/spec/rspec/core/rake_task_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/support/matchers.rb +2 -12
- metadata +18 -16
- data/features/command_line/configure.feature +0 -22
- data/lib/rspec/core/command_line_configuration.rb +0 -62
- data/lib/rspec/core/errors.rb +0 -13
- data/spec/rspec/core/command_line_configuration_spec.rb +0 -26
data/lib/rspec/core.rb
CHANGED
@@ -1,56 +1,67 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
if defined?(require_relative)
|
2
|
+
# @private
|
3
|
+
def require_rspec(path)
|
4
|
+
require_relative path
|
5
|
+
end
|
6
|
+
else
|
7
|
+
# @private
|
8
|
+
def require_rspec(path)
|
9
|
+
require "rspec/#{path}"
|
10
|
+
end
|
11
|
+
end
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
require_rspec 'core/filter_manager'
|
14
|
+
require_rspec 'core/dsl'
|
15
|
+
require_rspec 'core/extensions'
|
16
|
+
require_rspec 'core/load_path'
|
17
|
+
require_rspec 'core/deprecation'
|
18
|
+
require_rspec 'core/backward_compatibility'
|
19
|
+
require_rspec 'core/reporter'
|
15
20
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
require_rspec 'core/metadata_hash_builder'
|
22
|
+
require_rspec 'core/hooks'
|
23
|
+
require_rspec 'core/subject'
|
24
|
+
require_rspec 'core/let'
|
25
|
+
require_rspec 'core/metadata'
|
26
|
+
require_rspec 'core/pending'
|
27
|
+
|
28
|
+
require_rspec 'core/world'
|
29
|
+
require_rspec 'core/configuration'
|
30
|
+
require_rspec 'core/project_initializer'
|
31
|
+
require_rspec 'core/option_parser'
|
32
|
+
require_rspec 'core/drb_options'
|
33
|
+
require_rspec 'core/configuration_options'
|
34
|
+
require_rspec 'core/command_line'
|
35
|
+
require_rspec 'core/drb_command_line'
|
36
|
+
require_rspec 'core/runner'
|
37
|
+
require_rspec 'core/example'
|
38
|
+
require_rspec 'core/shared_example_group'
|
39
|
+
require_rspec 'core/example_group'
|
40
|
+
require_rspec 'core/version'
|
30
41
|
|
31
42
|
module RSpec
|
32
43
|
autoload :Matchers, 'rspec/matchers'
|
33
44
|
autoload :SharedContext, 'rspec/core/shared_context'
|
34
45
|
|
35
|
-
# @
|
36
|
-
# Used internally to determine what to do when a SIGINT is received
|
46
|
+
# @private
|
37
47
|
def self.wants_to_quit
|
48
|
+
# Used internally to determine what to do when a SIGINT is received
|
38
49
|
world.wants_to_quit
|
39
50
|
end
|
40
51
|
|
41
|
-
# @
|
52
|
+
# @private
|
42
53
|
# Used internally to determine what to do when a SIGINT is received
|
43
54
|
def self.wants_to_quit=(maybe)
|
44
55
|
world.wants_to_quit=(maybe)
|
45
56
|
end
|
46
57
|
|
47
|
-
# @
|
58
|
+
# @private
|
48
59
|
# Internal container for global non-configuration data
|
49
60
|
def self.world
|
50
61
|
@world ||= RSpec::Core::World.new
|
51
62
|
end
|
52
63
|
|
53
|
-
# @
|
64
|
+
# @private
|
54
65
|
# Used internally to ensure examples get reloaded between multiple runs in
|
55
66
|
# the same process.
|
56
67
|
def self.reset
|
@@ -58,7 +69,7 @@ module RSpec
|
|
58
69
|
configuration.reset
|
59
70
|
end
|
60
71
|
|
61
|
-
# Returns the global [Configuration](Core/Configuration) object. While you
|
72
|
+
# Returns the global [Configuration](RSpec/Core/Configuration) object. While you
|
62
73
|
# _can_ use this method to access the configuration, the more common
|
63
74
|
# convention is to use [RSpec.configure](RSpec#configure-class_method).
|
64
75
|
#
|
@@ -70,6 +81,7 @@ module RSpec
|
|
70
81
|
@configuration ||= RSpec::Core::Configuration.new
|
71
82
|
end
|
72
83
|
|
84
|
+
# Yields the global configuration to a block.
|
73
85
|
# @yield [Configuration] global configuration
|
74
86
|
#
|
75
87
|
# @example
|
@@ -81,137 +93,15 @@ module RSpec
|
|
81
93
|
yield configuration if block_given?
|
82
94
|
end
|
83
95
|
|
84
|
-
# @
|
96
|
+
# @private
|
85
97
|
# Used internally to clear remaining groups when fail_fast is set
|
86
98
|
def self.clear_remaining_example_groups
|
87
99
|
world.example_groups.clear
|
88
100
|
end
|
89
101
|
|
90
|
-
# rspec-core provides the structure for writing executable examples of how
|
91
|
-
# your code should behave. It uses the words "describe" and "it" so we can
|
92
|
-
# express concepts like a conversation:
|
93
|
-
#
|
94
|
-
# "Describe an order."
|
95
|
-
# "It sums the prices of its line items."
|
96
|
-
#
|
97
|
-
# ## Basic structure
|
98
|
-
#
|
99
|
-
# describe Order do
|
100
|
-
# it "sums the prices of its line items" do
|
101
|
-
# order = Order.new
|
102
|
-
# order.add_entry(LineItem.new(:item => Item.new(
|
103
|
-
# :price => Money.new(1.11, :USD)
|
104
|
-
# )
|
105
|
-
# order.add_entry(LineItem.new(:item => Item.new(
|
106
|
-
# :price => Money.new(2.22, :USD),
|
107
|
-
# :quantity => 2
|
108
|
-
# )
|
109
|
-
# order.total.should eq(Money.new(5.55, :USD))
|
110
|
-
# end
|
111
|
-
# end
|
112
|
-
#
|
113
|
-
# The `describe` method creates an [ExampleGroup](Core/ExampleGroup). Within the
|
114
|
-
# block passed to `describe` you can declare examples using the `it` method.
|
115
|
-
#
|
116
|
-
# Under the hood, an example group is a class in which the block passed to
|
117
|
-
# `describe` is evaluated. The blocks passed to `it` are evaluated in the
|
118
|
-
# context of an _instance_ of that class.
|
119
|
-
#
|
120
|
-
# ## Nested groups
|
121
|
-
#
|
122
|
-
# You can also declare nested nested groups using the `describe` or `context`
|
123
|
-
# methods:
|
124
|
-
#
|
125
|
-
# describe Order to
|
126
|
-
# context "with no items" do
|
127
|
-
# it "behaves one way" do
|
128
|
-
# # ...
|
129
|
-
# end
|
130
|
-
# end
|
131
|
-
#
|
132
|
-
# context "with one item" do
|
133
|
-
# it "behaves another way" do
|
134
|
-
# # ...
|
135
|
-
# end
|
136
|
-
# end
|
137
|
-
# end
|
138
|
-
#
|
139
|
-
# ## Aliases
|
140
|
-
#
|
141
|
-
# You can declare example groups using either `describe` or `context`, though
|
142
|
-
# only `describe` is available at the top level.
|
143
|
-
#
|
144
|
-
# You can declare examples within a group using any of `it`, `specify`, or
|
145
|
-
# `example`.
|
146
|
-
#
|
147
|
-
# ## Shared examples
|
148
|
-
#
|
149
|
-
# Declare a shared example group using `shared_examples`, and then include it
|
150
|
-
# in each group using `include_examples`.
|
151
|
-
#
|
152
|
-
# shared_examples "collections" do |collection_class|
|
153
|
-
# it "is empty when first created" do
|
154
|
-
# collection_class.new.should be_empty
|
155
|
-
# end
|
156
|
-
# end
|
157
|
-
#
|
158
|
-
# describe Array do
|
159
|
-
# include_examples "collections", Array
|
160
|
-
# end
|
161
|
-
#
|
162
|
-
# ## Metadata
|
163
|
-
#
|
164
|
-
# rspec-core stores a metadata hash with every example and group, which
|
165
|
-
# contains like their descriptions, the locations at which they were
|
166
|
-
# declared, etc, etc. This hash powers many of rspec-core's features,
|
167
|
-
# including output formatters (which access descriptions and locations),
|
168
|
-
# and filtering before and after hooks.
|
169
|
-
#
|
170
|
-
# Although you probably won't ever need this unless you are writing an
|
171
|
-
# extension, you can access it from an example like this:
|
172
|
-
#
|
173
|
-
# it "does something" do
|
174
|
-
# example.metadata[:description].should eq("does something")
|
175
|
-
# end
|
176
|
-
#
|
177
|
-
# ### `described_class`
|
178
|
-
#
|
179
|
-
# When a class is passed to `describe`, you can access it from an example
|
180
|
-
# using the `described_class` method, which is a wrapper for
|
181
|
-
# `example.metadata[:described_class]`.
|
182
|
-
#
|
183
|
-
# describe Widget do
|
184
|
-
# example do
|
185
|
-
# described_class.should equal(Widget)
|
186
|
-
# end
|
187
|
-
# end
|
188
|
-
#
|
189
|
-
# This is useful in extensions or shared example groups in which the specific
|
190
|
-
# class is unknown. Taking the shared examples example from above, we can
|
191
|
-
# clean it up a bit using `described_class`:
|
192
|
-
#
|
193
|
-
# shared_examples "collections" do
|
194
|
-
# it "is empty when first created" do
|
195
|
-
# described.new.should be_empty
|
196
|
-
# end
|
197
|
-
# end
|
198
|
-
#
|
199
|
-
# describe Array do
|
200
|
-
# include_examples "collections"
|
201
|
-
# end
|
202
|
-
#
|
203
|
-
# describe Hash do
|
204
|
-
# include_examples "collections"
|
205
|
-
# end
|
206
|
-
#
|
207
|
-
# ## The `rspec` command
|
208
|
-
#
|
209
|
-
# When you install the rspec-core gem, it installs the `rspec` executable,
|
210
|
-
# which you'll use to run rspec. The `rspec` comes with many useful options.
|
211
|
-
# Run `rspec --help` to see the complete list.
|
212
102
|
module Core
|
213
103
|
end
|
214
104
|
end
|
215
105
|
|
216
|
-
|
217
|
-
|
106
|
+
require_rspec 'core/backward_compatibility'
|
107
|
+
require_rspec 'monkey'
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Core
|
3
|
+
# @private
|
3
4
|
module ConstMissing
|
4
5
|
# Used to print deprecation warnings for Rspec and Spec constants (use
|
5
6
|
# RSpec instead)
|
@@ -38,6 +39,7 @@ WARNING
|
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
42
|
+
# @private
|
41
43
|
module Rake
|
42
44
|
# Used to print deprecation warnings for Rake::SpecTask constant (use
|
43
45
|
# RSpec::Core::RakeTask instead)
|
@@ -7,7 +7,9 @@ module RSpec
|
|
7
7
|
#
|
8
8
|
# @example Standard settings
|
9
9
|
# RSpec.configure do |c|
|
10
|
-
# c.
|
10
|
+
# c.drb = true
|
11
|
+
# c.drb_port = 1234
|
12
|
+
# c.default_path = 'behavior'
|
11
13
|
# end
|
12
14
|
#
|
13
15
|
# @example Hooks
|
@@ -24,60 +26,147 @@ module RSpec
|
|
24
26
|
|
25
27
|
class MustBeConfiguredBeforeExampleGroupsError < StandardError; end
|
26
28
|
|
29
|
+
# @private
|
30
|
+
def self.define_reader(name)
|
31
|
+
eval <<-CODE
|
32
|
+
def #{name}
|
33
|
+
value_for(#{name.inspect}, defined?(@#{name}) ? @#{name} : nil)
|
34
|
+
end
|
35
|
+
CODE
|
36
|
+
end
|
37
|
+
|
38
|
+
# @private
|
39
|
+
def self.deprecate_alias_key
|
40
|
+
RSpec.warn_deprecation <<-MESSAGE
|
41
|
+
The :alias option to add_setting is deprecated. Use :alias_with on the original setting instead.
|
42
|
+
Called from #{caller(0)[5]}
|
43
|
+
MESSAGE
|
44
|
+
end
|
45
|
+
|
46
|
+
# @private
|
47
|
+
def self.define_aliases(name, alias_name)
|
48
|
+
alias_method alias_name, name
|
49
|
+
alias_method "#{alias_name}=", "#{name}="
|
50
|
+
define_predicate_for alias_name
|
51
|
+
end
|
52
|
+
|
53
|
+
# @private
|
27
54
|
def self.define_predicate_for(*names)
|
28
55
|
names.each {|name| alias_method "#{name}?", name}
|
29
56
|
end
|
30
57
|
|
31
|
-
# @
|
58
|
+
# @private
|
32
59
|
#
|
33
60
|
# Invoked by the `add_setting` instance method. Use that method on a
|
34
61
|
# `Configuration` instance rather than this class method.
|
35
62
|
def self.add_setting(name, opts={})
|
36
63
|
raise "Use the instance add_setting method if you want to set a default" if opts.has_key?(:default)
|
37
64
|
if opts[:alias]
|
38
|
-
|
39
|
-
|
40
|
-
Called from #{caller(0)[4]}
|
41
|
-
MESSAGE
|
42
|
-
alias_method name, opts[:alias]
|
43
|
-
alias_method "#{name}=", "#{opts[:alias]}="
|
44
|
-
define_predicate_for name
|
65
|
+
deprecate_alias_key
|
66
|
+
define_aliases(opts[:alias], name)
|
45
67
|
else
|
46
68
|
attr_writer name
|
47
|
-
|
48
|
-
def #{name}
|
49
|
-
value_for(#{name.inspect}, defined?(@#{name}) ? @#{name} : nil)
|
50
|
-
end
|
51
|
-
CODE
|
69
|
+
define_reader name
|
52
70
|
define_predicate_for name
|
53
71
|
end
|
54
|
-
|
55
|
-
|
56
|
-
alias_method alias_name, name
|
57
|
-
alias_method "#{alias_name}=", "#{name}="
|
58
|
-
define_predicate_for alias_name
|
59
|
-
end
|
72
|
+
[opts[:alias_with]].flatten.compact.each do |alias_name|
|
73
|
+
define_aliases(name, alias_name)
|
60
74
|
end
|
61
75
|
end
|
62
76
|
|
63
|
-
add_setting
|
64
|
-
|
77
|
+
# @macro [attach] add_setting
|
78
|
+
# @attribute $1
|
79
|
+
# Patterns to match against lines in backtraces presented in failure
|
80
|
+
# messages in order to filter them out (default:
|
81
|
+
# DEFAULT_BACKTRACE_PATTERNS). You can either replace this list using
|
82
|
+
# the setter or modify it using the getter.
|
83
|
+
#
|
84
|
+
# To override this behavior and display a full backtrace, use
|
85
|
+
# `--backtrace` on the command line, in a `.rspec` file, or in the
|
86
|
+
# `rspec_options` attribute of RSpec's rake task.
|
87
|
+
add_setting :backtrace_clean_patterns
|
88
|
+
|
89
|
+
# Path to use if no path is provided to the `rspec` command (default:
|
90
|
+
# `"spec"`). Allows you to just type `rspec` instead of `rspec spec` to
|
91
|
+
# run all the examples in the `spec` directory.
|
92
|
+
add_setting :default_path
|
93
|
+
|
94
|
+
# Run examples over DRb (default: `false`). RSpec doesn't supply the DRb
|
95
|
+
# server, but you can use tools like spork.
|
65
96
|
add_setting :drb
|
97
|
+
|
98
|
+
# The drb_port (default: `8989`).
|
66
99
|
add_setting :drb_port
|
67
|
-
|
100
|
+
|
101
|
+
# Default: `$stderr`.
|
102
|
+
add_setting :error_stream
|
103
|
+
|
104
|
+
# Clean up and exit after the first failure (default: `false`).
|
68
105
|
add_setting :fail_fast
|
106
|
+
|
107
|
+
# The exit code to return if there are any failures (default: 1).
|
69
108
|
add_setting :failure_exit_code
|
70
|
-
|
109
|
+
|
110
|
+
# Determines the order in which examples are run (default: OS standard
|
111
|
+
# load order for files, declaration order for groups and examples).
|
112
|
+
define_reader :order
|
113
|
+
|
114
|
+
# Default: `$stdout`.
|
115
|
+
# Also known as `output` and `out`
|
116
|
+
add_setting :output_stream, :alias_with => [:output, :out]
|
117
|
+
|
118
|
+
# Load files matching this pattern (default: `'**/*_spec.rb'`)
|
71
119
|
add_setting :pattern, :alias_with => :filename_pattern
|
72
|
-
|
73
|
-
|
74
|
-
add_setting :
|
75
|
-
|
120
|
+
|
121
|
+
# Report the times for the 10 slowest examples (default: `false`).
|
122
|
+
add_setting :profile_examples
|
123
|
+
|
124
|
+
# Run all examples if none match the configured filters (default: `false`).
|
125
|
+
add_setting :run_all_when_everything_filtered
|
126
|
+
|
127
|
+
# Seed for random ordering (default: generated randomly each run).
|
128
|
+
#
|
129
|
+
# When you run specs with `--order random`, RSpec generates a random seed
|
130
|
+
# for the randomization and prints it to the `output_stream` (assuming
|
131
|
+
# you're using RSpec's built-in formatters). If you discover an ordering
|
132
|
+
# dependency (i.e. examples fail intermittently depending on order), set
|
133
|
+
# this (on Configuration or on the command line with `--seed`) to run
|
134
|
+
# using the same seed while you debug the issue.
|
135
|
+
#
|
136
|
+
# We recommend, actually, that you use the command line approach so you
|
137
|
+
# don't accidentally leave the seed encoded.
|
138
|
+
define_reader :seed
|
139
|
+
|
140
|
+
# When a block passed to pending fails (as expected), display the failure
|
141
|
+
# without reporting it as a failure (default: false).
|
142
|
+
add_setting :show_failures_in_pending_blocks
|
143
|
+
|
144
|
+
# Convert symbols to hashes with the symbol as a key with a value of
|
145
|
+
# `true` (default: false).
|
146
|
+
#
|
147
|
+
# This allows you to tag a group or example like this:
|
148
|
+
#
|
149
|
+
# describe "something slow", :slow do
|
150
|
+
# # ...
|
151
|
+
# end
|
152
|
+
#
|
153
|
+
# ... instead of having to type:
|
154
|
+
#
|
155
|
+
# describe "something slow", :slow => true do
|
156
|
+
# # ...
|
157
|
+
# end
|
76
158
|
add_setting :treat_symbols_as_metadata_keys_with_true_values
|
159
|
+
|
160
|
+
# @private
|
161
|
+
add_setting :tty
|
162
|
+
# @private
|
163
|
+
add_setting :include_or_extend_modules
|
164
|
+
# @private
|
165
|
+
add_setting :files_to_run
|
166
|
+
# @private
|
77
167
|
add_setting :expecting_with_rspec
|
78
|
-
|
79
|
-
|
80
|
-
add_setting :order
|
168
|
+
# @private
|
169
|
+
attr_accessor :filter_manager
|
81
170
|
|
82
171
|
DEFAULT_BACKTRACE_PATTERNS = [
|
83
172
|
/\/lib\d*\/ruby\//,
|
@@ -104,27 +193,39 @@ MESSAGE
|
|
104
193
|
@seed = srand % 0xFFFF
|
105
194
|
end
|
106
195
|
|
107
|
-
|
108
|
-
|
196
|
+
# @private
|
197
|
+
#
|
198
|
+
# Used to set higher priority option values from the command line.
|
109
199
|
def force(hash)
|
200
|
+
if hash.has_key?(:seed)
|
201
|
+
hash[:order], hash[:seed] = order_and_seed_from_seed(hash[:seed])
|
202
|
+
elsif hash.has_key?(:order)
|
203
|
+
set_order_and_seed(hash)
|
204
|
+
end
|
110
205
|
@preferred_options.merge!(hash)
|
111
206
|
end
|
112
207
|
|
113
|
-
|
114
|
-
filter_manager.include hash
|
115
|
-
end
|
116
|
-
|
117
|
-
def force_exclude(hash)
|
118
|
-
filter_manager.exclude hash
|
119
|
-
end
|
120
|
-
|
208
|
+
# @api private
|
121
209
|
def reset
|
122
210
|
@reporter = nil
|
123
211
|
@formatters.clear
|
124
212
|
end
|
125
213
|
|
126
214
|
# @overload add_setting(name)
|
127
|
-
# @overload add_setting(name,
|
215
|
+
# @overload add_setting(name, opts)
|
216
|
+
# @option opts [Symbol] :default
|
217
|
+
#
|
218
|
+
# set a default value for the generated getter and predicate methods:
|
219
|
+
#
|
220
|
+
# add_setting(:foo, :default => "default value")
|
221
|
+
#
|
222
|
+
# @option opts [Symbol] :alias_with
|
223
|
+
#
|
224
|
+
# Use `:alias_with` to alias the setter, getter, and predicate to another
|
225
|
+
# name, or names:
|
226
|
+
#
|
227
|
+
# add_setting(:foo, :alias_with => :bar)
|
228
|
+
# add_setting(:foo, :alias_with => [:bar, :baz])
|
128
229
|
#
|
129
230
|
# Adds a custom setting to the RSpec.configuration object.
|
130
231
|
#
|
@@ -145,23 +246,6 @@ MESSAGE
|
|
145
246
|
# RSpec.configuration.foo=(value)
|
146
247
|
# RSpec.configuration.foo
|
147
248
|
# RSpec.configuration.foo? # returns true if foo returns anything but nil or false
|
148
|
-
#
|
149
|
-
# ### Options
|
150
|
-
#
|
151
|
-
# `add_setting` takes an optional hash that supports the keys `:default`
|
152
|
-
# and `:alias_with`.
|
153
|
-
#
|
154
|
-
# Use `:default` to set a default value for the generated getter and
|
155
|
-
# predicate methods:
|
156
|
-
#
|
157
|
-
# add_setting(:foo, :default => "default value")
|
158
|
-
#
|
159
|
-
# Use `:alias_with` to alias the setter, getter, and predicate to another
|
160
|
-
# name, or names:
|
161
|
-
#
|
162
|
-
# add_setting(:foo, :alias_with => :bar)
|
163
|
-
# add_setting(:foo, :alias_with => [:bar, :baz])
|
164
|
-
#
|
165
249
|
def add_setting(name, opts={})
|
166
250
|
default = opts.delete(:default)
|
167
251
|
(class << self; self; end).class_eval do
|
@@ -384,35 +468,6 @@ EOM
|
|
384
468
|
self.files_to_run = get_files_to_run(files)
|
385
469
|
end
|
386
470
|
|
387
|
-
# @api private
|
388
|
-
def command
|
389
|
-
$0.split(File::SEPARATOR).last
|
390
|
-
end
|
391
|
-
|
392
|
-
# @api private
|
393
|
-
def get_files_to_run(files)
|
394
|
-
patterns = pattern.split(",")
|
395
|
-
files.map do |file|
|
396
|
-
if File.directory?(file)
|
397
|
-
patterns.map do |pattern|
|
398
|
-
if pattern =~ /^#{file}/
|
399
|
-
Dir[pattern.strip]
|
400
|
-
else
|
401
|
-
Dir["#{file}/{#{pattern.strip}}"]
|
402
|
-
end
|
403
|
-
end
|
404
|
-
else
|
405
|
-
if file =~ /^(.*?)((?:\:\d+)+)$/
|
406
|
-
path, lines = $1, $2[1..-1].split(":").map{|n| n.to_i}
|
407
|
-
filter_manager.add_location path, lines
|
408
|
-
path
|
409
|
-
else
|
410
|
-
file
|
411
|
-
end
|
412
|
-
end
|
413
|
-
end.flatten
|
414
|
-
end
|
415
|
-
|
416
471
|
# Creates a method that delegates to `example` including the submitted
|
417
472
|
# `args`. Used internally to add variants of `example` like `pending`:
|
418
473
|
#
|
@@ -480,7 +535,7 @@ EOM
|
|
480
535
|
# # with treat_symbols_as_metadata_keys_with_true_values = true
|
481
536
|
# filter_run_including :foo # results in {:foo => true}
|
482
537
|
def filter_run_including(*args)
|
483
|
-
filter_manager.
|
538
|
+
filter_manager.include_with_low_priority build_metadata_hash_from(args)
|
484
539
|
end
|
485
540
|
|
486
541
|
alias_method :filter_run, :filter_run_including
|
@@ -493,7 +548,7 @@ EOM
|
|
493
548
|
# This overrides any inclusion filters/tags set on the command line or in
|
494
549
|
# configuration files.
|
495
550
|
def inclusion_filter=(filter)
|
496
|
-
filter_manager.include
|
551
|
+
filter_manager.include! build_metadata_hash_from([filter])
|
497
552
|
end
|
498
553
|
|
499
554
|
alias_method :filter=, :inclusion_filter=
|
@@ -522,7 +577,7 @@ EOM
|
|
522
577
|
# # with treat_symbols_as_metadata_keys_with_true_values = true
|
523
578
|
# filter_run_excluding :foo # results in {:foo => true}
|
524
579
|
def filter_run_excluding(*args)
|
525
|
-
filter_manager.
|
580
|
+
filter_manager.exclude_with_low_priority build_metadata_hash_from(args)
|
526
581
|
end
|
527
582
|
|
528
583
|
# Clears and reassigns the `exclusion_filter`. Set to `nil` if you don't
|
@@ -533,7 +588,7 @@ EOM
|
|
533
588
|
# This overrides any exclusion filters/tags set on the command line or in
|
534
589
|
# configuration files.
|
535
590
|
def exclusion_filter=(filter)
|
536
|
-
filter_manager.exclude
|
591
|
+
filter_manager.exclude! build_metadata_hash_from([filter])
|
537
592
|
end
|
538
593
|
|
539
594
|
# Returns the `exclusion_filter`. If none has been set, returns an empty
|
@@ -563,45 +618,68 @@ EOM
|
|
563
618
|
end
|
564
619
|
end
|
565
620
|
|
621
|
+
# @api private
|
566
622
|
def configure_mock_framework
|
567
623
|
RSpec::Core::ExampleGroup.send(:include, mock_framework)
|
568
624
|
end
|
569
625
|
|
626
|
+
# @api private
|
570
627
|
def configure_expectation_framework
|
571
628
|
expectation_frameworks.each do |framework|
|
572
629
|
RSpec::Core::ExampleGroup.send(:include, framework)
|
573
630
|
end
|
574
631
|
end
|
575
632
|
|
633
|
+
# @api private
|
576
634
|
def load_spec_files
|
577
635
|
files_to_run.map {|f| load File.expand_path(f) }
|
578
636
|
raise_if_rspec_1_is_loaded
|
579
637
|
end
|
580
638
|
|
581
|
-
|
582
|
-
|
639
|
+
# @api
|
640
|
+
#
|
641
|
+
# Sets the seed value and sets `order='rand'`
|
583
642
|
def seed=(seed)
|
584
|
-
|
585
|
-
|
643
|
+
order_and_seed_from_seed(seed)
|
644
|
+
end
|
645
|
+
|
646
|
+
# @api
|
647
|
+
#
|
648
|
+
# Sets the order and, if order is `'rand:<seed>'`, also sets the seed.
|
649
|
+
def order=(type)
|
650
|
+
order_and_seed_from_order(type)
|
586
651
|
end
|
587
652
|
|
588
653
|
def randomize?
|
589
654
|
order.to_s.match(/rand/)
|
590
655
|
end
|
591
656
|
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
657
|
+
private
|
658
|
+
|
659
|
+
def get_files_to_run(paths)
|
660
|
+
patterns = pattern.split(",")
|
661
|
+
paths.map do |path|
|
662
|
+
File.directory?(path) ? gather_directories(path, patterns) : extract_location(path)
|
663
|
+
end.flatten
|
664
|
+
end
|
665
|
+
|
666
|
+
def gather_directories(path, patterns)
|
667
|
+
patterns.map do |pattern|
|
668
|
+
pattern =~ /^#{path}/ ? Dir[pattern.strip] : Dir["#{path}/{#{pattern.strip}}"]
|
601
669
|
end
|
602
670
|
end
|
603
671
|
|
604
|
-
|
672
|
+
def extract_location(path)
|
673
|
+
if path =~ /^(.*?)((?:\:\d+)+)$/
|
674
|
+
path, lines = $1, $2[1..-1].split(":").map{|n| n.to_i}
|
675
|
+
filter_manager.add_location path, lines
|
676
|
+
end
|
677
|
+
path
|
678
|
+
end
|
679
|
+
|
680
|
+
def command
|
681
|
+
$0.split(File::SEPARATOR).last
|
682
|
+
end
|
605
683
|
|
606
684
|
def value_for(key, default=nil)
|
607
685
|
@preferred_options.has_key?(key) ? @preferred_options[key] : default
|
@@ -698,6 +776,23 @@ MESSAGE
|
|
698
776
|
File.new(path, 'w')
|
699
777
|
end
|
700
778
|
|
779
|
+
def order_and_seed_from_seed(value)
|
780
|
+
@order, @seed = 'rand', value.to_i
|
781
|
+
end
|
782
|
+
|
783
|
+
def set_order_and_seed(hash)
|
784
|
+
hash[:order], seed = order_and_seed_from_order(hash[:order])
|
785
|
+
hash[:seed] = seed if seed
|
786
|
+
end
|
787
|
+
|
788
|
+
def order_and_seed_from_order(type)
|
789
|
+
order, seed = type.to_s.split(':')
|
790
|
+
@order = order
|
791
|
+
@seed = seed = seed.to_i if seed
|
792
|
+
@order, @seed = nil, nil if order == 'default'
|
793
|
+
return order, seed
|
794
|
+
end
|
795
|
+
|
701
796
|
end
|
702
797
|
end
|
703
798
|
end
|