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,151 @@
1
+ require 'rspec/mocks/verifying_message_expecation'
2
+ require 'rspec/mocks/method_reference'
3
+
4
+ module RSpec
5
+ module Mocks
6
+
7
+ module VerifyingProxyMethods
8
+ def add_stub(location, method_name, opts={}, &implementation)
9
+ ensure_implemented(method_name)
10
+ super
11
+ end
12
+
13
+ def add_simple_stub(method_name, *args)
14
+ ensure_implemented(method_name)
15
+ super
16
+ end
17
+
18
+ def add_message_expectation(location, method_name, opts={}, &block)
19
+ ensure_implemented(method_name)
20
+ super
21
+ end
22
+
23
+ def ensure_implemented(method_name)
24
+ return unless @doubled_module.defined?
25
+
26
+ method_reference[method_name].when_unimplemented do
27
+ @error_generator.raise_unimplemented_error(
28
+ @doubled_module,
29
+ method_name
30
+ )
31
+ end
32
+ end
33
+ end
34
+
35
+ # A verifying proxy mostly acts like a normal proxy, except that it
36
+ # contains extra logic to try and determine the validity of any expectation
37
+ # set on it. This includes whether or not methods have been defined and the
38
+ # arity of method calls.
39
+ #
40
+ # In all other ways this behaves like a normal proxy. It only adds the
41
+ # verification behaviour to specific methods then delegates to the parent
42
+ # implementation.
43
+ #
44
+ # These checks are only activated if the doubled class has already been
45
+ # loaded, otherwise they are disabled. This allows for testing in
46
+ # isolation.
47
+ #
48
+ # @api private
49
+ class VerifyingProxy < Proxy
50
+ include VerifyingProxyMethods
51
+
52
+ def initialize(object, order_group, name, method_reference_class)
53
+ super(object, order_group)
54
+ @object = object
55
+ @doubled_module = name
56
+ @method_reference_class = method_reference_class
57
+
58
+ # A custom method double is required to pass through a way to lookup
59
+ # methods to determine their arity. This is only relevant if the doubled
60
+ # class is loaded.
61
+ @method_doubles = Hash.new do |h, k|
62
+ h[k] = VerifyingMethodDouble.new(@object, k, self, method_reference[k])
63
+ end
64
+ end
65
+
66
+ def method_reference
67
+ @method_reference ||= Hash.new do |h, k|
68
+ h[k] = @method_reference_class.new(@doubled_module, k)
69
+ end
70
+ end
71
+ end
72
+
73
+ class VerifyingPartialMockProxy < PartialMockProxy
74
+ include VerifyingProxyMethods
75
+
76
+ def initialize(object, expectation_ordering)
77
+ super(object, expectation_ordering)
78
+ @doubled_module = DirectObjectReference.new(object)
79
+
80
+ # A custom method double is required to pass through a way to lookup
81
+ # methods to determine their arity.
82
+ @method_doubles = Hash.new do |h, k|
83
+ h[k] = VerifyingExistingMethodDouble.new(object, k, self)
84
+ end
85
+ end
86
+
87
+ def method_reference
88
+ @method_doubles
89
+ end
90
+ end
91
+
92
+ # @api private
93
+ class VerifyingMethodDouble < MethodDouble
94
+ def initialize(object, method_name, proxy, method_reference)
95
+ super(object, method_name, proxy)
96
+ @method_reference = method_reference
97
+ end
98
+
99
+ def message_expectation_class
100
+ VerifyingMessageExpectation
101
+ end
102
+
103
+ def add_expectation(*arg)
104
+ super.tap { |x| x.method_reference = @method_reference }
105
+ end
106
+
107
+ def proxy_method_invoked(obj, *args, &block)
108
+ ensure_arity!(args.length)
109
+ super
110
+ end
111
+
112
+ private
113
+
114
+ def ensure_arity!(arity)
115
+ @method_reference.when_defined do |method|
116
+ calculator = ArityCalculator.new(method)
117
+ unless calculator.within_range?(arity)
118
+ raise ArgumentError, "wrong number of arguments (#{arity} for #{method.arity})"
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+ # @api private
125
+ #
126
+ # A VerifyingMethodDouble fetches the method to verify against from the
127
+ # original object, using a MethodReference. This works for pure doubles,
128
+ # but when the original object is itself the one being modified we need to
129
+ # collapse the reference and the method double into a single object so that
130
+ # we can access the original pristine method definition.
131
+ class VerifyingExistingMethodDouble < VerifyingMethodDouble
132
+ def initialize(object, method_name, proxy)
133
+ super(object, method_name, proxy, self)
134
+
135
+ @valid_method = object.respond_to?(method_name)
136
+
137
+ # Trigger an eager find of the original method since if we find it any
138
+ # later we end up getting a stubbed method with incorrect arity.
139
+ save_original_method!
140
+ end
141
+
142
+ def when_defined
143
+ yield original_method
144
+ end
145
+
146
+ def when_unimplemented
147
+ yield unless @valid_method
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,7 @@
1
+ module RSpec
2
+ module Mocks
3
+ module Version
4
+ STRING = '3.0.0.beta1'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,100 @@
1
+ require 'rspec/mocks/framework'
2
+ require 'rspec/mocks/version'
3
+
4
+ module RSpec
5
+
6
+ module Mocks
7
+ class << self
8
+ attr_accessor :space
9
+
10
+ def setup(host)
11
+ (class << host; self; end).class_exec do
12
+ include RSpec::Mocks::ExampleMethods
13
+ end
14
+ self.space ||= RSpec::Mocks::Space.new
15
+ end
16
+
17
+ def verify
18
+ space.verify_all
19
+ end
20
+
21
+ def teardown
22
+ space.reset_all
23
+ end
24
+
25
+ def proxy_for(object)
26
+ space.proxy_for(object)
27
+ end
28
+
29
+ def proxies_of(klass)
30
+ space.proxies_of(klass)
31
+ end
32
+
33
+ def any_instance_recorder_for(klass)
34
+ space.any_instance_recorder_for(klass)
35
+ end
36
+
37
+ # Adds an allowance (stub) on `subject`
38
+ #
39
+ # @param subject the subject to which the message will be added
40
+ # @param message a symbol, representing the message that will be
41
+ # added.
42
+ # @param opts a hash of options, :expected_from is used to set the
43
+ # original call site
44
+ # @param block an optional implementation for the allowance
45
+ #
46
+ # @example Defines the implementation of `foo` on `bar`, using the passed block
47
+ # x = 0
48
+ # RSpec::Mocks.allow_message(bar, :foo) { x += 1 }
49
+ def allow_message(subject, message, opts={}, &block)
50
+ orig_caller = opts.fetch(:expected_from) {
51
+ CallerFilter.first_non_rspec_line
52
+ }
53
+ ::RSpec::Mocks.proxy_for(subject).
54
+ add_stub(orig_caller, message, opts, &block)
55
+ end
56
+
57
+ # Sets a message expectation on `subject`.
58
+ # @param subject the subject on which the message will be expected
59
+ # @param message a symbol, representing the message that will be
60
+ # expected.
61
+ # @param opts a hash of options, :expected_from is used to set the
62
+ # original call site
63
+ # @param block an optional implementation for the expectation
64
+ #
65
+ # @example Expect the message `foo` to receive `bar`, then call it
66
+ # RSpec::Mocks.expect_message(bar, :foo)
67
+ # bar.foo
68
+ def expect_message(subject, message, opts={}, &block)
69
+ orig_caller = opts.fetch(:expected_from) {
70
+ CallerFilter.first_non_rspec_line
71
+ }
72
+ ::RSpec::Mocks.proxy_for(subject).
73
+ add_message_expectation(orig_caller, message, opts, &block)
74
+ end
75
+
76
+ # @api private
77
+ KERNEL_METHOD_METHOD = ::Kernel.instance_method(:method)
78
+
79
+ # @api private
80
+ # Used internally to get a method handle for a particular object
81
+ # and method name.
82
+ #
83
+ # Includes handling for a few special cases:
84
+ #
85
+ # - Objects that redefine #method (e.g. an HTTPRequest struct)
86
+ # - BasicObject subclasses that mixin a Kernel dup (e.g. SimpleDelegator)
87
+ def method_handle_for(object, method_name)
88
+ if ::Kernel === object
89
+ KERNEL_METHOD_METHOD.bind(object).call(method_name)
90
+ else
91
+ object.method(method_name)
92
+ end
93
+ end
94
+ end
95
+
96
+ # @private
97
+ IGNORED_BACKTRACE_LINE = 'this backtrace line is ignored'
98
+ end
99
+ end
100
+
@@ -0,0 +1,56 @@
1
+ module RSpec
2
+ # Consistent implementation for "cleaning" the caller method to strip out
3
+ # non-rspec lines. This enables errors to be reported at the call site in
4
+ # the code using the library, which is far more useful than the particular
5
+ # internal method that raised an error.
6
+ class CallerFilter
7
+
8
+ RSPEC_LIBS = %w[
9
+ core
10
+ mocks
11
+ expectations
12
+ support
13
+ matchers
14
+ rails
15
+ ]
16
+
17
+ ADDITIONAL_TOP_LEVEL_FILES = %w[ autorun ]
18
+
19
+ LIB_REGEX = %r{/lib/rspec/(#{(RSPEC_LIBS + ADDITIONAL_TOP_LEVEL_FILES).join('|')})(\.rb|/)}
20
+
21
+ if RUBY_VERSION >= '2.0.0'
22
+ def self.first_non_rspec_line
23
+ # `caller` is an expensive method that scales linearly with the size of
24
+ # the stack. The performance hit for fetching it in chunks is small,
25
+ # and since the target line is probably near the top of the stack, the
26
+ # overall improvement of a chunked search like this is significant.
27
+ #
28
+ # See benchmarks/caller.rb for measurements.
29
+
30
+ # Initial value here is mostly arbitrary, but is chosen to give good
31
+ # performance on the common case of creating a double.
32
+ increment = 5
33
+ i = 1
34
+ line = nil
35
+
36
+ while !line
37
+ stack = caller(i, increment)
38
+ raise "No non-lib lines in stack" unless stack
39
+
40
+ line = stack.find { |l| l !~ LIB_REGEX }
41
+
42
+ i += increment
43
+ increment *= 2 # The choice of two here is arbitrary.
44
+ end
45
+
46
+ line
47
+ end
48
+ else
49
+ # Earlier rubies do not support the two argument form of `caller`. This
50
+ # fallback is logically the same, but slower.
51
+ def self.first_non_rspec_line
52
+ caller.find { |line| line !~ LIB_REGEX }
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,29 @@
1
+ module RSpecHelpers
2
+ def expect_deprecation_with_call_site(file, line)
3
+ expect(RSpec.configuration.reporter).to receive(:deprecation) do |options|
4
+ expect(options[:call_site]).to include([file, line].join(':'))
5
+ end
6
+ end
7
+
8
+ def allow_deprecation
9
+ allow(RSpec.configuration.reporter).to receive(:deprecation)
10
+ end
11
+
12
+ def expect_warning_without_call_site(expected = //)
13
+ expect(::Kernel).to receive(:warn) do |message|
14
+ expect(message).to match expected
15
+ expect(message).to_not match(/Called from/)
16
+ end
17
+ end
18
+
19
+ def expect_warning_with_call_site(file, line, expected = //)
20
+ expect(::Kernel).to receive(:warn) do |message|
21
+ expect(message).to match expected
22
+ expect(message).to match(/Called from #{file}:#{line}/)
23
+ end
24
+ end
25
+
26
+ def allow_warning
27
+ allow(::Kernel).to receive(:warn)
28
+ end
29
+ end
@@ -0,0 +1,40 @@
1
+ module RSpec
2
+ module Support
3
+ module InSubProcess
4
+ if Process.respond_to?(:fork) && !(RUBY_PLATFORM == 'java' && RUBY_VERSION == '1.8.7')
5
+ # Useful as a way to isolate a global change to a subprocess.
6
+ def in_sub_process
7
+ readme, writeme = IO.pipe
8
+
9
+ pid = Process.fork do
10
+ exception = nil
11
+ begin
12
+ yield
13
+ rescue Exception => e
14
+ exception = e
15
+ end
16
+
17
+ writeme.write Marshal.dump(exception)
18
+
19
+ readme.close
20
+ writeme.close
21
+ exit! # prevent at_exit hooks from running (e.g. minitest)
22
+ end
23
+
24
+ writeme.close
25
+ Process.waitpid(pid)
26
+
27
+ exception = Marshal.load(readme.read)
28
+ readme.close
29
+
30
+ raise exception if exception
31
+ end
32
+ else
33
+ def in_sub_process
34
+ pending "This spec requires forking to work properly, " +
35
+ "and your platform does not support forking"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,50 @@
1
+ require 'stringio'
2
+
3
+ module RSpec
4
+ module Support
5
+ class StdErrSplitter < (defined?(::BasicObject) ? ::BasicObject : ::Object)
6
+ def initialize(original)
7
+ @orig_stderr = original
8
+ @output_tracker = ::StringIO.new
9
+ end
10
+
11
+ respond_to_name = (::RUBY_VERSION.to_f < 1.9) ? :respond_to? : :respond_to_missing?
12
+ define_method respond_to_name do |*args|
13
+ @orig_stderr.respond_to?(*args) || super
14
+ end
15
+
16
+ def method_missing(name, *args, &block)
17
+ @output_tracker.__send__(name, *args, &block)
18
+ @orig_stderr.__send__(name, *args, &block)
19
+ end
20
+
21
+ def ==(other)
22
+ @orig_stderr == other
23
+ end
24
+
25
+ # To work around JRuby error:
26
+ # TypeError: $stderr must have write method, RSpec::StdErrSplitter given
27
+ def write(*args)
28
+ @orig_stderr.write(*args)
29
+ @output_tracker.write(*args)
30
+ end
31
+
32
+ def has_output?
33
+ !output.empty?
34
+ end
35
+
36
+ def reset!
37
+ @output_tracker = ::StringIO.new
38
+ end
39
+
40
+ def verify_example!(example)
41
+ example.send(:fail,"Warnings were generated: #{output}") if has_output?
42
+ reset!
43
+ end
44
+
45
+ def output
46
+ @output_tracker.string
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,14 @@
1
+ require 'rspec/support/spec/deprecation_helpers'
2
+ require 'rspec/support/spec/stderr_splitter'
3
+
4
+ warning_preventer = $stderr = RSpec::Support::StdErrSplitter.new($stderr)
5
+
6
+ RSpec.configure do |c|
7
+ c.include RSpecHelpers
8
+ c.before do
9
+ warning_preventer.reset!
10
+ end
11
+ c.after do |example|
12
+ warning_preventer.verify_example!(example)
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ module RSpec
2
+ module Support
3
+ module Version
4
+ STRING = '3.0.0.beta1'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,41 @@
1
+ module RSpec
2
+
3
+ unless respond_to?(:deprecate)
4
+
5
+ # @private
6
+ #
7
+ # Used internally to print deprecation warnings
8
+ # when rspec-core isn't loaded
9
+ def self.deprecate(deprecated, options = {})
10
+ warn_with "DEPRECATION: #{deprecated} is deprecated.", options
11
+ end
12
+ end
13
+
14
+ unless respond_to?(:warn_deprecation)
15
+
16
+ # @private
17
+ #
18
+ # Used internally to print deprecation warnings
19
+ # when rspec-core isn't loaded
20
+ def self.warn_deprecation(message)
21
+ warn_with "DEPRECATION: \n #{message}"
22
+ end
23
+ end
24
+
25
+ # @private
26
+ #
27
+ # Used internally to print warnings
28
+ def self.warning(text, options={})
29
+ warn_with "WARNING: #{text}.", options
30
+ end
31
+
32
+ # @private
33
+ #
34
+ # Used internally to print longer warnings
35
+ def self.warn_with(message, options = {})
36
+ call_site = options.fetch(:call_site) { CallerFilter.first_non_rspec_line }
37
+ message << " Called from #{call_site}." if call_site
38
+ ::Kernel.warn message
39
+ end
40
+
41
+ end
@@ -0,0 +1,6 @@
1
+ require "rspec/support/version"
2
+
3
+ module RSpec
4
+ module Support
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module RSpec # :nodoc:
2
+ module Version # :nodoc:
3
+ STRING = '3.0.0.beta1'
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require "rspec/expectations"
@@ -0,0 +1,3 @@
1
+ require 'rspec/core'
2
+ require 'rspec/version'
3
+