opal-rspec 0.4.0.beta3 → 0.4.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.gitmodules +15 -0
  4. data/.travis.yml +12 -0
  5. data/.yardopts +5 -0
  6. data/CHANGELOG.md +3 -1
  7. data/Gemfile +6 -7
  8. data/README.md +2 -0
  9. data/Rakefile +12 -50
  10. data/lib/opal/rspec/version.rb +1 -1
  11. data/lib/opal/rspec.rb +14 -0
  12. data/opal/opal/rspec/async.rb +146 -11
  13. data/opal/opal/rspec/fixes.rb +18 -8
  14. data/opal/opal/rspec/requires.rb +45 -0
  15. data/opal/opal/rspec.rb +1 -24
  16. data/opal-rspec.gemspec +1 -1
  17. data/spec/async_spec.rb +4 -5
  18. data/spec/matchers_spec.rb +20 -0
  19. data/spec/named_subject_spec.rb +11 -0
  20. data/spec/should_syntax_spec.rb +17 -0
  21. data/vendor_lib/rspec/autorun.rb +2 -0
  22. data/vendor_lib/rspec/core/backport_random.rb +302 -0
  23. data/vendor_lib/rspec/core/backtrace_formatter.rb +65 -0
  24. data/vendor_lib/rspec/core/command_line.rb +36 -0
  25. data/vendor_lib/rspec/core/configuration.rb +1129 -0
  26. data/vendor_lib/rspec/core/configuration_options.rb +143 -0
  27. data/vendor_lib/rspec/core/drb_command_line.rb +26 -0
  28. data/vendor_lib/rspec/core/drb_options.rb +87 -0
  29. data/vendor_lib/rspec/core/dsl.rb +26 -0
  30. data/vendor_lib/rspec/core/example.rb +312 -0
  31. data/vendor_lib/rspec/core/example_group.rb +540 -0
  32. data/vendor_lib/rspec/core/filter_manager.rb +224 -0
  33. data/vendor_lib/rspec/core/flat_map.rb +17 -0
  34. data/vendor_lib/rspec/core/formatters/base_formatter.rb +291 -0
  35. data/vendor_lib/rspec/core/formatters/base_text_formatter.rb +307 -0
  36. data/vendor_lib/rspec/core/formatters/deprecation_formatter.rb +193 -0
  37. data/vendor_lib/rspec/core/formatters/documentation_formatter.rb +67 -0
  38. data/vendor_lib/rspec/core/formatters/helpers.rb +82 -0
  39. data/vendor_lib/rspec/core/formatters/html_formatter.rb +155 -0
  40. data/vendor_lib/rspec/core/formatters/html_printer.rb +408 -0
  41. data/vendor_lib/rspec/core/formatters/json_formatter.rb +99 -0
  42. data/vendor_lib/rspec/core/formatters/progress_formatter.rb +32 -0
  43. data/vendor_lib/rspec/core/formatters/snippet_extractor.rb +101 -0
  44. data/vendor_lib/rspec/core/formatters.rb +54 -0
  45. data/vendor_lib/rspec/core/hooks.rb +535 -0
  46. data/vendor_lib/rspec/core/memoized_helpers.rb +431 -0
  47. data/vendor_lib/rspec/core/metadata.rb +313 -0
  48. data/vendor_lib/rspec/core/mocking/with_absolutely_nothing.rb +11 -0
  49. data/vendor_lib/rspec/core/mocking/with_flexmock.rb +27 -0
  50. data/vendor_lib/rspec/core/mocking/with_mocha.rb +52 -0
  51. data/vendor_lib/rspec/core/mocking/with_rr.rb +27 -0
  52. data/vendor_lib/rspec/core/mocking/with_rspec.rb +27 -0
  53. data/vendor_lib/rspec/core/option_parser.rb +234 -0
  54. data/vendor_lib/rspec/core/ordering.rb +154 -0
  55. data/vendor_lib/rspec/core/pending.rb +110 -0
  56. data/vendor_lib/rspec/core/project_initializer.rb +88 -0
  57. data/vendor_lib/rspec/core/rake_task.rb +128 -0
  58. data/vendor_lib/rspec/core/reporter.rb +132 -0
  59. data/vendor_lib/rspec/core/ruby_project.rb +44 -0
  60. data/vendor_lib/rspec/core/runner.rb +97 -0
  61. data/vendor_lib/rspec/core/shared_context.rb +53 -0
  62. data/vendor_lib/rspec/core/shared_example_group/collection.rb +27 -0
  63. data/vendor_lib/rspec/core/shared_example_group.rb +146 -0
  64. data/vendor_lib/rspec/core/version.rb +7 -0
  65. data/vendor_lib/rspec/core/warnings.rb +22 -0
  66. data/vendor_lib/rspec/core/world.rb +131 -0
  67. data/vendor_lib/rspec/core.rb +203 -0
  68. data/vendor_lib/rspec/expectations/differ.rb +154 -0
  69. data/vendor_lib/rspec/expectations/errors.rb +9 -0
  70. data/vendor_lib/rspec/expectations/expectation_target.rb +87 -0
  71. data/vendor_lib/rspec/expectations/extensions/object.rb +29 -0
  72. data/vendor_lib/rspec/expectations/extensions.rb +1 -0
  73. data/vendor_lib/rspec/expectations/fail_with.rb +79 -0
  74. data/vendor_lib/rspec/expectations/handler.rb +68 -0
  75. data/vendor_lib/rspec/expectations/syntax.rb +182 -0
  76. data/vendor_lib/rspec/expectations/version.rb +8 -0
  77. data/vendor_lib/rspec/expectations.rb +75 -0
  78. data/vendor_lib/rspec/matchers/built_in/base_matcher.rb +68 -0
  79. data/vendor_lib/rspec/matchers/built_in/be.rb +213 -0
  80. data/vendor_lib/rspec/matchers/built_in/be_instance_of.rb +15 -0
  81. data/vendor_lib/rspec/matchers/built_in/be_kind_of.rb +11 -0
  82. data/vendor_lib/rspec/matchers/built_in/be_within.rb +55 -0
  83. data/vendor_lib/rspec/matchers/built_in/change.rb +141 -0
  84. data/vendor_lib/rspec/matchers/built_in/cover.rb +21 -0
  85. data/vendor_lib/rspec/matchers/built_in/eq.rb +22 -0
  86. data/vendor_lib/rspec/matchers/built_in/eql.rb +23 -0
  87. data/vendor_lib/rspec/matchers/built_in/equal.rb +48 -0
  88. data/vendor_lib/rspec/matchers/built_in/exist.rb +26 -0
  89. data/vendor_lib/rspec/matchers/built_in/has.rb +48 -0
  90. data/vendor_lib/rspec/matchers/built_in/include.rb +61 -0
  91. data/vendor_lib/rspec/matchers/built_in/match.rb +17 -0
  92. data/vendor_lib/rspec/matchers/built_in/match_array.rb +51 -0
  93. data/vendor_lib/rspec/matchers/built_in/raise_error.rb +154 -0
  94. data/vendor_lib/rspec/matchers/built_in/respond_to.rb +74 -0
  95. data/vendor_lib/rspec/matchers/built_in/satisfy.rb +30 -0
  96. data/vendor_lib/rspec/matchers/built_in/start_and_end_with.rb +48 -0
  97. data/vendor_lib/rspec/matchers/built_in/throw_symbol.rb +94 -0
  98. data/vendor_lib/rspec/matchers/built_in/yield.rb +297 -0
  99. data/vendor_lib/rspec/matchers/built_in.rb +39 -0
  100. data/vendor_lib/rspec/matchers/compatibility.rb +14 -0
  101. data/vendor_lib/rspec/matchers/configuration.rb +113 -0
  102. data/vendor_lib/rspec/matchers/dsl.rb +23 -0
  103. data/vendor_lib/rspec/matchers/generated_descriptions.rb +35 -0
  104. data/vendor_lib/rspec/matchers/matcher.rb +301 -0
  105. data/vendor_lib/rspec/matchers/method_missing.rb +12 -0
  106. data/vendor_lib/rspec/matchers/operator_matcher.rb +99 -0
  107. data/vendor_lib/rspec/matchers/pretty.rb +70 -0
  108. data/vendor_lib/rspec/matchers/test_unit_integration.rb +11 -0
  109. data/vendor_lib/rspec/matchers.rb +633 -0
  110. data/vendor_lib/rspec/mocks/any_instance/chain.rb +92 -0
  111. data/vendor_lib/rspec/mocks/any_instance/expectation_chain.rb +47 -0
  112. data/vendor_lib/rspec/mocks/any_instance/message_chains.rb +75 -0
  113. data/vendor_lib/rspec/mocks/any_instance/recorder.rb +200 -0
  114. data/vendor_lib/rspec/mocks/any_instance/stub_chain.rb +45 -0
  115. data/vendor_lib/rspec/mocks/any_instance/stub_chain_chain.rb +23 -0
  116. data/vendor_lib/rspec/mocks/argument_list_matcher.rb +104 -0
  117. data/vendor_lib/rspec/mocks/argument_matchers.rb +264 -0
  118. data/vendor_lib/rspec/mocks/arity_calculator.rb +66 -0
  119. data/vendor_lib/rspec/mocks/configuration.rb +111 -0
  120. data/vendor_lib/rspec/mocks/error_generator.rb +203 -0
  121. data/vendor_lib/rspec/mocks/errors.rb +12 -0
  122. data/vendor_lib/rspec/mocks/example_methods.rb +201 -0
  123. data/vendor_lib/rspec/mocks/extensions/marshal.rb +17 -0
  124. data/vendor_lib/rspec/mocks/framework.rb +36 -0
  125. data/vendor_lib/rspec/mocks/instance_method_stasher.rb +112 -0
  126. data/vendor_lib/rspec/mocks/matchers/have_received.rb +99 -0
  127. data/vendor_lib/rspec/mocks/matchers/receive.rb +112 -0
  128. data/vendor_lib/rspec/mocks/matchers/receive_messages.rb +72 -0
  129. data/vendor_lib/rspec/mocks/message_expectation.rb +643 -0
  130. data/vendor_lib/rspec/mocks/method_double.rb +209 -0
  131. data/vendor_lib/rspec/mocks/method_reference.rb +95 -0
  132. data/vendor_lib/rspec/mocks/mock.rb +7 -0
  133. data/vendor_lib/rspec/mocks/mutate_const.rb +406 -0
  134. data/vendor_lib/rspec/mocks/object_reference.rb +90 -0
  135. data/vendor_lib/rspec/mocks/order_group.rb +82 -0
  136. data/vendor_lib/rspec/mocks/proxy.rb +269 -0
  137. data/vendor_lib/rspec/mocks/proxy_for_nil.rb +37 -0
  138. data/vendor_lib/rspec/mocks/space.rb +95 -0
  139. data/vendor_lib/rspec/mocks/standalone.rb +3 -0
  140. data/vendor_lib/rspec/mocks/stub_chain.rb +51 -0
  141. data/vendor_lib/rspec/mocks/syntax.rb +374 -0
  142. data/vendor_lib/rspec/mocks/targets.rb +90 -0
  143. data/vendor_lib/rspec/mocks/test_double.rb +109 -0
  144. data/vendor_lib/rspec/mocks/verifying_double.rb +77 -0
  145. data/vendor_lib/rspec/mocks/verifying_message_expecation.rb +60 -0
  146. data/vendor_lib/rspec/mocks/verifying_proxy.rb +151 -0
  147. data/vendor_lib/rspec/mocks/version.rb +7 -0
  148. data/vendor_lib/rspec/mocks.rb +100 -0
  149. data/vendor_lib/rspec/support/caller_filter.rb +56 -0
  150. data/vendor_lib/rspec/support/spec/deprecation_helpers.rb +29 -0
  151. data/vendor_lib/rspec/support/spec/in_sub_process.rb +40 -0
  152. data/vendor_lib/rspec/support/spec/stderr_splitter.rb +50 -0
  153. data/vendor_lib/rspec/support/spec.rb +14 -0
  154. data/vendor_lib/rspec/support/version.rb +7 -0
  155. data/vendor_lib/rspec/support/warnings.rb +41 -0
  156. data/vendor_lib/rspec/support.rb +6 -0
  157. data/vendor_lib/rspec/version.rb +5 -0
  158. data/vendor_lib/rspec-expectations.rb +1 -0
  159. data/vendor_lib/rspec.rb +3 -0
  160. metadata +163 -4
  161. data/opal/opal/rspec/rspec.js +0 -20384
@@ -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,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,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,7 @@
1
+ module RSpec
2
+ module Core
3
+ module Version
4
+ STRING = '3.0.0.beta1'
5
+ end
6
+ end
7
+ 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
@@ -0,0 +1,203 @@
1
+ require_rspec = if defined?(require_relative)
2
+ lambda do |path|
3
+ require_relative path
4
+ end
5
+ else # for 1.8.7
6
+ lambda do |path|
7
+ require "rspec/#{path}"
8
+ end
9
+ end
10
+
11
+ require 'set'
12
+ require 'time'
13
+ require 'rbconfig'
14
+
15
+ require_rspec['core/version']
16
+
17
+ require 'rspec/support/caller_filter'
18
+ require 'rspec/core/warnings'
19
+ require 'rspec/support/warnings'
20
+
21
+ require_rspec['core/flat_map']
22
+ require_rspec['core/filter_manager']
23
+ require_rspec['core/dsl']
24
+ require_rspec['core/reporter']
25
+
26
+ require_rspec['core/hooks']
27
+ require_rspec['core/memoized_helpers']
28
+ require_rspec['core/metadata']
29
+ require_rspec['core/pending']
30
+ require_rspec['core/formatters']
31
+ require_rspec['core/ordering']
32
+
33
+ require_rspec['core/world']
34
+ require_rspec['core/configuration']
35
+ require_rspec['core/option_parser']
36
+ require_rspec['core/configuration_options']
37
+ require_rspec['core/command_line']
38
+ require_rspec['core/runner']
39
+ require_rspec['core/example']
40
+ require_rspec['core/shared_example_group/collection']
41
+ require_rspec['core/shared_example_group']
42
+ require_rspec['core/example_group']
43
+
44
+ module RSpec
45
+ autoload :SharedContext, 'rspec/core/shared_context'
46
+
47
+ # @private
48
+ def self.wants_to_quit
49
+ # Used internally to determine what to do when a SIGINT is received
50
+ world.wants_to_quit
51
+ end
52
+
53
+ # @private
54
+ # Used internally to determine what to do when a SIGINT is received
55
+ def self.wants_to_quit=(maybe)
56
+ world.wants_to_quit=(maybe)
57
+ end
58
+
59
+ # @private
60
+ # Internal container for global non-configuration data
61
+ def self.world
62
+ @world ||= RSpec::Core::World.new
63
+ end
64
+
65
+ # @private
66
+ # Used internally to set the global object
67
+ def self.world=(new_world)
68
+ @world = new_world
69
+ end
70
+
71
+ # @private
72
+ # Used internally to ensure examples get reloaded between multiple runs in
73
+ # the same process.
74
+ def self.reset
75
+ @world = nil
76
+ @configuration = nil
77
+ end
78
+
79
+ # Returns the global [Configuration](RSpec/Core/Configuration) object. While you
80
+ # _can_ use this method to access the configuration, the more common
81
+ # convention is to use [RSpec.configure](RSpec#configure-class_method).
82
+ #
83
+ # @example
84
+ # RSpec.configuration.drb_port = 1234
85
+ # @see RSpec.configure
86
+ # @see Core::Configuration
87
+ def self.configuration
88
+ if block_given?
89
+ RSpec.warn_deprecation <<-WARNING
90
+
91
+ *****************************************************************
92
+ DEPRECATION WARNING
93
+
94
+ * RSpec.configuration with a block is deprecated and has no effect.
95
+ * please use RSpec.configure with a block instead.
96
+
97
+ Called from #{CallerFilter.first_non_rspec_line}
98
+ *****************************************************************
99
+
100
+ WARNING
101
+ end
102
+ @configuration ||= RSpec::Core::Configuration.new
103
+ end
104
+
105
+ # @private
106
+ # Used internally to set the global object
107
+ def self.configuration=(new_configuration)
108
+ @configuration = new_configuration
109
+ end
110
+
111
+ # Yields the global configuration to a block.
112
+ # @yield [Configuration] global configuration
113
+ #
114
+ # @example
115
+ # RSpec.configure do |config|
116
+ # config.add_formatter 'documentation'
117
+ # end
118
+ # @see Core::Configuration
119
+ def self.configure
120
+ yield configuration if block_given?
121
+ end
122
+
123
+ # @private
124
+ # Used internally to clear remaining groups when fail_fast is set
125
+ def self.clear_remaining_example_groups
126
+ world.example_groups.clear
127
+ end
128
+
129
+ # The example being executed.
130
+ #
131
+ # The primary audience for this method is library authors who need access
132
+ # to the example currently being executed and also want to support all
133
+ # versions of RSpec 2 and 3.
134
+ #
135
+ # @example
136
+ #
137
+ # RSpec.configure do |c|
138
+ # # context.example is deprecated, but RSpec.current_example is not
139
+ # # available until RSpec 3.0.
140
+ # fetch_current_example = RSpec.respond_to?(:current_example) ?
141
+ # proc { RSpec.current_example } : proc { |context| context.example }
142
+ #
143
+ # c.before(:each) do
144
+ # example = fetch_current_example.call(self)
145
+ #
146
+ # # ...
147
+ # end
148
+ # end
149
+ #
150
+ def self.current_example
151
+ Thread.current[:_rspec_current_example]
152
+ end
153
+
154
+ # Set the current example being executed.
155
+ # @api private
156
+ def self.current_example=(example)
157
+ Thread.current[:_rspec_current_example] = example
158
+ end
159
+
160
+ # @private
161
+ def self.windows_os?
162
+ RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/
163
+ end
164
+
165
+ module Core
166
+ # @private
167
+ # This avoids issues with reporting time caused by examples that
168
+ # change the value/meaning of Time.now without properly restoring
169
+ # it.
170
+ class Time
171
+ class << self
172
+ define_method(:now, &::Time.method(:now))
173
+ end
174
+ end
175
+
176
+ # @private path to executable file
177
+ def self.path_to_executable
178
+ @path_to_executable ||= File.expand_path('../../../exe/rspec', __FILE__)
179
+ end
180
+ end
181
+
182
+ MODULES_TO_AUTOLOAD = {
183
+ :Matchers => "rspec/expectations",
184
+ :Expectations => "rspec/expectations",
185
+ :Mocks => "rspec/mocks"
186
+ }
187
+
188
+ def self.const_missing(name)
189
+ # Load rspec-expectations when RSpec::Matchers is referenced. This allows
190
+ # people to define custom matchers (using `RSpec::Matchers.define`) before
191
+ # rspec-core has loaded rspec-expectations (since it delays the loading of
192
+ # it to allow users to configure a different assertion/expectation
193
+ # framework). `autoload` can't be used since it works with ruby's built-in
194
+ # require (e.g. for files that are available relative to a load path dir),
195
+ # but not with rubygems' extended require.
196
+ #
197
+ # As of rspec 2.14.1, we no longer require `rspec/mocks` and
198
+ # `rspec/expectations` when `rspec` is required, so we want
199
+ # to make them available as an autoload. For more info, see:
200
+ require MODULES_TO_AUTOLOAD.fetch(name) { return super }
201
+ ::RSpec.const_get(name)
202
+ end
203
+ end