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,44 @@
|
|
1
|
+
# This is borrowed (slightly modified) from Scott Taylor's
|
2
|
+
# project_path project:
|
3
|
+
# http://github.com/smtlaissezfaire/project_path
|
4
|
+
|
5
|
+
require 'pathname'
|
6
|
+
|
7
|
+
module RSpec
|
8
|
+
module Core
|
9
|
+
module RubyProject
|
10
|
+
def add_to_load_path(*dirs)
|
11
|
+
dirs.map {|dir| add_dir_to_load_path(File.join(root, dir))}
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_dir_to_load_path(dir)
|
15
|
+
$LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir)
|
16
|
+
end
|
17
|
+
|
18
|
+
def root
|
19
|
+
@project_root ||= determine_root
|
20
|
+
end
|
21
|
+
|
22
|
+
def determine_root
|
23
|
+
find_first_parent_containing('spec') || '.'
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_first_parent_containing(dir)
|
27
|
+
ascend_until {|path| File.exists?(File.join(path, dir))}
|
28
|
+
end
|
29
|
+
|
30
|
+
def ascend_until
|
31
|
+
Pathname(File.expand_path('.')).ascend do |path|
|
32
|
+
return path if yield(path)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module_function :add_to_load_path
|
37
|
+
module_function :add_dir_to_load_path
|
38
|
+
module_function :root
|
39
|
+
module_function :determine_root
|
40
|
+
module_function :find_first_parent_containing
|
41
|
+
module_function :ascend_until
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
class Runner
|
4
|
+
|
5
|
+
# Register an at_exit hook that runs the suite.
|
6
|
+
def self.autorun
|
7
|
+
return if autorun_disabled? || installed_at_exit? || running_in_drb?
|
8
|
+
at_exit do
|
9
|
+
# Don't bother running any specs and just let the program terminate
|
10
|
+
# if we got here due to an unrescued exception (anything other than
|
11
|
+
# SystemExit, which is raised when somebody calls Kernel#exit).
|
12
|
+
next unless $!.nil? || $!.kind_of?(SystemExit)
|
13
|
+
|
14
|
+
# We got here because either the end of the program was reached or
|
15
|
+
# somebody called Kernel#exit. Run the specs and then override any
|
16
|
+
# existing exit status with RSpec's exit status if any specs failed.
|
17
|
+
status = run(ARGV, $stderr, $stdout).to_i
|
18
|
+
exit status if status != 0
|
19
|
+
end
|
20
|
+
@installed_at_exit = true
|
21
|
+
end
|
22
|
+
AT_EXIT_HOOK_BACKTRACE_LINE = "#{__FILE__}:#{__LINE__ - 2}:in `autorun'"
|
23
|
+
|
24
|
+
def self.disable_autorun!
|
25
|
+
@autorun_disabled = true
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.autorun_disabled?
|
29
|
+
@autorun_disabled ||= false
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.installed_at_exit?
|
33
|
+
@installed_at_exit ||= false
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.running_in_drb?
|
37
|
+
begin
|
38
|
+
if defined?(DRb) && DRb.current_server
|
39
|
+
require 'socket'
|
40
|
+
require 'uri'
|
41
|
+
|
42
|
+
local_ipv4 = IPSocket.getaddress(Socket.gethostname)
|
43
|
+
|
44
|
+
local_drb = ["127.0.0.1", "localhost", local_ipv4].any? { |addr| addr == URI(DRb.current_server.uri).host }
|
45
|
+
end
|
46
|
+
rescue DRb::DRbServerNotFound
|
47
|
+
ensure
|
48
|
+
return local_drb || false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.trap_interrupt
|
53
|
+
trap('INT') do
|
54
|
+
exit!(1) if RSpec.wants_to_quit
|
55
|
+
RSpec.wants_to_quit = true
|
56
|
+
STDERR.puts "\nExiting... Interrupt again to exit immediately."
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Run a suite of RSpec examples.
|
61
|
+
#
|
62
|
+
# This is used internally by RSpec to run a suite, but is available
|
63
|
+
# for use by any other automation tool.
|
64
|
+
#
|
65
|
+
# If you want to run this multiple times in the same process, and you
|
66
|
+
# want files like spec_helper.rb to be reloaded, be sure to load `load`
|
67
|
+
# instead of `require`.
|
68
|
+
#
|
69
|
+
# #### Parameters
|
70
|
+
# * +args+ - an array of command-line-supported arguments
|
71
|
+
# * +err+ - error stream (Default: $stderr)
|
72
|
+
# * +out+ - output stream (Default: $stdout)
|
73
|
+
#
|
74
|
+
# #### Returns
|
75
|
+
# * +Fixnum+ - exit status code (0/1)
|
76
|
+
def self.run(args, err=$stderr, out=$stdout)
|
77
|
+
trap_interrupt
|
78
|
+
options = ConfigurationOptions.new(args)
|
79
|
+
options.parse_options
|
80
|
+
|
81
|
+
if options.options[:drb]
|
82
|
+
require 'rspec/core/drb_command_line'
|
83
|
+
begin
|
84
|
+
DRbCommandLine.new(options).run(err, out)
|
85
|
+
rescue DRb::DRbConnError
|
86
|
+
err.puts "No DRb server is running. Running in local process instead ..."
|
87
|
+
CommandLine.new(options).run(err, out)
|
88
|
+
end
|
89
|
+
else
|
90
|
+
CommandLine.new(options).run(err, out)
|
91
|
+
end
|
92
|
+
ensure
|
93
|
+
RSpec.reset
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
# Exposes {ExampleGroup}-level methods to a module, so you can include that
|
4
|
+
# module in an {ExampleGroup}.
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
#
|
8
|
+
# module LoggedInAsAdmin
|
9
|
+
# extend RSpec::Core::SharedContext
|
10
|
+
# before(:each) do
|
11
|
+
# log_in_as :admin
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# describe "admin section" do
|
16
|
+
# include LoggedInAsAdmin
|
17
|
+
# # ...
|
18
|
+
# end
|
19
|
+
module SharedContext
|
20
|
+
# @api private
|
21
|
+
def included(group)
|
22
|
+
__shared_context_recordings.each do |recording|
|
23
|
+
recording.playback_onto(group)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# @api private
|
28
|
+
def __shared_context_recordings
|
29
|
+
@__shared_context_recordings ||= []
|
30
|
+
end
|
31
|
+
|
32
|
+
Recording = Struct.new(:method_name, :args, :block) do
|
33
|
+
def playback_onto(group)
|
34
|
+
group.__send__(method_name, *args, &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# @api private
|
39
|
+
def self.record(methods)
|
40
|
+
methods.each do |meth|
|
41
|
+
define_method(meth) do |*args, &block|
|
42
|
+
__shared_context_recordings << Recording.new(meth, args, block)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
record [:describe, :context] + Hooks.instance_methods(false) +
|
48
|
+
MemoizedHelpers::ClassMethods.instance_methods(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
SharedContext = Core::SharedContext
|
53
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
module SharedExampleGroup
|
4
|
+
# @overload shared_examples(name, &block)
|
5
|
+
# @overload shared_examples(name, tags, &block)
|
6
|
+
#
|
7
|
+
# Wraps the `block` in a module which can then be included in example
|
8
|
+
# groups using `include_examples`, `include_context`, or
|
9
|
+
# `it_behaves_like`.
|
10
|
+
#
|
11
|
+
# @param [String] name to match when looking up this shared group
|
12
|
+
# @param block to be eval'd in a nested example group generated by `it_behaves_like`
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
#
|
16
|
+
# shared_examples "auditable" do
|
17
|
+
# it "stores an audit record on save!" do
|
18
|
+
# lambda { auditable.save! }.should change(Audit, :count).by(1)
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# class Account do
|
23
|
+
# it_behaves_like "auditable" do
|
24
|
+
# def auditable; Account.new; end
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# @see ExampleGroup.it_behaves_like
|
29
|
+
# @see ExampleGroup.include_examples
|
30
|
+
# @see ExampleGroup.include_context
|
31
|
+
def shared_examples(*args, &block)
|
32
|
+
SharedExampleGroup.registry.add_group(self, *args, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
alias_method :shared_context, :shared_examples
|
36
|
+
alias_method :share_examples_for, :shared_examples
|
37
|
+
alias_method :shared_examples_for, :shared_examples
|
38
|
+
|
39
|
+
def shared_example_groups
|
40
|
+
SharedExampleGroup.registry.shared_example_groups_for('main', *ancestors[0..-1])
|
41
|
+
end
|
42
|
+
|
43
|
+
module TopLevelDSL
|
44
|
+
def shared_examples(*args, &block)
|
45
|
+
SharedExampleGroup.registry.add_group('main', *args, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
alias_method :shared_context, :shared_examples
|
49
|
+
alias_method :share_examples_for, :shared_examples
|
50
|
+
alias_method :shared_examples_for, :shared_examples
|
51
|
+
|
52
|
+
def shared_example_groups
|
53
|
+
SharedExampleGroup.registry.shared_example_groups_for('main')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.registry
|
58
|
+
@registry ||= Registry.new
|
59
|
+
end
|
60
|
+
|
61
|
+
# @private
|
62
|
+
#
|
63
|
+
# Used internally to manage the shared example groups and
|
64
|
+
# constants. We want to limit the number of methods we add
|
65
|
+
# to objects we don't own (main and Module) so this allows
|
66
|
+
# us to have helper methods that don't get added to those
|
67
|
+
# objects.
|
68
|
+
class Registry
|
69
|
+
def add_group(source, *args, &block)
|
70
|
+
ensure_block_has_source_location(block, CallerFilter.first_non_rspec_line)
|
71
|
+
|
72
|
+
if key? args.first
|
73
|
+
key = args.shift
|
74
|
+
warn_if_key_taken source, key, block
|
75
|
+
add_shared_example_group source, key, block
|
76
|
+
end
|
77
|
+
|
78
|
+
unless args.empty?
|
79
|
+
mod = Module.new
|
80
|
+
(class << mod; self; end).send :define_method, :extended do |host|
|
81
|
+
host.class_eval(&block)
|
82
|
+
end
|
83
|
+
RSpec.configuration.extend mod, *args
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def shared_example_groups_for(*sources)
|
88
|
+
Collection.new(sources, shared_example_groups)
|
89
|
+
end
|
90
|
+
|
91
|
+
def shared_example_groups
|
92
|
+
@shared_example_groups ||= Hash.new { |hash,key| hash[key] = Hash.new }
|
93
|
+
end
|
94
|
+
|
95
|
+
def clear
|
96
|
+
shared_example_groups.clear
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def add_shared_example_group(source, key, block)
|
102
|
+
shared_example_groups[source][key] = block
|
103
|
+
end
|
104
|
+
|
105
|
+
def key?(candidate)
|
106
|
+
[String, Symbol, Module].any? { |cls| cls === candidate }
|
107
|
+
end
|
108
|
+
|
109
|
+
def warn_if_key_taken(source, key, new_block)
|
110
|
+
return unless existing_block = example_block_for(source, key)
|
111
|
+
|
112
|
+
RSpec.warn_with <<-WARNING.gsub(/^ +\|/, ''), :call_site => nil
|
113
|
+
|WARNING: Shared example group '#{key}' has been previously defined at:
|
114
|
+
| #{formatted_location existing_block}
|
115
|
+
|...and you are now defining it at:
|
116
|
+
| #{formatted_location new_block}
|
117
|
+
|The new definition will overwrite the original one.
|
118
|
+
WARNING
|
119
|
+
end
|
120
|
+
|
121
|
+
def formatted_location(block)
|
122
|
+
block.source_location.join ":"
|
123
|
+
end
|
124
|
+
|
125
|
+
def example_block_for(source, key)
|
126
|
+
shared_example_groups[source][key]
|
127
|
+
end
|
128
|
+
|
129
|
+
if Proc.method_defined?(:source_location)
|
130
|
+
def ensure_block_has_source_location(block, caller_line); end
|
131
|
+
else # for 1.8.7
|
132
|
+
def ensure_block_has_source_location(block, caller_line)
|
133
|
+
block.extend Module.new {
|
134
|
+
define_method :source_location do
|
135
|
+
caller_line.split(':')
|
136
|
+
end
|
137
|
+
}
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
extend RSpec::Core::SharedExampleGroup::TopLevelDSL
|
146
|
+
Module.send(:include, RSpec::Core::SharedExampleGroup::TopLevelDSL)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
module SharedExampleGroup
|
4
|
+
class Collection
|
5
|
+
|
6
|
+
def initialize(sources, examples)
|
7
|
+
@sources, @examples = sources, examples
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](key)
|
11
|
+
fetch_examples(key)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def fetch_examples(key)
|
17
|
+
@examples[source_for key][key]
|
18
|
+
end
|
19
|
+
|
20
|
+
def source_for(key)
|
21
|
+
@sources.reverse.find { |source| @examples[source].has_key? key }
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RSpec
|
2
|
+
|
3
|
+
# @private
|
4
|
+
#
|
5
|
+
# Used internally to print deprecation warnings
|
6
|
+
def self.deprecate(deprecated, data = {})
|
7
|
+
RSpec.configuration.reporter.deprecation(
|
8
|
+
{
|
9
|
+
:deprecated => deprecated,
|
10
|
+
:call_site => CallerFilter.first_non_rspec_line
|
11
|
+
}.merge(data)
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
# @private
|
16
|
+
#
|
17
|
+
# Used internally to print deprecation warnings
|
18
|
+
def self.warn_deprecation(message)
|
19
|
+
RSpec.configuration.reporter.deprecation :message => message
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
class World
|
4
|
+
|
5
|
+
include RSpec::Core::Hooks
|
6
|
+
|
7
|
+
attr_reader :example_groups, :filtered_examples
|
8
|
+
attr_accessor :wants_to_quit
|
9
|
+
|
10
|
+
def initialize(configuration=RSpec.configuration)
|
11
|
+
@configuration = configuration
|
12
|
+
@example_groups = []
|
13
|
+
@filtered_examples = Hash.new { |hash,group|
|
14
|
+
hash[group] = begin
|
15
|
+
examples = group.examples.dup
|
16
|
+
examples = filter_manager.prune(examples)
|
17
|
+
examples.uniq!
|
18
|
+
examples
|
19
|
+
end
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def ordered_example_groups
|
24
|
+
ordering_strategy = @configuration.ordering_registry.fetch(:global)
|
25
|
+
ordering_strategy.order(@example_groups)
|
26
|
+
end
|
27
|
+
|
28
|
+
def reset
|
29
|
+
example_groups.clear
|
30
|
+
SharedExampleGroup.registry.clear
|
31
|
+
end
|
32
|
+
|
33
|
+
def filter_manager
|
34
|
+
@configuration.filter_manager
|
35
|
+
end
|
36
|
+
|
37
|
+
def register(example_group)
|
38
|
+
example_groups << example_group
|
39
|
+
example_group
|
40
|
+
end
|
41
|
+
|
42
|
+
def inclusion_filter
|
43
|
+
@configuration.inclusion_filter
|
44
|
+
end
|
45
|
+
|
46
|
+
def exclusion_filter
|
47
|
+
@configuration.exclusion_filter
|
48
|
+
end
|
49
|
+
|
50
|
+
def configure_group(group)
|
51
|
+
@configuration.configure_group(group)
|
52
|
+
end
|
53
|
+
|
54
|
+
def example_count
|
55
|
+
FlatMap.flat_map(example_groups) {|g| g.descendants}.
|
56
|
+
inject(0) {|sum, g| sum + g.filtered_examples.size}
|
57
|
+
end
|
58
|
+
|
59
|
+
def preceding_declaration_line(filter_line)
|
60
|
+
declaration_line_numbers.sort.inject(nil) do |highest_prior_declaration_line, line|
|
61
|
+
line <= filter_line ? line : highest_prior_declaration_line
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def reporter
|
66
|
+
@configuration.reporter
|
67
|
+
end
|
68
|
+
|
69
|
+
def announce_filters
|
70
|
+
filter_announcements = []
|
71
|
+
|
72
|
+
announce_inclusion_filter filter_announcements
|
73
|
+
announce_exclusion_filter filter_announcements
|
74
|
+
|
75
|
+
unless filter_manager.empty?
|
76
|
+
if filter_announcements.length == 1
|
77
|
+
reporter.message("Run options: #{filter_announcements[0]}")
|
78
|
+
else
|
79
|
+
reporter.message("Run options:\n #{filter_announcements.join("\n ")}")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
if @configuration.run_all_when_everything_filtered? && example_count.zero?
|
84
|
+
reporter.message("#{everything_filtered_message}; ignoring #{inclusion_filter.description}")
|
85
|
+
filtered_examples.clear
|
86
|
+
inclusion_filter.clear
|
87
|
+
end
|
88
|
+
|
89
|
+
if example_count.zero?
|
90
|
+
example_groups.clear
|
91
|
+
if filter_manager.empty?
|
92
|
+
reporter.message("No examples found.")
|
93
|
+
elsif exclusion_filter.empty_without_conditional_filters?
|
94
|
+
message = everything_filtered_message
|
95
|
+
if @configuration.run_all_when_everything_filtered?
|
96
|
+
message << "; ignoring #{inclusion_filter.description}"
|
97
|
+
end
|
98
|
+
reporter.message(message)
|
99
|
+
elsif inclusion_filter.empty?
|
100
|
+
reporter.message(everything_filtered_message)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def everything_filtered_message
|
106
|
+
"\nAll examples were filtered out"
|
107
|
+
end
|
108
|
+
|
109
|
+
def announce_inclusion_filter(announcements)
|
110
|
+
unless inclusion_filter.empty?
|
111
|
+
announcements << "include #{inclusion_filter.description}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def announce_exclusion_filter(announcements)
|
116
|
+
unless exclusion_filter.empty_without_conditional_filters?
|
117
|
+
announcements << "exclude #{exclusion_filter.description}"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
def declaration_line_numbers
|
124
|
+
@line_numbers ||= example_groups.inject([]) do |lines, g|
|
125
|
+
lines + g.declaration_line_numbers
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|