floehopper-mocha 0.9.3.20081220175348
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +3 -0
- data/MIT-LICENSE +7 -0
- data/README +35 -0
- data/RELEASE +257 -0
- data/Rakefile +199 -0
- data/examples/misc.rb +44 -0
- data/examples/mocha.rb +26 -0
- data/examples/stubba.rb +65 -0
- data/lib/mocha/any_instance_method.rb +54 -0
- data/lib/mocha/argument_iterator.rb +21 -0
- data/lib/mocha/backtrace_filter.rb +17 -0
- data/lib/mocha/cardinality.rb +95 -0
- data/lib/mocha/central.rb +27 -0
- data/lib/mocha/change_state_side_effect.rb +19 -0
- data/lib/mocha/class_method.rb +86 -0
- data/lib/mocha/configuration.rb +60 -0
- data/lib/mocha/deprecation.rb +22 -0
- data/lib/mocha/exception_raiser.rb +17 -0
- data/lib/mocha/expectation.rb +451 -0
- data/lib/mocha/expectation_error.rb +15 -0
- data/lib/mocha/expectation_list.rb +50 -0
- data/lib/mocha/in_state_ordering_constraint.rb +19 -0
- data/lib/mocha/inspect.rb +67 -0
- data/lib/mocha/instance_method.rb +16 -0
- data/lib/mocha/is_a.rb +9 -0
- data/lib/mocha/logger.rb +15 -0
- data/lib/mocha/metaclass.rb +13 -0
- data/lib/mocha/method_matcher.rb +21 -0
- data/lib/mocha/mini_test_adapter.rb +50 -0
- data/lib/mocha/mock.rb +200 -0
- data/lib/mocha/mockery.rb +181 -0
- data/lib/mocha/module_method.rb +16 -0
- data/lib/mocha/multiple_yields.rb +20 -0
- data/lib/mocha/names.rb +53 -0
- data/lib/mocha/no_yields.rb +11 -0
- data/lib/mocha/object.rb +187 -0
- data/lib/mocha/parameter_matchers/all_of.rb +42 -0
- data/lib/mocha/parameter_matchers/any_of.rb +47 -0
- data/lib/mocha/parameter_matchers/any_parameters.rb +40 -0
- data/lib/mocha/parameter_matchers/anything.rb +33 -0
- data/lib/mocha/parameter_matchers/base.rb +15 -0
- data/lib/mocha/parameter_matchers/equals.rb +42 -0
- data/lib/mocha/parameter_matchers/has_entries.rb +45 -0
- data/lib/mocha/parameter_matchers/has_entry.rb +56 -0
- data/lib/mocha/parameter_matchers/has_key.rb +42 -0
- data/lib/mocha/parameter_matchers/has_value.rb +42 -0
- data/lib/mocha/parameter_matchers/includes.rb +40 -0
- data/lib/mocha/parameter_matchers/instance_of.rb +42 -0
- data/lib/mocha/parameter_matchers/is_a.rb +42 -0
- data/lib/mocha/parameter_matchers/kind_of.rb +42 -0
- data/lib/mocha/parameter_matchers/not.rb +42 -0
- data/lib/mocha/parameter_matchers/object.rb +15 -0
- data/lib/mocha/parameter_matchers/optionally.rb +55 -0
- data/lib/mocha/parameter_matchers/regexp_matches.rb +43 -0
- data/lib/mocha/parameter_matchers/responds_with.rb +43 -0
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +43 -0
- data/lib/mocha/parameter_matchers.rb +27 -0
- data/lib/mocha/parameters_matcher.rb +37 -0
- data/lib/mocha/pretty_parameters.rb +28 -0
- data/lib/mocha/return_values.rb +31 -0
- data/lib/mocha/sequence.rb +42 -0
- data/lib/mocha/single_return_value.rb +17 -0
- data/lib/mocha/single_yield.rb +18 -0
- data/lib/mocha/standalone.rb +166 -0
- data/lib/mocha/state_machine.rb +91 -0
- data/lib/mocha/stubbing_error.rb +16 -0
- data/lib/mocha/test_case_adapter.rb +103 -0
- data/lib/mocha/unexpected_invocation.rb +18 -0
- data/lib/mocha/yield_parameters.rb +31 -0
- data/lib/mocha.rb +47 -0
- data/lib/mocha_standalone.rb +2 -0
- data/lib/stubba.rb +4 -0
- data/test/acceptance/acceptance_test_helper.rb +38 -0
- data/test/acceptance/bug_18914_test.rb +43 -0
- data/test/acceptance/bug_21465_test.rb +34 -0
- data/test/acceptance/bug_21563_test.rb +25 -0
- data/test/acceptance/expected_invocation_count_test.rb +196 -0
- data/test/acceptance/failure_messages_test.rb +64 -0
- data/test/acceptance/minitest_test.rb +130 -0
- data/test/acceptance/mocha_example_test.rb +98 -0
- data/test/acceptance/mocha_test_result_test.rb +84 -0
- data/test/acceptance/mock_test.rb +100 -0
- data/test/acceptance/mock_with_initializer_block_test.rb +51 -0
- data/test/acceptance/mocked_methods_dispatch_test.rb +78 -0
- data/test/acceptance/optional_parameters_test.rb +70 -0
- data/test/acceptance/parameter_matcher_test.rb +209 -0
- data/test/acceptance/partial_mocks_test.rb +47 -0
- data/test/acceptance/return_value_test.rb +52 -0
- data/test/acceptance/sequence_test.rb +186 -0
- data/test/acceptance/standalone_test.rb +139 -0
- data/test/acceptance/states_test.rb +70 -0
- data/test/acceptance/stub_any_instance_method_test.rb +195 -0
- data/test/acceptance/stub_class_method_test.rb +203 -0
- data/test/acceptance/stub_everything_test.rb +56 -0
- data/test/acceptance/stub_instance_method_test.rb +203 -0
- data/test/acceptance/stub_module_method_test.rb +163 -0
- data/test/acceptance/stub_test.rb +52 -0
- data/test/acceptance/stubba_example_test.rb +102 -0
- data/test/acceptance/stubba_test.rb +15 -0
- data/test/acceptance/stubba_test_result_test.rb +66 -0
- data/test/acceptance/stubbing_error_backtrace_test.rb +64 -0
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +65 -0
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +130 -0
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +157 -0
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +147 -0
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +130 -0
- data/test/acceptance/stubbing_non_public_class_method_test.rb +163 -0
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +143 -0
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +64 -0
- data/test/deprecation_disabler.rb +15 -0
- data/test/execution_point.rb +36 -0
- data/test/method_definer.rb +24 -0
- data/test/simple_counter.rb +13 -0
- data/test/test_helper.rb +11 -0
- data/test/test_runner.rb +33 -0
- data/test/unit/any_instance_method_test.rb +126 -0
- data/test/unit/array_inspect_test.rb +16 -0
- data/test/unit/backtrace_filter_test.rb +19 -0
- data/test/unit/cardinality_test.rb +56 -0
- data/test/unit/central_test.rb +65 -0
- data/test/unit/change_state_side_effect_test.rb +41 -0
- data/test/unit/class_method_test.rb +237 -0
- data/test/unit/date_time_inspect_test.rb +21 -0
- data/test/unit/exception_raiser_test.rb +42 -0
- data/test/unit/expectation_list_test.rb +57 -0
- data/test/unit/expectation_test.rb +459 -0
- data/test/unit/hash_inspect_test.rb +16 -0
- data/test/unit/in_state_ordering_constraint_test.rb +43 -0
- data/test/unit/metaclass_test.rb +22 -0
- data/test/unit/method_matcher_test.rb +23 -0
- data/test/unit/mock_test.rb +295 -0
- data/test/unit/mockery_test.rb +149 -0
- data/test/unit/multiple_yields_test.rb +18 -0
- data/test/unit/no_yields_test.rb +18 -0
- data/test/unit/object_inspect_test.rb +37 -0
- data/test/unit/object_test.rb +82 -0
- data/test/unit/parameter_matchers/all_of_test.rb +26 -0
- data/test/unit/parameter_matchers/any_of_test.rb +26 -0
- data/test/unit/parameter_matchers/anything_test.rb +21 -0
- data/test/unit/parameter_matchers/equals_test.rb +25 -0
- data/test/unit/parameter_matchers/has_entries_test.rb +51 -0
- data/test/unit/parameter_matchers/has_entry_test.rb +62 -0
- data/test/unit/parameter_matchers/has_key_test.rb +36 -0
- data/test/unit/parameter_matchers/has_value_test.rb +37 -0
- data/test/unit/parameter_matchers/includes_test.rb +25 -0
- data/test/unit/parameter_matchers/instance_of_test.rb +25 -0
- data/test/unit/parameter_matchers/is_a_test.rb +25 -0
- data/test/unit/parameter_matchers/kind_of_test.rb +25 -0
- data/test/unit/parameter_matchers/not_test.rb +26 -0
- data/test/unit/parameter_matchers/regexp_matches_test.rb +25 -0
- data/test/unit/parameter_matchers/responds_with_test.rb +25 -0
- data/test/unit/parameter_matchers/stub_matcher.rb +27 -0
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +25 -0
- data/test/unit/parameters_matcher_test.rb +121 -0
- data/test/unit/return_values_test.rb +63 -0
- data/test/unit/sequence_test.rb +104 -0
- data/test/unit/single_return_value_test.rb +14 -0
- data/test/unit/single_yield_test.rb +18 -0
- data/test/unit/state_machine_test.rb +98 -0
- data/test/unit/string_inspect_test.rb +11 -0
- data/test/unit/yield_parameters_test.rb +93 -0
- metadata +226 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'mocha/class_method'
|
2
|
+
|
3
|
+
module Mocha
|
4
|
+
|
5
|
+
class AnyInstanceMethod < ClassMethod
|
6
|
+
|
7
|
+
def unstub
|
8
|
+
remove_new_method
|
9
|
+
restore_original_method
|
10
|
+
stubbee.any_instance.reset_mocha
|
11
|
+
end
|
12
|
+
|
13
|
+
def mock
|
14
|
+
stubbee.any_instance.mocha
|
15
|
+
end
|
16
|
+
|
17
|
+
def hide_original_method
|
18
|
+
if method_exists?(method)
|
19
|
+
begin
|
20
|
+
stubbee.class_eval("alias_method :#{hidden_method}, :#{method}", __FILE__, __LINE__)
|
21
|
+
rescue NameError
|
22
|
+
# deal with nasties like ActiveRecord::Associations::AssociationProxy
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def define_new_method
|
28
|
+
stubbee.class_eval("def #{method}(*args, &block); self.class.any_instance.mocha.method_missing(:#{method}, *args, &block); end", __FILE__, __LINE__)
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove_new_method
|
32
|
+
stubbee.class_eval("remove_method :#{method}", __FILE__, __LINE__)
|
33
|
+
end
|
34
|
+
|
35
|
+
def restore_original_method
|
36
|
+
if method_exists?(hidden_method)
|
37
|
+
begin
|
38
|
+
stubbee.class_eval("alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}", __FILE__, __LINE__)
|
39
|
+
rescue NameError
|
40
|
+
# deal with nasties like ActiveRecord::Associations::AssociationProxy
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def method_exists?(method)
|
46
|
+
return true if stubbee.public_instance_methods(false).include?(method)
|
47
|
+
return true if stubbee.protected_instance_methods(false).include?(method)
|
48
|
+
return true if stubbee.private_instance_methods(false).include?(method)
|
49
|
+
return false
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Mocha
|
2
|
+
|
3
|
+
class ArgumentIterator
|
4
|
+
|
5
|
+
def initialize(argument)
|
6
|
+
@argument = argument
|
7
|
+
end
|
8
|
+
|
9
|
+
def each(&block)
|
10
|
+
if @argument.is_a?(Hash) then
|
11
|
+
@argument.each do |method_name, return_value|
|
12
|
+
block.call(method_name, return_value)
|
13
|
+
end
|
14
|
+
else
|
15
|
+
block.call(@argument)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mocha
|
2
|
+
|
3
|
+
class BacktraceFilter
|
4
|
+
|
5
|
+
LIB_DIRECTORY = File.expand_path(File.join(File.dirname(__FILE__), "..")) + File::SEPARATOR
|
6
|
+
|
7
|
+
def initialize(lib_directory = LIB_DIRECTORY)
|
8
|
+
@lib_directory = lib_directory
|
9
|
+
end
|
10
|
+
|
11
|
+
def filtered(backtrace)
|
12
|
+
backtrace.reject { |location| Regexp.new(@lib_directory).match(File.expand_path(location)) }
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Mocha
|
2
|
+
|
3
|
+
class Cardinality
|
4
|
+
|
5
|
+
INFINITY = 1 / 0.0
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def exactly(count)
|
10
|
+
new(count, count)
|
11
|
+
end
|
12
|
+
|
13
|
+
def at_least(count)
|
14
|
+
new(count, INFINITY)
|
15
|
+
end
|
16
|
+
|
17
|
+
def at_most(count)
|
18
|
+
new(0, count)
|
19
|
+
end
|
20
|
+
|
21
|
+
def times(range_or_count)
|
22
|
+
case range_or_count
|
23
|
+
when Range then new(range_or_count.first, range_or_count.last)
|
24
|
+
else new(range_or_count, range_or_count)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(required, maximum)
|
31
|
+
@required, @maximum = required, maximum
|
32
|
+
end
|
33
|
+
|
34
|
+
def invocations_allowed?(invocation_count)
|
35
|
+
invocation_count < maximum
|
36
|
+
end
|
37
|
+
|
38
|
+
def satisfied?(invocations_so_far)
|
39
|
+
invocations_so_far >= required
|
40
|
+
end
|
41
|
+
|
42
|
+
def needs_verifying?
|
43
|
+
!allowed_any_number_of_times?
|
44
|
+
end
|
45
|
+
|
46
|
+
def verified?(invocation_count)
|
47
|
+
(invocation_count >= required) && (invocation_count <= maximum)
|
48
|
+
end
|
49
|
+
|
50
|
+
def allowed_any_number_of_times?
|
51
|
+
required == 0 && infinite?(maximum)
|
52
|
+
end
|
53
|
+
|
54
|
+
def used?(invocation_count)
|
55
|
+
(invocation_count > 0) || (maximum == 0)
|
56
|
+
end
|
57
|
+
|
58
|
+
def mocha_inspect
|
59
|
+
if allowed_any_number_of_times?
|
60
|
+
"allowed any number of times"
|
61
|
+
else
|
62
|
+
if required == 0 && maximum == 0
|
63
|
+
"expected never"
|
64
|
+
elsif required == maximum
|
65
|
+
"expected exactly #{times(required)}"
|
66
|
+
elsif infinite?(maximum)
|
67
|
+
"expected at least #{times(required)}"
|
68
|
+
elsif required == 0
|
69
|
+
"expected at most #{times(maximum)}"
|
70
|
+
else
|
71
|
+
"expected between #{required} and #{times(maximum)}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
protected
|
77
|
+
|
78
|
+
attr_reader :required, :maximum
|
79
|
+
|
80
|
+
def times(number)
|
81
|
+
case number
|
82
|
+
when 0 then "no times"
|
83
|
+
when 1 then "once"
|
84
|
+
when 2 then "twice"
|
85
|
+
else "#{number} times"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def infinite?(number)
|
90
|
+
number.respond_to?(:infinite?) && number.infinite?
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Mocha
|
2
|
+
|
3
|
+
class Central
|
4
|
+
|
5
|
+
attr_accessor :stubba_methods
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
self.stubba_methods = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def stub(method)
|
12
|
+
unless stubba_methods.include?(method)
|
13
|
+
method.stub
|
14
|
+
stubba_methods.push(method)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def unstub_all
|
19
|
+
while stubba_methods.length > 0
|
20
|
+
method = stubba_methods.pop
|
21
|
+
method.unstub
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'mocha/metaclass'
|
2
|
+
|
3
|
+
module Mocha
|
4
|
+
|
5
|
+
class ClassMethod
|
6
|
+
|
7
|
+
attr_reader :stubbee, :method
|
8
|
+
|
9
|
+
def initialize(stubbee, method)
|
10
|
+
@stubbee = stubbee
|
11
|
+
@method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym
|
12
|
+
end
|
13
|
+
|
14
|
+
def stub
|
15
|
+
hide_original_method
|
16
|
+
define_new_method
|
17
|
+
end
|
18
|
+
|
19
|
+
def unstub
|
20
|
+
remove_new_method
|
21
|
+
restore_original_method
|
22
|
+
stubbee.reset_mocha
|
23
|
+
end
|
24
|
+
|
25
|
+
def mock
|
26
|
+
stubbee.mocha
|
27
|
+
end
|
28
|
+
|
29
|
+
def hide_original_method
|
30
|
+
if method_exists?(method)
|
31
|
+
begin
|
32
|
+
stubbee.__metaclass__.class_eval("alias_method :#{hidden_method}, :#{method}", __FILE__, __LINE__)
|
33
|
+
rescue NameError
|
34
|
+
# deal with nasties like ActiveRecord::Associations::AssociationProxy
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def define_new_method
|
40
|
+
stubbee.__metaclass__.class_eval("def #{method}(*args, &block); mocha.method_missing(:#{method}, *args, &block); end", __FILE__, __LINE__)
|
41
|
+
end
|
42
|
+
|
43
|
+
def remove_new_method
|
44
|
+
stubbee.__metaclass__.class_eval("remove_method :#{method}", __FILE__, __LINE__)
|
45
|
+
end
|
46
|
+
|
47
|
+
def restore_original_method
|
48
|
+
if method_exists?(hidden_method)
|
49
|
+
begin
|
50
|
+
stubbee.__metaclass__.class_eval("alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}", __FILE__, __LINE__)
|
51
|
+
rescue NameError
|
52
|
+
# deal with nasties like ActiveRecord::Associations::AssociationProxy
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def hidden_method
|
58
|
+
if RUBY_VERSION < '1.9'
|
59
|
+
method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s[0]}_" }
|
60
|
+
else
|
61
|
+
method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s.ord}_" }
|
62
|
+
end
|
63
|
+
hidden_method = "__stubba__#{method_name}__stubba__"
|
64
|
+
RUBY_VERSION < '1.9' ? hidden_method.to_s : hidden_method.to_sym
|
65
|
+
end
|
66
|
+
|
67
|
+
def eql?(other)
|
68
|
+
return false unless (other.class == self.class)
|
69
|
+
(stubbee.object_id == other.stubbee.object_id) and (method == other.method)
|
70
|
+
end
|
71
|
+
|
72
|
+
alias_method :==, :eql?
|
73
|
+
|
74
|
+
def to_s
|
75
|
+
"#{stubbee}.#{method}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def method_exists?(method)
|
79
|
+
symbol = method.to_sym
|
80
|
+
metaclass = stubbee.__metaclass__
|
81
|
+
metaclass.public_method_defined?(symbol) || metaclass.protected_method_defined?(symbol) || metaclass.private_method_defined?(symbol)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Mocha # :nodoc:
|
2
|
+
|
3
|
+
# Configuration settings
|
4
|
+
class Configuration
|
5
|
+
|
6
|
+
DEFAULTS = { :stubbing_method_unnecessarily => :allow, :stubbing_method_on_non_mock_object => :allow, :stubbing_non_existent_method => :allow, :stubbing_non_public_method => :allow }
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# :call-seq: allow(action)
|
11
|
+
#
|
12
|
+
# Allow the specified <tt>action</tt> (as a symbol).
|
13
|
+
# The <tt>actions</tt> currently available are <tt>:stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method</tt>.
|
14
|
+
def allow(action)
|
15
|
+
configuration[action] = :allow
|
16
|
+
end
|
17
|
+
|
18
|
+
def allow?(action) # :nodoc:
|
19
|
+
configuration[action] == :allow
|
20
|
+
end
|
21
|
+
|
22
|
+
# :call-seq: warn_when(action)
|
23
|
+
#
|
24
|
+
# Warn if the specified <tt>action</tt> (as a symbol) is attempted.
|
25
|
+
# The <tt>actions</tt> currently available are <tt>:stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method</tt>.
|
26
|
+
def warn_when(action)
|
27
|
+
configuration[action] = :warn
|
28
|
+
end
|
29
|
+
|
30
|
+
def warn_when?(action) # :nodoc:
|
31
|
+
configuration[action] == :warn
|
32
|
+
end
|
33
|
+
|
34
|
+
# :call-seq: prevent(action)
|
35
|
+
#
|
36
|
+
# Raise a StubbingError if the specified <tt>action</tt> (as a symbol) is attempted.
|
37
|
+
# The <tt>actions</tt> currently available are <tt>:stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method</tt>.
|
38
|
+
def prevent(action)
|
39
|
+
configuration[action] = :prevent
|
40
|
+
end
|
41
|
+
|
42
|
+
def prevent?(action) # :nodoc:
|
43
|
+
configuration[action] == :prevent
|
44
|
+
end
|
45
|
+
|
46
|
+
def reset_configuration # :nodoc:
|
47
|
+
@configuration = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def configuration # :nodoc:
|
53
|
+
@configuration ||= DEFAULTS.dup
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Mocha
|
2
|
+
|
3
|
+
class Deprecation
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
attr_accessor :mode, :messages
|
8
|
+
|
9
|
+
def warning(message)
|
10
|
+
@messages << message
|
11
|
+
$stderr.puts "Mocha deprecation warning: #{message}" unless mode == :disabled
|
12
|
+
$stderr.puts caller.join("\n ") if mode == :debug
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
self.mode = :enabled
|
18
|
+
self.messages = []
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mocha # :nodoc:
|
2
|
+
|
3
|
+
class ExceptionRaiser # :nodoc:
|
4
|
+
|
5
|
+
def initialize(exception, message)
|
6
|
+
@exception, @message = exception, message
|
7
|
+
end
|
8
|
+
|
9
|
+
def evaluate
|
10
|
+
raise @exception, @exception.to_s if @exception.is_a?(Module) && @exception.ancestors.include?(Interrupt)
|
11
|
+
raise @exception, @message if @message
|
12
|
+
raise @exception
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|