dradis-mediawiki 3.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/issue_template.md +16 -0
- data/.github/pull_request_template.md +36 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +51 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +23 -0
- data/LICENSE +339 -0
- data/README.md +32 -0
- data/Rakefile +1 -0
- data/dradis-mediawiki.gemspec +31 -0
- data/lib/dradis-mediawiki.rb +2 -0
- data/lib/dradis/plugins/mediawiki.rb +10 -0
- data/lib/dradis/plugins/mediawiki/engine.rb +17 -0
- data/lib/dradis/plugins/mediawiki/filters.rb +68 -0
- data/lib/dradis/plugins/mediawiki/gem_version.rb +21 -0
- data/lib/dradis/plugins/mediawiki/version.rb +9 -0
- data/lib/tasks/thorfile.rb +17 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/wiki_import_spec.rb +18 -0
- data/test/vendor/mocha-0.9.5/COPYING +3 -0
- data/test/vendor/mocha-0.9.5/MIT-LICENSE +7 -0
- data/test/vendor/mocha-0.9.5/README +37 -0
- data/test/vendor/mocha-0.9.5/README.dradis +4 -0
- data/test/vendor/mocha-0.9.5/RELEASE +269 -0
- data/test/vendor/mocha-0.9.5/Rakefile +207 -0
- data/test/vendor/mocha-0.9.5/lib/mocha.rb +49 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/any_instance_method.rb +55 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/argument_iterator.rb +21 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/backtrace_filter.rb +17 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/cardinality.rb +95 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/central.rb +27 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/change_state_side_effect.rb +19 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/class_method.rb +87 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/configuration.rb +60 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/deprecation.rb +22 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/exception_raiser.rb +17 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/expectation.rb +476 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/expectation_error.rb +15 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/expectation_list.rb +50 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/in_state_ordering_constraint.rb +19 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/inspect.rb +67 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/instance_method.rb +16 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/is_a.rb +9 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/logger.rb +15 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/metaclass.rb +13 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/method_matcher.rb +21 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/mini_test_adapter.rb +50 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/mock.rb +200 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/mockery.rb +181 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/module_method.rb +16 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/multiple_yields.rb +20 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/names.rb +53 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/no_yields.rb +11 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/object.rb +187 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers.rb +27 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/all_of.rb +42 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/any_of.rb +47 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/any_parameters.rb +40 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/anything.rb +33 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/base.rb +15 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/equals.rb +42 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/has_entries.rb +45 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/has_entry.rb +56 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/has_key.rb +42 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/has_value.rb +42 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/includes.rb +40 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/instance_of.rb +42 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/is_a.rb +42 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/kind_of.rb +42 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/not.rb +42 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/object.rb +15 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/optionally.rb +55 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/regexp_matches.rb +43 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/responds_with.rb +43 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameter_matchers/yaml_equivalent.rb +43 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/parameters_matcher.rb +37 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/pretty_parameters.rb +28 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/return_values.rb +31 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/sequence.rb +42 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/single_return_value.rb +17 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/single_yield.rb +18 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/standalone.rb +166 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/state_machine.rb +91 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/stubbing_error.rb +16 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/test_case_adapter.rb +103 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/unexpected_invocation.rb +18 -0
- data/test/vendor/mocha-0.9.5/lib/mocha/yield_parameters.rb +31 -0
- data/test/vendor/mocha-0.9.5/lib/mocha_standalone.rb +2 -0
- data/test/vendor/mocha-0.9.5/lib/stubba.rb +4 -0
- data/test/wiki_import_test.rb +106 -0
- metadata +249 -0
@@ -0,0 +1,181 @@
|
|
1
|
+
require 'mocha/central'
|
2
|
+
require 'mocha/mock'
|
3
|
+
require 'mocha/names'
|
4
|
+
require 'mocha/state_machine'
|
5
|
+
require 'mocha/logger'
|
6
|
+
require 'mocha/configuration'
|
7
|
+
require 'mocha/stubbing_error'
|
8
|
+
|
9
|
+
module Mocha
|
10
|
+
|
11
|
+
class Mockery
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def instance
|
16
|
+
@instance ||= new
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset_instance
|
20
|
+
@instance = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def named_mock(name, &block)
|
26
|
+
add_mock(Mock.new(Name.new(name), &block))
|
27
|
+
end
|
28
|
+
|
29
|
+
def unnamed_mock(&block)
|
30
|
+
add_mock(Mock.new(&block))
|
31
|
+
end
|
32
|
+
|
33
|
+
def mock_impersonating(object, &block)
|
34
|
+
add_mock(Mock.new(ImpersonatingName.new(object), &block))
|
35
|
+
end
|
36
|
+
|
37
|
+
def mock_impersonating_any_instance_of(klass, &block)
|
38
|
+
add_mock(Mock.new(ImpersonatingAnyInstanceName.new(klass), &block))
|
39
|
+
end
|
40
|
+
|
41
|
+
def new_state_machine(name)
|
42
|
+
add_state_machine(StateMachine.new(name))
|
43
|
+
end
|
44
|
+
|
45
|
+
def verify(assertion_counter = nil)
|
46
|
+
unless mocks.all? { |mock| mock.__verified__?(assertion_counter) }
|
47
|
+
message = "not all expectations were satisfied\n#{mocha_inspect}"
|
48
|
+
if unsatisfied_expectations.empty?
|
49
|
+
backtrace = caller
|
50
|
+
else
|
51
|
+
backtrace = unsatisfied_expectations[0].backtrace
|
52
|
+
end
|
53
|
+
raise ExpectationError.new(message, backtrace)
|
54
|
+
end
|
55
|
+
expectations.each do |e|
|
56
|
+
unless Mocha::Configuration.allow?(:stubbing_method_unnecessarily)
|
57
|
+
unless e.used?
|
58
|
+
on_stubbing_method_unnecessarily(e)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def teardown
|
65
|
+
stubba.unstub_all
|
66
|
+
reset
|
67
|
+
end
|
68
|
+
|
69
|
+
def stubba
|
70
|
+
@stubba ||= Central.new
|
71
|
+
end
|
72
|
+
|
73
|
+
def mocks
|
74
|
+
@mocks ||= []
|
75
|
+
end
|
76
|
+
|
77
|
+
def state_machines
|
78
|
+
@state_machines ||= []
|
79
|
+
end
|
80
|
+
|
81
|
+
def mocha_inspect
|
82
|
+
message = ""
|
83
|
+
message << "unsatisfied expectations:\n- #{unsatisfied_expectations.map { |e| e.mocha_inspect }.join("\n- ")}\n" unless unsatisfied_expectations.empty?
|
84
|
+
message << "satisfied expectations:\n- #{satisfied_expectations.map { |e| e.mocha_inspect }.join("\n- ")}\n" unless satisfied_expectations.empty?
|
85
|
+
message << "states:\n- #{state_machines.map { |sm| sm.mocha_inspect }.join("\n- ")}" unless state_machines.empty?
|
86
|
+
message
|
87
|
+
end
|
88
|
+
|
89
|
+
def on_stubbing(object, method)
|
90
|
+
method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym
|
91
|
+
unless Mocha::Configuration.allow?(:stubbing_non_existent_method)
|
92
|
+
unless object.method_exists?(method, include_public_methods = true)
|
93
|
+
on_stubbing_non_existent_method(object, method)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
unless Mocha::Configuration.allow?(:stubbing_non_public_method)
|
97
|
+
if object.method_exists?(method, include_public_methods = false)
|
98
|
+
on_stubbing_non_public_method(object, method)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
unless Mocha::Configuration.allow?(:stubbing_method_on_non_mock_object)
|
102
|
+
on_stubbing_method_on_non_mock_object(object, method)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def on_stubbing_non_existent_method(object, method)
|
107
|
+
if Mocha::Configuration.prevent?(:stubbing_non_existent_method)
|
108
|
+
raise StubbingError.new("stubbing non-existent method: #{object.mocha_inspect}.#{method}", caller)
|
109
|
+
end
|
110
|
+
if Mocha::Configuration.warn_when?(:stubbing_non_existent_method)
|
111
|
+
logger.warn "stubbing non-existent method: #{object.mocha_inspect}.#{method}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def on_stubbing_non_public_method(object, method)
|
116
|
+
if Mocha::Configuration.prevent?(:stubbing_non_public_method)
|
117
|
+
raise StubbingError.new("stubbing non-public method: #{object.mocha_inspect}.#{method}", caller)
|
118
|
+
end
|
119
|
+
if Mocha::Configuration.warn_when?(:stubbing_non_public_method)
|
120
|
+
logger.warn "stubbing non-public method: #{object.mocha_inspect}.#{method}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def on_stubbing_method_on_non_mock_object(object, method)
|
125
|
+
if Mocha::Configuration.prevent?(:stubbing_method_on_non_mock_object)
|
126
|
+
raise StubbingError.new("stubbing method on non-mock object: #{object.mocha_inspect}.#{method}", caller)
|
127
|
+
end
|
128
|
+
if Mocha::Configuration.warn_when?(:stubbing_method_on_non_mock_object)
|
129
|
+
logger.warn "stubbing method on non-mock object: #{object.mocha_inspect}.#{method}"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def on_stubbing_method_unnecessarily(expectation)
|
134
|
+
if Mocha::Configuration.prevent?(:stubbing_method_unnecessarily)
|
135
|
+
raise StubbingError.new("stubbing method unnecessarily: #{expectation.method_signature}", expectation.backtrace)
|
136
|
+
end
|
137
|
+
if Mocha::Configuration.warn_when?(:stubbing_method_unnecessarily)
|
138
|
+
logger.warn "stubbing method unnecessarily: #{expectation.method_signature}"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
attr_writer :logger
|
143
|
+
|
144
|
+
def logger
|
145
|
+
@logger ||= Logger.new($stderr)
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
private
|
150
|
+
|
151
|
+
def expectations
|
152
|
+
mocks.map { |mock| mock.expectations.to_a }.flatten
|
153
|
+
end
|
154
|
+
|
155
|
+
def unsatisfied_expectations
|
156
|
+
expectations.reject { |e| e.verified? }
|
157
|
+
end
|
158
|
+
|
159
|
+
def satisfied_expectations
|
160
|
+
expectations.select { |e| e.verified? }
|
161
|
+
end
|
162
|
+
|
163
|
+
def add_mock(mock)
|
164
|
+
mocks << mock
|
165
|
+
mock
|
166
|
+
end
|
167
|
+
|
168
|
+
def add_state_machine(state_machine)
|
169
|
+
state_machines << state_machine
|
170
|
+
state_machine
|
171
|
+
end
|
172
|
+
|
173
|
+
def reset
|
174
|
+
@stubba = nil
|
175
|
+
@mocks = nil
|
176
|
+
@state_machines = nil
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'mocha/module_method'
|
2
|
+
|
3
|
+
module Mocha
|
4
|
+
|
5
|
+
class ModuleMethod < ClassMethod
|
6
|
+
|
7
|
+
def method_exists?(method)
|
8
|
+
return true if stubbee.public_methods(false).include?(method)
|
9
|
+
return true if stubbee.protected_methods(false).include?(method)
|
10
|
+
return true if stubbee.private_methods(false).include?(method)
|
11
|
+
return false
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Mocha # :nodoc:
|
2
|
+
|
3
|
+
class MultipleYields # :nodoc:
|
4
|
+
|
5
|
+
attr_reader :parameter_groups
|
6
|
+
|
7
|
+
def initialize(*parameter_groups)
|
8
|
+
@parameter_groups = parameter_groups
|
9
|
+
end
|
10
|
+
|
11
|
+
def each
|
12
|
+
@parameter_groups.each do |parameter_group|
|
13
|
+
yield(parameter_group)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Mocha
|
2
|
+
|
3
|
+
class ImpersonatingName
|
4
|
+
|
5
|
+
def initialize(object)
|
6
|
+
@object = object
|
7
|
+
end
|
8
|
+
|
9
|
+
def mocha_inspect
|
10
|
+
@object.mocha_inspect
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
class ImpersonatingAnyInstanceName
|
16
|
+
|
17
|
+
def initialize(klass)
|
18
|
+
@klass = klass
|
19
|
+
end
|
20
|
+
|
21
|
+
def mocha_inspect
|
22
|
+
"#<AnyInstance:#{@klass.mocha_inspect}>"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
class Name
|
28
|
+
|
29
|
+
def initialize(name)
|
30
|
+
@name = name
|
31
|
+
end
|
32
|
+
|
33
|
+
def mocha_inspect
|
34
|
+
"#<Mock:#{@name}>"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
class DefaultName
|
40
|
+
|
41
|
+
def initialize(mock)
|
42
|
+
@mock = mock
|
43
|
+
end
|
44
|
+
|
45
|
+
def mocha_inspect
|
46
|
+
address = @mock.__id__ * 2
|
47
|
+
address += 0x100000000 if address < 0
|
48
|
+
"#<Mock:0x#{'%x' % address}>"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require 'mocha/mockery'
|
2
|
+
require 'mocha/instance_method'
|
3
|
+
require 'mocha/class_method'
|
4
|
+
require 'mocha/module_method'
|
5
|
+
require 'mocha/any_instance_method'
|
6
|
+
require 'mocha/argument_iterator'
|
7
|
+
|
8
|
+
module Mocha
|
9
|
+
|
10
|
+
# Methods added all objects to allow mocking and stubbing on real objects.
|
11
|
+
#
|
12
|
+
# Methods return a Mocha::Expectation which can be further modified by methods on Mocha::Expectation.
|
13
|
+
module ObjectMethods
|
14
|
+
|
15
|
+
def mocha # :nodoc:
|
16
|
+
@mocha ||= Mocha::Mockery.instance.mock_impersonating(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset_mocha # :nodoc:
|
20
|
+
@mocha = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def stubba_method # :nodoc:
|
24
|
+
Mocha::InstanceMethod
|
25
|
+
end
|
26
|
+
|
27
|
+
def stubba_object # :nodoc:
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
# :call-seq: expects(method_name) -> expectation
|
32
|
+
# expects(method_names_vs_return_values) -> last expectation
|
33
|
+
#
|
34
|
+
# Adds an expectation that a method identified by +method_name+ Symbol must be called exactly once with any parameters.
|
35
|
+
# Returns the new expectation which can be further modified by methods on Mocha::Expectation.
|
36
|
+
# product = Product.new
|
37
|
+
# product.expects(:save).returns(true)
|
38
|
+
# assert_equal true, product.save
|
39
|
+
#
|
40
|
+
# The original implementation of <tt>Product#save</tt> is replaced temporarily.
|
41
|
+
#
|
42
|
+
# The original implementation of <tt>Product#save</tt> is restored at the end of the test.
|
43
|
+
#
|
44
|
+
# If +method_names_vs_return_values+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+.
|
45
|
+
# product = Product.new
|
46
|
+
# product.expects(:valid? => true, :save => true)
|
47
|
+
#
|
48
|
+
# # exactly equivalent to
|
49
|
+
#
|
50
|
+
# product = Product.new
|
51
|
+
# product.expects(:valid?).returns(true)
|
52
|
+
# product.expects(:save).returns(true)
|
53
|
+
def expects(method_name_or_hash)
|
54
|
+
expectation = nil
|
55
|
+
mockery = Mocha::Mockery.instance
|
56
|
+
iterator = ArgumentIterator.new(method_name_or_hash)
|
57
|
+
iterator.each { |*args|
|
58
|
+
method_name = args.shift
|
59
|
+
mockery.on_stubbing(self, method_name)
|
60
|
+
method = stubba_method.new(stubba_object, method_name)
|
61
|
+
mockery.stubba.stub(method)
|
62
|
+
expectation = mocha.expects(method_name, caller)
|
63
|
+
expectation.returns(args.shift) if args.length > 0
|
64
|
+
}
|
65
|
+
expectation
|
66
|
+
end
|
67
|
+
|
68
|
+
# :call-seq: stubs(method_name) -> expectation
|
69
|
+
# stubs(method_names_vs_return_values) -> last expectation
|
70
|
+
#
|
71
|
+
# Adds an expectation that a method identified by +method_name+ Symbol may be called any number of times with any parameters.
|
72
|
+
# Returns the new expectation which can be further modified by methods on Mocha::Expectation.
|
73
|
+
# product = Product.new
|
74
|
+
# product.stubs(:save).returns(true)
|
75
|
+
# assert_equal true, product.save
|
76
|
+
#
|
77
|
+
# The original implementation of <tt>Product#save</tt> is replaced temporarily.
|
78
|
+
#
|
79
|
+
# The original implementation of <tt>Product#save</tt> is restored at the end of the test.
|
80
|
+
#
|
81
|
+
# If +method_names_vs_return_values+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+.
|
82
|
+
# product = Product.new
|
83
|
+
# product.stubs(:valid? => true, :save => true)
|
84
|
+
#
|
85
|
+
# # exactly equivalent to
|
86
|
+
#
|
87
|
+
# product = Product.new
|
88
|
+
# product.stubs(:valid?).returns(true)
|
89
|
+
# product.stubs(:save).returns(true)
|
90
|
+
def stubs(method_name_or_hash)
|
91
|
+
expectation = nil
|
92
|
+
mockery = Mocha::Mockery.instance
|
93
|
+
iterator = ArgumentIterator.new(method_name_or_hash)
|
94
|
+
iterator.each { |*args|
|
95
|
+
method_name = args.shift
|
96
|
+
mockery.on_stubbing(self, method_name)
|
97
|
+
method = stubba_method.new(stubba_object, method_name)
|
98
|
+
mockery.stubba.stub(method)
|
99
|
+
expectation = mocha.stubs(method_name, caller)
|
100
|
+
expectation.returns(args.shift) if args.length > 0
|
101
|
+
}
|
102
|
+
expectation
|
103
|
+
end
|
104
|
+
|
105
|
+
def method_exists?(method, include_public_methods = true) # :nodoc:
|
106
|
+
if include_public_methods
|
107
|
+
return true if public_methods(include_superclass_methods = true).include?(method)
|
108
|
+
return true if respond_to?(method.to_sym)
|
109
|
+
end
|
110
|
+
return true if protected_methods(include_superclass_methods = true).include?(method)
|
111
|
+
return true if private_methods(include_superclass_methods = true).include?(method)
|
112
|
+
return false
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
module ModuleMethods # :nodoc:
|
118
|
+
|
119
|
+
def stubba_method
|
120
|
+
Mocha::ModuleMethod
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
# Methods added all classes to allow mocking and stubbing on real objects.
|
126
|
+
module ClassMethods
|
127
|
+
|
128
|
+
def stubba_method # :nodoc:
|
129
|
+
Mocha::ClassMethod
|
130
|
+
end
|
131
|
+
|
132
|
+
class AnyInstance # :nodoc:
|
133
|
+
|
134
|
+
def initialize(klass)
|
135
|
+
@stubba_object = klass
|
136
|
+
end
|
137
|
+
|
138
|
+
def mocha
|
139
|
+
@mocha ||= Mocha::Mockery.instance.mock_impersonating_any_instance_of(@stubba_object)
|
140
|
+
end
|
141
|
+
|
142
|
+
def stubba_method
|
143
|
+
Mocha::AnyInstanceMethod
|
144
|
+
end
|
145
|
+
|
146
|
+
def stubba_object
|
147
|
+
@stubba_object
|
148
|
+
end
|
149
|
+
|
150
|
+
def method_exists?(method, include_public_methods = true)
|
151
|
+
if include_public_methods
|
152
|
+
return true if @stubba_object.public_instance_methods(include_superclass_methods = true).include?(method)
|
153
|
+
end
|
154
|
+
return true if @stubba_object.protected_instance_methods(include_superclass_methods = true).include?(method)
|
155
|
+
return true if @stubba_object.private_instance_methods(include_superclass_methods = true).include?(method)
|
156
|
+
return false
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
# :call-seq: any_instance -> mock object
|
162
|
+
#
|
163
|
+
# Returns a mock object which will detect calls to any instance of this class.
|
164
|
+
# Product.any_instance.stubs(:save).returns(false)
|
165
|
+
# product_1 = Product.new
|
166
|
+
# assert_equal false, product_1.save
|
167
|
+
# product_2 = Product.new
|
168
|
+
# assert_equal false, product_2.save
|
169
|
+
def any_instance
|
170
|
+
@any_instance ||= AnyInstance.new(self)
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
class Object # :nodoc:
|
178
|
+
include Mocha::ObjectMethods
|
179
|
+
end
|
180
|
+
|
181
|
+
class Module # :nodoc:
|
182
|
+
include Mocha::ModuleMethods
|
183
|
+
end
|
184
|
+
|
185
|
+
class Class # :nodoc:
|
186
|
+
include Mocha::ClassMethods
|
187
|
+
end
|