opal-rspec-cj 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.gitmodules +15 -0
- data/.travis.yml +13 -0
- data/.yardopts +5 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +8 -0
- data/README.md +147 -0
- data/Rakefile +26 -0
- data/config.ru +10 -0
- data/example/Gemfile +4 -0
- data/example/README.md +13 -0
- data/example/Rakefile +8 -0
- data/example/opal/user.rb +11 -0
- data/example/spec/user_spec.rb +15 -0
- data/lib/opal-rspec.rb +2 -0
- data/lib/opal/rspec.rb +20 -0
- data/lib/opal/rspec/rake_task.rb +63 -0
- data/lib/opal/rspec/version.rb +5 -0
- data/opal-rspec.gemspec +21 -0
- data/opal/opal-rspec.rb +1 -0
- data/opal/opal/rspec.rb +25 -0
- data/opal/opal/rspec/async.rb +289 -0
- data/opal/opal/rspec/browser_formatter.rb +188 -0
- data/opal/opal/rspec/fixes.rb +116 -0
- data/opal/opal/rspec/requires.rb +45 -0
- data/opal/opal/rspec/runner.rb +69 -0
- data/opal/opal/rspec/sprockets_runner.rb.erb +11 -0
- data/opal/opal/rspec/text_formatter.rb +74 -0
- data/spec/async_spec.rb +38 -0
- data/spec/example_spec.rb +163 -0
- data/spec/matchers_spec.rb +201 -0
- data/spec/mock_spec.rb +63 -0
- data/spec/named_subject_spec.rb +11 -0
- data/spec/should_syntax_spec.rb +17 -0
- data/vendor/spec_runner.js +50 -0
- data/vendor_lib/rspec-expectations.rb +1 -0
- data/vendor_lib/rspec.rb +3 -0
- data/vendor_lib/rspec/autorun.rb +2 -0
- data/vendor_lib/rspec/core.rb +203 -0
- data/vendor_lib/rspec/core/backport_random.rb +302 -0
- data/vendor_lib/rspec/core/backtrace_formatter.rb +65 -0
- data/vendor_lib/rspec/core/command_line.rb +36 -0
- data/vendor_lib/rspec/core/configuration.rb +1129 -0
- data/vendor_lib/rspec/core/configuration_options.rb +143 -0
- data/vendor_lib/rspec/core/drb_command_line.rb +26 -0
- data/vendor_lib/rspec/core/drb_options.rb +87 -0
- data/vendor_lib/rspec/core/dsl.rb +26 -0
- data/vendor_lib/rspec/core/example.rb +312 -0
- data/vendor_lib/rspec/core/example_group.rb +540 -0
- data/vendor_lib/rspec/core/filter_manager.rb +224 -0
- data/vendor_lib/rspec/core/flat_map.rb +17 -0
- data/vendor_lib/rspec/core/formatters.rb +54 -0
- data/vendor_lib/rspec/core/formatters/base_formatter.rb +291 -0
- data/vendor_lib/rspec/core/formatters/base_text_formatter.rb +307 -0
- data/vendor_lib/rspec/core/formatters/deprecation_formatter.rb +193 -0
- data/vendor_lib/rspec/core/formatters/documentation_formatter.rb +67 -0
- data/vendor_lib/rspec/core/formatters/helpers.rb +82 -0
- data/vendor_lib/rspec/core/formatters/html_formatter.rb +155 -0
- data/vendor_lib/rspec/core/formatters/html_printer.rb +408 -0
- data/vendor_lib/rspec/core/formatters/json_formatter.rb +99 -0
- data/vendor_lib/rspec/core/formatters/progress_formatter.rb +32 -0
- data/vendor_lib/rspec/core/formatters/snippet_extractor.rb +101 -0
- data/vendor_lib/rspec/core/hooks.rb +535 -0
- data/vendor_lib/rspec/core/memoized_helpers.rb +431 -0
- data/vendor_lib/rspec/core/metadata.rb +313 -0
- data/vendor_lib/rspec/core/mocking/with_absolutely_nothing.rb +11 -0
- data/vendor_lib/rspec/core/mocking/with_flexmock.rb +27 -0
- data/vendor_lib/rspec/core/mocking/with_mocha.rb +52 -0
- data/vendor_lib/rspec/core/mocking/with_rr.rb +27 -0
- data/vendor_lib/rspec/core/mocking/with_rspec.rb +27 -0
- data/vendor_lib/rspec/core/option_parser.rb +234 -0
- data/vendor_lib/rspec/core/ordering.rb +154 -0
- data/vendor_lib/rspec/core/pending.rb +110 -0
- data/vendor_lib/rspec/core/project_initializer.rb +88 -0
- data/vendor_lib/rspec/core/rake_task.rb +128 -0
- data/vendor_lib/rspec/core/reporter.rb +132 -0
- data/vendor_lib/rspec/core/ruby_project.rb +44 -0
- data/vendor_lib/rspec/core/runner.rb +97 -0
- data/vendor_lib/rspec/core/shared_context.rb +53 -0
- data/vendor_lib/rspec/core/shared_example_group.rb +146 -0
- data/vendor_lib/rspec/core/shared_example_group/collection.rb +27 -0
- data/vendor_lib/rspec/core/version.rb +7 -0
- data/vendor_lib/rspec/core/warnings.rb +22 -0
- data/vendor_lib/rspec/core/world.rb +131 -0
- data/vendor_lib/rspec/expectations.rb +75 -0
- data/vendor_lib/rspec/expectations/differ.rb +154 -0
- data/vendor_lib/rspec/expectations/errors.rb +9 -0
- data/vendor_lib/rspec/expectations/expectation_target.rb +87 -0
- data/vendor_lib/rspec/expectations/extensions.rb +1 -0
- data/vendor_lib/rspec/expectations/extensions/object.rb +29 -0
- data/vendor_lib/rspec/expectations/fail_with.rb +79 -0
- data/vendor_lib/rspec/expectations/handler.rb +68 -0
- data/vendor_lib/rspec/expectations/syntax.rb +182 -0
- data/vendor_lib/rspec/expectations/version.rb +8 -0
- data/vendor_lib/rspec/matchers.rb +633 -0
- data/vendor_lib/rspec/matchers/built_in.rb +39 -0
- data/vendor_lib/rspec/matchers/built_in/base_matcher.rb +68 -0
- data/vendor_lib/rspec/matchers/built_in/be.rb +213 -0
- data/vendor_lib/rspec/matchers/built_in/be_instance_of.rb +15 -0
- data/vendor_lib/rspec/matchers/built_in/be_kind_of.rb +11 -0
- data/vendor_lib/rspec/matchers/built_in/be_within.rb +55 -0
- data/vendor_lib/rspec/matchers/built_in/change.rb +141 -0
- data/vendor_lib/rspec/matchers/built_in/cover.rb +21 -0
- data/vendor_lib/rspec/matchers/built_in/eq.rb +22 -0
- data/vendor_lib/rspec/matchers/built_in/eql.rb +23 -0
- data/vendor_lib/rspec/matchers/built_in/equal.rb +48 -0
- data/vendor_lib/rspec/matchers/built_in/exist.rb +26 -0
- data/vendor_lib/rspec/matchers/built_in/has.rb +48 -0
- data/vendor_lib/rspec/matchers/built_in/include.rb +61 -0
- data/vendor_lib/rspec/matchers/built_in/match.rb +17 -0
- data/vendor_lib/rspec/matchers/built_in/match_array.rb +51 -0
- data/vendor_lib/rspec/matchers/built_in/raise_error.rb +154 -0
- data/vendor_lib/rspec/matchers/built_in/respond_to.rb +74 -0
- data/vendor_lib/rspec/matchers/built_in/satisfy.rb +30 -0
- data/vendor_lib/rspec/matchers/built_in/start_and_end_with.rb +48 -0
- data/vendor_lib/rspec/matchers/built_in/throw_symbol.rb +94 -0
- data/vendor_lib/rspec/matchers/built_in/yield.rb +297 -0
- data/vendor_lib/rspec/matchers/compatibility.rb +14 -0
- data/vendor_lib/rspec/matchers/configuration.rb +113 -0
- data/vendor_lib/rspec/matchers/dsl.rb +23 -0
- data/vendor_lib/rspec/matchers/generated_descriptions.rb +35 -0
- data/vendor_lib/rspec/matchers/matcher.rb +301 -0
- data/vendor_lib/rspec/matchers/method_missing.rb +12 -0
- data/vendor_lib/rspec/matchers/operator_matcher.rb +99 -0
- data/vendor_lib/rspec/matchers/pretty.rb +70 -0
- data/vendor_lib/rspec/matchers/test_unit_integration.rb +11 -0
- data/vendor_lib/rspec/mocks.rb +100 -0
- data/vendor_lib/rspec/mocks/any_instance/chain.rb +92 -0
- data/vendor_lib/rspec/mocks/any_instance/expectation_chain.rb +47 -0
- data/vendor_lib/rspec/mocks/any_instance/message_chains.rb +75 -0
- data/vendor_lib/rspec/mocks/any_instance/recorder.rb +200 -0
- data/vendor_lib/rspec/mocks/any_instance/stub_chain.rb +45 -0
- data/vendor_lib/rspec/mocks/any_instance/stub_chain_chain.rb +23 -0
- data/vendor_lib/rspec/mocks/argument_list_matcher.rb +104 -0
- data/vendor_lib/rspec/mocks/argument_matchers.rb +264 -0
- data/vendor_lib/rspec/mocks/arity_calculator.rb +66 -0
- data/vendor_lib/rspec/mocks/configuration.rb +111 -0
- data/vendor_lib/rspec/mocks/error_generator.rb +203 -0
- data/vendor_lib/rspec/mocks/errors.rb +12 -0
- data/vendor_lib/rspec/mocks/example_methods.rb +201 -0
- data/vendor_lib/rspec/mocks/extensions/marshal.rb +17 -0
- data/vendor_lib/rspec/mocks/framework.rb +36 -0
- data/vendor_lib/rspec/mocks/instance_method_stasher.rb +112 -0
- data/vendor_lib/rspec/mocks/matchers/have_received.rb +99 -0
- data/vendor_lib/rspec/mocks/matchers/receive.rb +112 -0
- data/vendor_lib/rspec/mocks/matchers/receive_messages.rb +72 -0
- data/vendor_lib/rspec/mocks/message_expectation.rb +643 -0
- data/vendor_lib/rspec/mocks/method_double.rb +209 -0
- data/vendor_lib/rspec/mocks/method_reference.rb +95 -0
- data/vendor_lib/rspec/mocks/mock.rb +7 -0
- data/vendor_lib/rspec/mocks/mutate_const.rb +406 -0
- data/vendor_lib/rspec/mocks/object_reference.rb +90 -0
- data/vendor_lib/rspec/mocks/order_group.rb +82 -0
- data/vendor_lib/rspec/mocks/proxy.rb +269 -0
- data/vendor_lib/rspec/mocks/proxy_for_nil.rb +37 -0
- data/vendor_lib/rspec/mocks/space.rb +95 -0
- data/vendor_lib/rspec/mocks/standalone.rb +3 -0
- data/vendor_lib/rspec/mocks/stub_chain.rb +51 -0
- data/vendor_lib/rspec/mocks/syntax.rb +374 -0
- data/vendor_lib/rspec/mocks/targets.rb +90 -0
- data/vendor_lib/rspec/mocks/test_double.rb +109 -0
- data/vendor_lib/rspec/mocks/verifying_double.rb +77 -0
- data/vendor_lib/rspec/mocks/verifying_message_expecation.rb +60 -0
- data/vendor_lib/rspec/mocks/verifying_proxy.rb +151 -0
- data/vendor_lib/rspec/mocks/version.rb +7 -0
- data/vendor_lib/rspec/support.rb +6 -0
- data/vendor_lib/rspec/support/caller_filter.rb +56 -0
- data/vendor_lib/rspec/support/spec.rb +14 -0
- data/vendor_lib/rspec/support/spec/deprecation_helpers.rb +29 -0
- data/vendor_lib/rspec/support/spec/in_sub_process.rb +40 -0
- data/vendor_lib/rspec/support/spec/stderr_splitter.rb +50 -0
- data/vendor_lib/rspec/support/version.rb +7 -0
- data/vendor_lib/rspec/support/warnings.rb +41 -0
- data/vendor_lib/rspec/version.rb +5 -0
- metadata +268 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created by Jim Weirich on 2007-04-10.
|
4
|
+
# Copyright (c) 2007. All rights reserved.
|
5
|
+
|
6
|
+
require 'flexmock/rspec'
|
7
|
+
|
8
|
+
module RSpec
|
9
|
+
module Core
|
10
|
+
module MockFrameworkAdapter
|
11
|
+
|
12
|
+
def self.framework_name; :flexmock end
|
13
|
+
|
14
|
+
include FlexMock::MockContainer
|
15
|
+
def setup_mocks_for_rspec
|
16
|
+
# No setup required
|
17
|
+
end
|
18
|
+
def verify_mocks_for_rspec
|
19
|
+
flexmock_verify
|
20
|
+
end
|
21
|
+
def teardown_mocks_for_rspec
|
22
|
+
flexmock_close
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# In order to support all versions of mocha, we have to jump through some
|
2
|
+
# hoops here.
|
3
|
+
#
|
4
|
+
# mocha >= '0.13.0':
|
5
|
+
# require 'mocha/api' is required
|
6
|
+
# require 'mocha/object' raises a LoadError b/c the file no longer exists
|
7
|
+
# mocha < '0.13.0', >= '0.9.7'
|
8
|
+
# require 'mocha/api' is required
|
9
|
+
# require 'mocha/object' is required
|
10
|
+
# mocha < '0.9.7':
|
11
|
+
# require 'mocha/api' raises a LoadError b/c the file does not yet exist
|
12
|
+
# require 'mocha/standalone' is required
|
13
|
+
# require 'mocha/object' is required
|
14
|
+
begin
|
15
|
+
require 'mocha/api'
|
16
|
+
|
17
|
+
begin
|
18
|
+
require 'mocha/object'
|
19
|
+
rescue LoadError
|
20
|
+
# Mocha >= 0.13.0 no longer contains this file nor needs it to be loaded
|
21
|
+
end
|
22
|
+
rescue LoadError
|
23
|
+
require 'mocha/standalone'
|
24
|
+
require 'mocha/object'
|
25
|
+
end
|
26
|
+
|
27
|
+
module RSpec
|
28
|
+
module Core
|
29
|
+
module MockFrameworkAdapter
|
30
|
+
def self.framework_name; :mocha end
|
31
|
+
|
32
|
+
# Mocha::Standalone was deprecated as of Mocha 0.9.7.
|
33
|
+
begin
|
34
|
+
include Mocha::API
|
35
|
+
rescue NameError
|
36
|
+
include Mocha::Standalone
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup_mocks_for_rspec
|
40
|
+
mocha_setup
|
41
|
+
end
|
42
|
+
|
43
|
+
def verify_mocks_for_rspec
|
44
|
+
mocha_verify
|
45
|
+
end
|
46
|
+
|
47
|
+
def teardown_mocks_for_rspec
|
48
|
+
mocha_teardown
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rr'
|
2
|
+
|
3
|
+
RSpec.configuration.backtrace_exclusion_patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
module Core
|
7
|
+
module MockFrameworkAdapter
|
8
|
+
|
9
|
+
def self.framework_name; :rr end
|
10
|
+
|
11
|
+
include RR::Extensions::InstanceMethods
|
12
|
+
|
13
|
+
def setup_mocks_for_rspec
|
14
|
+
RR::Space.instance.reset
|
15
|
+
end
|
16
|
+
|
17
|
+
def verify_mocks_for_rspec
|
18
|
+
RR::Space.instance.verify_doubles
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown_mocks_for_rspec
|
22
|
+
RR::Space.instance.reset
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rspec/mocks'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Core
|
5
|
+
module MockFrameworkAdapter
|
6
|
+
|
7
|
+
def self.framework_name; :rspec end
|
8
|
+
|
9
|
+
def self.configuration
|
10
|
+
RSpec::Mocks.configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup_mocks_for_rspec
|
14
|
+
RSpec::Mocks::setup(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
def verify_mocks_for_rspec
|
18
|
+
RSpec::Mocks::verify
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown_mocks_for_rspec
|
22
|
+
RSpec::Mocks::teardown
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
# http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
module RSpec::Core
|
5
|
+
class Parser
|
6
|
+
def self.parse!(args)
|
7
|
+
new.parse!(args)
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
alias_method :parse, :parse!
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse!(args)
|
15
|
+
return {} if args.empty?
|
16
|
+
|
17
|
+
convert_deprecated_args(args)
|
18
|
+
|
19
|
+
options = args.delete('--tty') ? {:tty => true} : {}
|
20
|
+
begin
|
21
|
+
parser(options).parse!(args)
|
22
|
+
rescue OptionParser::InvalidOption => e
|
23
|
+
abort "#{e.message}\n\nPlease use --help for a listing of valid options"
|
24
|
+
end
|
25
|
+
|
26
|
+
options
|
27
|
+
end
|
28
|
+
|
29
|
+
def convert_deprecated_args(args)
|
30
|
+
args.map! { |arg|
|
31
|
+
case arg
|
32
|
+
when "--formatter"
|
33
|
+
RSpec.deprecate("the --formatter option", :replacement => "-f or --format")
|
34
|
+
"--format"
|
35
|
+
when "--default_path"
|
36
|
+
"--default-path"
|
37
|
+
when "--line_number"
|
38
|
+
"--line-number"
|
39
|
+
else
|
40
|
+
arg
|
41
|
+
end
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
alias_method :parse, :parse!
|
46
|
+
|
47
|
+
def parser(options)
|
48
|
+
OptionParser.new do |parser|
|
49
|
+
parser.banner = "Usage: rspec [options] [files or directories]\n\n"
|
50
|
+
|
51
|
+
parser.on('-I PATH', 'Specify PATH to add to $LOAD_PATH (may be used more than once).') do |dir|
|
52
|
+
options[:libs] ||= []
|
53
|
+
options[:libs] << dir
|
54
|
+
end
|
55
|
+
|
56
|
+
parser.on('-r', '--require PATH', 'Require a file.') do |path|
|
57
|
+
options[:requires] ||= []
|
58
|
+
options[:requires] << path
|
59
|
+
end
|
60
|
+
|
61
|
+
parser.on('-O', '--options PATH', 'Specify the path to a custom options file.') do |path|
|
62
|
+
options[:custom_options_file] = path
|
63
|
+
end
|
64
|
+
|
65
|
+
parser.on('--order TYPE[:SEED]', 'Run examples by the specified order type.',
|
66
|
+
' [defined] examples and groups are run in the order they are defined',
|
67
|
+
' [rand] randomize the order of groups and examples',
|
68
|
+
' [random] alias for rand',
|
69
|
+
' [random:SEED] e.g. --order random:123') do |o|
|
70
|
+
options[:order] = o
|
71
|
+
end
|
72
|
+
|
73
|
+
parser.on('--seed SEED', Integer, 'Equivalent of --order rand:SEED.') do |seed|
|
74
|
+
options[:order] = "rand:#{seed}"
|
75
|
+
end
|
76
|
+
|
77
|
+
parser.on('--fail-fast', 'Abort the run on first failure.') do |o|
|
78
|
+
options[:fail_fast] = true
|
79
|
+
end
|
80
|
+
|
81
|
+
parser.on('--no-fail-fast', 'Do not abort the run on first failure.') do |o|
|
82
|
+
options[:fail_fast] = false
|
83
|
+
end
|
84
|
+
|
85
|
+
parser.on('--failure-exit-code CODE', Integer, 'Override the exit code used when there are failing specs.') do |code|
|
86
|
+
options[:failure_exit_code] = code
|
87
|
+
end
|
88
|
+
|
89
|
+
parser.on('--dry-run', 'Print the formatter output of your suite without',
|
90
|
+
' running any examples or hooks') do |o|
|
91
|
+
options[:dry_run] = true
|
92
|
+
end
|
93
|
+
|
94
|
+
parser.on('-X', '--[no-]drb', 'Run examples via DRb.') do |o|
|
95
|
+
options[:drb] = o
|
96
|
+
end
|
97
|
+
|
98
|
+
parser.on('--drb-port PORT', 'Port to connect to the DRb server.') do |o|
|
99
|
+
options[:drb_port] = o.to_i
|
100
|
+
end
|
101
|
+
|
102
|
+
parser.on('--init', 'Initialize your project with RSpec.') do |cmd|
|
103
|
+
require 'rspec/core/project_initializer'
|
104
|
+
ProjectInitializer.new(cmd).run
|
105
|
+
exit
|
106
|
+
end
|
107
|
+
|
108
|
+
parser.on('--configure', 'Deprecated. Use --init instead.') do |cmd|
|
109
|
+
RSpec.warning "--configure is deprecated with no effect. Use --init instead.", :call_site => nil
|
110
|
+
exit
|
111
|
+
end
|
112
|
+
|
113
|
+
parser.separator("\n **** Output ****\n\n")
|
114
|
+
|
115
|
+
parser.on('-f', '--format FORMATTER', 'Choose a formatter.',
|
116
|
+
' [p]rogress (default - dots)',
|
117
|
+
' [d]ocumentation (group and example names)',
|
118
|
+
' [h]tml',
|
119
|
+
' [j]son',
|
120
|
+
' custom formatter class name') do |o|
|
121
|
+
options[:formatters] ||= []
|
122
|
+
options[:formatters] << [o]
|
123
|
+
end
|
124
|
+
|
125
|
+
parser.on('-o', '--out FILE',
|
126
|
+
'Write output to a file instead of $stdout. This option applies',
|
127
|
+
' to the previously specified --format, or the default format',
|
128
|
+
' if no format is specified.'
|
129
|
+
) do |o|
|
130
|
+
options[:formatters] ||= [['progress']]
|
131
|
+
options[:formatters].last << o
|
132
|
+
end
|
133
|
+
|
134
|
+
parser.on('-b', '--backtrace', 'Enable full backtrace.') do |o|
|
135
|
+
options[:full_backtrace] = true
|
136
|
+
end
|
137
|
+
|
138
|
+
parser.on('-c', '--[no-]color', '--[no-]colour', 'Enable color in the output.') do |o|
|
139
|
+
options[:color] = o
|
140
|
+
end
|
141
|
+
|
142
|
+
parser.on('-p', '--[no-]profile [COUNT]', 'Enable profiling of examples and list the slowest examples (default: 10).') do |argument|
|
143
|
+
options[:profile_examples] = if argument.nil?
|
144
|
+
true
|
145
|
+
elsif argument == false
|
146
|
+
false
|
147
|
+
else
|
148
|
+
begin
|
149
|
+
Integer(argument)
|
150
|
+
rescue ArgumentError
|
151
|
+
RSpec.warning "Non integer specified as profile count, seperate " +
|
152
|
+
"your path from options with -- e.g. " +
|
153
|
+
"`rspec --profile -- #{argument}`",
|
154
|
+
:call_site => nil
|
155
|
+
true
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
parser.on('-w', '--warnings', 'Enable ruby warnings') do
|
161
|
+
options[:warnings] = true
|
162
|
+
end
|
163
|
+
|
164
|
+
parser.separator <<-FILTERING
|
165
|
+
|
166
|
+
**** Filtering/tags ****
|
167
|
+
|
168
|
+
In addition to the following options for selecting specific files, groups,
|
169
|
+
or examples, you can select a single example by appending the line number to
|
170
|
+
the filename:
|
171
|
+
|
172
|
+
rspec path/to/a_spec.rb:37
|
173
|
+
|
174
|
+
FILTERING
|
175
|
+
|
176
|
+
parser.on('-P', '--pattern PATTERN', 'Load files matching pattern (default: "spec/**/*_spec.rb").') do |o|
|
177
|
+
options[:pattern] = o
|
178
|
+
end
|
179
|
+
|
180
|
+
parser.on('-e', '--example STRING', "Run examples whose full nested names include STRING (may be",
|
181
|
+
" used more than once)") do |o|
|
182
|
+
(options[:full_description] ||= []) << Regexp.compile(Regexp.escape(o))
|
183
|
+
end
|
184
|
+
|
185
|
+
parser.on('-l', '--line-number LINE', 'Specify line number of an example or group (may be',
|
186
|
+
' used more than once).') do |o|
|
187
|
+
(options[:line_numbers] ||= []) << o
|
188
|
+
end
|
189
|
+
|
190
|
+
parser.on('-t', '--tag TAG[:VALUE]',
|
191
|
+
'Run examples with the specified tag, or exclude examples',
|
192
|
+
'by adding ~ before the tag.',
|
193
|
+
' - e.g. ~slow',
|
194
|
+
' - TAG is always converted to a symbol') do |tag|
|
195
|
+
filter_type = tag =~ /^~/ ? :exclusion_filter : :inclusion_filter
|
196
|
+
|
197
|
+
name,value = tag.gsub(/^(~@|~|@)/, '').split(':',2)
|
198
|
+
name = name.to_sym
|
199
|
+
|
200
|
+
options[filter_type] ||= {}
|
201
|
+
options[filter_type][name] = case value
|
202
|
+
when nil then true # The default value for tags is true
|
203
|
+
when 'true' then true
|
204
|
+
when 'false' then false
|
205
|
+
when 'nil' then nil
|
206
|
+
when /^:/ then value[1..-1].to_sym
|
207
|
+
when /^\d+$/ then Integer(value)
|
208
|
+
when /^\d+.\d+$/ then Float(value)
|
209
|
+
else
|
210
|
+
value
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
parser.on('--default-path PATH', 'Set the default path where RSpec looks for examples (can',
|
215
|
+
' be a path to a file or a directory).') do |path|
|
216
|
+
options[:default_path] = path
|
217
|
+
end
|
218
|
+
|
219
|
+
parser.separator("\n **** Utility ****\n\n")
|
220
|
+
|
221
|
+
parser.on('-v', '--version', 'Display the version.') do
|
222
|
+
puts RSpec::Core::Version::STRING
|
223
|
+
exit
|
224
|
+
end
|
225
|
+
|
226
|
+
parser.on_tail('-h', '--help', "You're looking at it.") do
|
227
|
+
puts parser
|
228
|
+
exit
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
if defined?(::Random)
|
4
|
+
RandomNumberGenerator = ::Random
|
5
|
+
else
|
6
|
+
require 'rspec/core/backport_random'
|
7
|
+
RandomNumberGenerator = RSpec::Core::Backports::Random
|
8
|
+
end
|
9
|
+
|
10
|
+
# @private
|
11
|
+
module Ordering
|
12
|
+
# @private
|
13
|
+
# The default global ordering (defined order).
|
14
|
+
class Identity
|
15
|
+
def order(items)
|
16
|
+
items
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# @private
|
21
|
+
# Orders items randomly.
|
22
|
+
class Random
|
23
|
+
def initialize(configuration)
|
24
|
+
@configuration = configuration
|
25
|
+
@used = false
|
26
|
+
end
|
27
|
+
|
28
|
+
def used?
|
29
|
+
@used
|
30
|
+
end
|
31
|
+
|
32
|
+
def order(items)
|
33
|
+
@used = true
|
34
|
+
rng = RandomNumberGenerator.new(@configuration.seed)
|
35
|
+
shuffle items, rng
|
36
|
+
end
|
37
|
+
|
38
|
+
if RUBY_VERSION > '1.9.3'
|
39
|
+
def shuffle(list, rng)
|
40
|
+
list.shuffle(:random => rng)
|
41
|
+
end
|
42
|
+
else
|
43
|
+
def shuffle(list, rng)
|
44
|
+
shuffled = list.dup
|
45
|
+
shuffled.size.times do |i|
|
46
|
+
j = i + rng.rand(shuffled.size - i)
|
47
|
+
next if i == j
|
48
|
+
shuffled[i], shuffled[j] = shuffled[j], shuffled[i]
|
49
|
+
end
|
50
|
+
|
51
|
+
shuffled
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# @private
|
57
|
+
# Orders items based on a custom block.
|
58
|
+
class Custom
|
59
|
+
def initialize(callable)
|
60
|
+
@callable = callable
|
61
|
+
end
|
62
|
+
|
63
|
+
def order(list)
|
64
|
+
@callable.call(list)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# @private
|
69
|
+
# Stores the different ordering strategies.
|
70
|
+
class Registry
|
71
|
+
def initialize(configuration)
|
72
|
+
@configuration = configuration
|
73
|
+
@strategies = {}
|
74
|
+
|
75
|
+
register(:random, Random.new(configuration))
|
76
|
+
|
77
|
+
identity = Identity.new
|
78
|
+
register(:defined, identity)
|
79
|
+
|
80
|
+
# The default global ordering is --defined.
|
81
|
+
register(:global, identity)
|
82
|
+
end
|
83
|
+
|
84
|
+
def fetch(name, &fallback)
|
85
|
+
@strategies.fetch(name, &fallback)
|
86
|
+
end
|
87
|
+
|
88
|
+
def register(sym, strategy)
|
89
|
+
@strategies[sym] = strategy
|
90
|
+
end
|
91
|
+
|
92
|
+
def used_random_seed?
|
93
|
+
@strategies[:random].used?
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# @private
|
98
|
+
# Manages ordering configuration.
|
99
|
+
#
|
100
|
+
# @note This is not intended to be used externally. Use
|
101
|
+
# the APIs provided by `RSpec::Core::Configuration` instead.
|
102
|
+
class ConfigurationManager
|
103
|
+
attr_reader :seed, :ordering_registry
|
104
|
+
|
105
|
+
def initialize
|
106
|
+
@ordering_registry = Registry.new(self)
|
107
|
+
@seed = rand(0xFFFF)
|
108
|
+
@seed_forced = false
|
109
|
+
@order_forced = false
|
110
|
+
end
|
111
|
+
|
112
|
+
def seed_used?
|
113
|
+
ordering_registry.used_random_seed?
|
114
|
+
end
|
115
|
+
|
116
|
+
def seed=(seed)
|
117
|
+
return if @seed_forced
|
118
|
+
register_ordering(:global, ordering_registry.fetch(:random))
|
119
|
+
@seed = seed.to_i
|
120
|
+
end
|
121
|
+
|
122
|
+
def order=(type)
|
123
|
+
order, seed = type.to_s.split(':')
|
124
|
+
@seed = seed = seed.to_i if seed
|
125
|
+
|
126
|
+
ordering_name = if order.include?('rand')
|
127
|
+
:random
|
128
|
+
elsif order == 'defined'
|
129
|
+
:defined
|
130
|
+
end
|
131
|
+
|
132
|
+
register_ordering(:global, ordering_registry.fetch(ordering_name)) if ordering_name
|
133
|
+
end
|
134
|
+
|
135
|
+
def force(hash)
|
136
|
+
if hash.has_key?(:seed)
|
137
|
+
self.seed = hash[:seed]
|
138
|
+
@seed_forced = true
|
139
|
+
@order_forced = true
|
140
|
+
elsif hash.has_key?(:order)
|
141
|
+
self.order = hash[:order]
|
142
|
+
@order_forced = true
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def register_ordering(name, strategy = Custom.new(Proc.new { |l| yield l }))
|
147
|
+
return if @order_forced && name == :global
|
148
|
+
ordering_registry.register(name, strategy)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|