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.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.gitmodules +15 -0
- data/.travis.yml +12 -0
- data/.yardopts +5 -0
- data/CHANGELOG.md +3 -1
- data/Gemfile +6 -7
- data/README.md +2 -0
- data/Rakefile +12 -50
- data/lib/opal/rspec/version.rb +1 -1
- data/lib/opal/rspec.rb +14 -0
- data/opal/opal/rspec/async.rb +146 -11
- data/opal/opal/rspec/fixes.rb +18 -8
- data/opal/opal/rspec/requires.rb +45 -0
- data/opal/opal/rspec.rb +1 -24
- data/opal-rspec.gemspec +1 -1
- data/spec/async_spec.rb +4 -5
- data/spec/matchers_spec.rb +20 -0
- data/spec/named_subject_spec.rb +11 -0
- data/spec/should_syntax_spec.rb +17 -0
- data/vendor_lib/rspec/autorun.rb +2 -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/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/formatters.rb +54 -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/collection.rb +27 -0
- data/vendor_lib/rspec/core/shared_example_group.rb +146 -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/core.rb +203 -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/object.rb +29 -0
- data/vendor_lib/rspec/expectations/extensions.rb +1 -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/expectations.rb +75 -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/built_in.rb +39 -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/matchers.rb +633 -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/mocks.rb +100 -0
- data/vendor_lib/rspec/support/caller_filter.rb +56 -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/spec.rb +14 -0
- data/vendor_lib/rspec/support/version.rb +7 -0
- data/vendor_lib/rspec/support/warnings.rb +41 -0
- data/vendor_lib/rspec/support.rb +6 -0
- data/vendor_lib/rspec/version.rb +5 -0
- data/vendor_lib/rspec-expectations.rb +1 -0
- data/vendor_lib/rspec.rb +3 -0
- metadata +163 -4
- data/opal/opal/rspec/rspec.js +0 -20384
@@ -0,0 +1,209 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Mocks
|
3
|
+
# @private
|
4
|
+
class MethodDouble
|
5
|
+
# @private
|
6
|
+
attr_reader :method_name, :object, :expectations, :stubs
|
7
|
+
|
8
|
+
# @private
|
9
|
+
def initialize(object, method_name, proxy)
|
10
|
+
@method_name = method_name
|
11
|
+
@object = object
|
12
|
+
@proxy = proxy
|
13
|
+
|
14
|
+
@original_visibility = nil
|
15
|
+
@method_stasher = InstanceMethodStasher.new(object, method_name)
|
16
|
+
@method_is_proxied = false
|
17
|
+
@expectations = []
|
18
|
+
@stubs = []
|
19
|
+
end
|
20
|
+
|
21
|
+
def original_method
|
22
|
+
# If original method is not present, uses the `method_missing`
|
23
|
+
# handler of the object. This accounts for cases where the user has not
|
24
|
+
# correctly defined `respond_to?`, and also 1.8 which does not provide
|
25
|
+
# method handles for missing methods even if `respond_to?` is correct.
|
26
|
+
@original_method ||=
|
27
|
+
@method_stasher.original_method ||
|
28
|
+
@proxy.method_handle_for(method_name) ||
|
29
|
+
Proc.new do |*args, &block|
|
30
|
+
@object.__send__(:method_missing, @method_name, *args, &block)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
alias_method :save_original_method!, :original_method
|
35
|
+
|
36
|
+
# @private
|
37
|
+
def visibility
|
38
|
+
if TestDouble === @object
|
39
|
+
'public'
|
40
|
+
elsif object_singleton_class.private_method_defined?(@method_name)
|
41
|
+
'private'
|
42
|
+
elsif object_singleton_class.protected_method_defined?(@method_name)
|
43
|
+
'protected'
|
44
|
+
else
|
45
|
+
'public'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# @private
|
50
|
+
def object_singleton_class
|
51
|
+
class << @object; self; end
|
52
|
+
end
|
53
|
+
|
54
|
+
# @private
|
55
|
+
def configure_method
|
56
|
+
@original_visibility = [visibility, method_name]
|
57
|
+
@method_stasher.stash unless @method_is_proxied
|
58
|
+
define_proxy_method
|
59
|
+
end
|
60
|
+
|
61
|
+
# @private
|
62
|
+
def define_proxy_method
|
63
|
+
return if @method_is_proxied
|
64
|
+
|
65
|
+
save_original_method!
|
66
|
+
|
67
|
+
object_singleton_class.class_exec(self, method_name, visibility) do |method_double, method_name, visibility|
|
68
|
+
define_method(method_name) do |*args, &block|
|
69
|
+
method_double.proxy_method_invoked(self, *args, &block)
|
70
|
+
end
|
71
|
+
self.__send__ visibility, method_name
|
72
|
+
end
|
73
|
+
|
74
|
+
@method_is_proxied = true
|
75
|
+
end
|
76
|
+
|
77
|
+
# The implementation of the proxied method. Subclasses may override this
|
78
|
+
# method to perform additional operations.
|
79
|
+
#
|
80
|
+
# @private
|
81
|
+
def proxy_method_invoked(obj, *args, &block)
|
82
|
+
@proxy.message_received method_name, *args, &block
|
83
|
+
end
|
84
|
+
|
85
|
+
# @private
|
86
|
+
def restore_original_method
|
87
|
+
return unless @method_is_proxied
|
88
|
+
|
89
|
+
object_singleton_class.__send__(:remove_method, @method_name)
|
90
|
+
if @method_stasher.method_is_stashed?
|
91
|
+
@method_stasher.restore
|
92
|
+
end
|
93
|
+
restore_original_visibility
|
94
|
+
|
95
|
+
@method_is_proxied = false
|
96
|
+
end
|
97
|
+
|
98
|
+
# @private
|
99
|
+
def restore_original_visibility
|
100
|
+
return unless @original_visibility &&
|
101
|
+
(object_singleton_class.method_defined?(@method_name) ||
|
102
|
+
object_singleton_class.private_method_defined?(@method_name))
|
103
|
+
|
104
|
+
object_singleton_class.__send__(*@original_visibility)
|
105
|
+
end
|
106
|
+
|
107
|
+
# @private
|
108
|
+
def verify
|
109
|
+
expectations.each {|e| e.verify_messages_received}
|
110
|
+
end
|
111
|
+
|
112
|
+
# @private
|
113
|
+
def reset
|
114
|
+
restore_original_method
|
115
|
+
clear
|
116
|
+
end
|
117
|
+
|
118
|
+
# @private
|
119
|
+
def clear
|
120
|
+
expectations.clear
|
121
|
+
stubs.clear
|
122
|
+
end
|
123
|
+
|
124
|
+
# The type of message expectation to create has been extracted to its own
|
125
|
+
# method so that subclasses can override it.
|
126
|
+
#
|
127
|
+
# @private
|
128
|
+
def message_expectation_class
|
129
|
+
MessageExpectation
|
130
|
+
end
|
131
|
+
|
132
|
+
# @private
|
133
|
+
def add_expectation(error_generator, expectation_ordering, expected_from, opts, &implementation)
|
134
|
+
configure_method
|
135
|
+
expectation = message_expectation_class.new(error_generator, expectation_ordering,
|
136
|
+
expected_from, self, 1, opts, &implementation)
|
137
|
+
expectations << expectation
|
138
|
+
expectation
|
139
|
+
end
|
140
|
+
|
141
|
+
# @private
|
142
|
+
def build_expectation(error_generator, expectation_ordering)
|
143
|
+
expected_from = IGNORED_BACKTRACE_LINE
|
144
|
+
message_expectation_class.new(error_generator, expectation_ordering, expected_from, self)
|
145
|
+
end
|
146
|
+
|
147
|
+
# @private
|
148
|
+
def add_stub(error_generator, expectation_ordering, expected_from, opts={}, &implementation)
|
149
|
+
configure_method
|
150
|
+
stub = message_expectation_class.new(error_generator, expectation_ordering, expected_from,
|
151
|
+
self, :any, opts, &implementation)
|
152
|
+
stubs.unshift stub
|
153
|
+
stub
|
154
|
+
end
|
155
|
+
|
156
|
+
# A simple stub can only return a concrete value for a message, and
|
157
|
+
# cannot match on arguments. It is used as an optimization over
|
158
|
+
# `add_stub` / `add_expectation` where it is known in advance that this
|
159
|
+
# is all that will be required of a stub, such as when passing attributes
|
160
|
+
# to the `double` example method. They do not stash or restore existing method
|
161
|
+
# definitions.
|
162
|
+
#
|
163
|
+
# @private
|
164
|
+
def add_simple_stub(method_name, response)
|
165
|
+
setup_simple_method_double method_name, response, stubs
|
166
|
+
end
|
167
|
+
|
168
|
+
# @private
|
169
|
+
def add_simple_expectation(method_name, response, error_generator, backtrace_line)
|
170
|
+
setup_simple_method_double method_name, response, expectations, error_generator, backtrace_line
|
171
|
+
end
|
172
|
+
|
173
|
+
# @private
|
174
|
+
def setup_simple_method_double(method_name, response, collection, error_generator = nil, backtrace_line = nil)
|
175
|
+
define_proxy_method
|
176
|
+
|
177
|
+
me = SimpleMessageExpectation.new(method_name, response, error_generator, backtrace_line)
|
178
|
+
collection.unshift me
|
179
|
+
me
|
180
|
+
end
|
181
|
+
|
182
|
+
# @private
|
183
|
+
def add_default_stub(*args, &implementation)
|
184
|
+
return if stubs.any?
|
185
|
+
add_stub(*args, &implementation)
|
186
|
+
end
|
187
|
+
|
188
|
+
# @private
|
189
|
+
def remove_stub
|
190
|
+
raise_method_not_stubbed_error if stubs.empty?
|
191
|
+
expectations.empty? ? reset : stubs.clear
|
192
|
+
end
|
193
|
+
|
194
|
+
# @private
|
195
|
+
def remove_single_stub(stub)
|
196
|
+
stubs.delete(stub)
|
197
|
+
restore_original_method if stubs.empty? && expectations.empty?
|
198
|
+
end
|
199
|
+
|
200
|
+
# @private
|
201
|
+
def raise_method_not_stubbed_error
|
202
|
+
raise MockExpectationError, "The method `#{method_name}` was not stubbed or was already unstubbed"
|
203
|
+
end
|
204
|
+
|
205
|
+
# @private
|
206
|
+
IGNORED_BACKTRACE_LINE = 'this backtrace line is ignored'
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Mocks
|
3
|
+
# Represents a method on a module that may or may not be defined.
|
4
|
+
#
|
5
|
+
# @private
|
6
|
+
class MethodReference
|
7
|
+
def initialize(module_reference, method_name)
|
8
|
+
@module_reference = module_reference
|
9
|
+
@method_name = method_name
|
10
|
+
end
|
11
|
+
|
12
|
+
# A method is implemented if sending the message does not result in
|
13
|
+
# a `NoMethodError`. It might be dynamically implemented by
|
14
|
+
# `method_missing`.
|
15
|
+
def implemented?
|
16
|
+
@module_reference.when_loaded do |m|
|
17
|
+
method_implemented?(m)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# A method is defined if we are able to get a `Method` object for it.
|
22
|
+
# In that case, we can assert against metadata like the arity.
|
23
|
+
def defined?
|
24
|
+
@module_reference.when_loaded do |m|
|
25
|
+
method_defined?(m)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def when_defined
|
30
|
+
if original = original_method
|
31
|
+
yield original
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Yields to the block if the method is not implemented.
|
36
|
+
def when_unimplemented
|
37
|
+
yield unless implemented?
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def original_method
|
42
|
+
@module_reference.when_loaded do |m|
|
43
|
+
self.defined? && find_method(m)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# @private
|
49
|
+
class InstanceMethodReference < MethodReference
|
50
|
+
private
|
51
|
+
def method_implemented?(m)
|
52
|
+
m.method_defined?(@method_name)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Ideally, we'd use `respond_to?` for `method_implemented?` but we need a
|
56
|
+
# reference to an instance to do that and we don't have one. Note that
|
57
|
+
# we may get false negatives: if the method is implemented via
|
58
|
+
# `method_missing`, we'll return `false` even though it meets our
|
59
|
+
# definition of "implemented". However, it's the best we can do.
|
60
|
+
alias method_defined? method_implemented?
|
61
|
+
|
62
|
+
# works around the fact that repeated calls for method parameters will
|
63
|
+
# falsely return empty arrays on JRuby in certain circumstances, this
|
64
|
+
# is necessary here because we can't dup/clone UnboundMethods.
|
65
|
+
#
|
66
|
+
# This is necessary due to a bug in JRuby prior to 1.7.5 fixed in:
|
67
|
+
# https://github.com/jruby/jruby/commit/99a0613fe29935150d76a9a1ee4cf2b4f63f4a27
|
68
|
+
if RUBY_PLATFORM == 'java' && JRUBY_VERSION.split('.')[-1].to_i < 5
|
69
|
+
def find_method(m)
|
70
|
+
m.dup.instance_method(@method_name)
|
71
|
+
end
|
72
|
+
else
|
73
|
+
def find_method(m)
|
74
|
+
m.instance_method(@method_name)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# @private
|
80
|
+
class ObjectMethodReference < MethodReference
|
81
|
+
private
|
82
|
+
def method_implemented?(m)
|
83
|
+
m.respond_to?(@method_name)
|
84
|
+
end
|
85
|
+
|
86
|
+
def method_defined?(m)
|
87
|
+
(class << m; self; end).method_defined?(@method_name)
|
88
|
+
end
|
89
|
+
|
90
|
+
def find_method(m)
|
91
|
+
m.method(@method_name)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|