puppet 0.24.1 → 0.24.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- data/CHANGELOG +94 -0
- data/Rakefile +0 -4
- data/bin/puppet +18 -10
- data/bin/puppetd +1 -1
- data/bin/puppetdoc +14 -4
- data/bin/puppetmasterd +1 -1
- data/bin/puppetrun +3 -8
- data/bin/ralsh +12 -11
- data/conf/freebsd/puppetd +1 -1
- data/conf/freebsd/puppetmasterd +1 -1
- data/conf/gentoo/puppet/puppet.conf +29 -0
- data/conf/namespaceauth.conf +20 -0
- data/conf/redhat/puppet.spec +4 -1
- data/conf/solaris/smf/puppetd.xml +1 -1
- data/conf/solaris/smf/puppetmasterd.xml +1 -1
- data/conf/suse/puppet.spec +10 -8
- data/examples/root/etc/puppet/{puppetmasterd.conf → puppet.conf} +6 -3
- data/ext/logcheck/puppet +7 -0
- data/ext/puppet-test +28 -5
- data/lib/puppet.rb +2 -1
- data/lib/puppet/defaults.rb +12 -5
- data/lib/puppet/dsl.rb +43 -45
- data/lib/puppet/external/{gratr/rdot.rb → dot.rb} +0 -0
- data/lib/puppet/external/nagios.rb +50 -0
- data/lib/puppet/external/nagios/base.rb +421 -0
- data/lib/puppet/external/nagios/parser.rb +816 -0
- data/lib/puppet/file_serving/file_base.rb +16 -3
- data/lib/puppet/file_serving/metadata.rb +29 -11
- data/lib/puppet/indirector/terminus.rb +1 -0
- data/lib/puppet/metatype/closure.rb +4 -0
- data/lib/puppet/metatype/evaluation.rb +2 -17
- data/lib/puppet/metatype/metaparams.rb +1 -1
- data/lib/puppet/network.rb +3 -0
- data/lib/puppet/network/client.rb +4 -5
- data/lib/puppet/network/client/master.rb +10 -7
- data/lib/puppet/network/handler/fileserver.rb +22 -45
- data/lib/puppet/network/http_pool.rb +3 -0
- data/lib/puppet/network/http_server/mongrel.rb +7 -1
- data/lib/puppet/network/http_server/webrick.rb +4 -3
- data/lib/puppet/network/xmlrpc/client.rb +12 -1
- data/lib/puppet/node/catalog.rb +51 -40
- data/lib/puppet/parser/ast.rb +27 -49
- data/lib/puppet/parser/ast/astarray.rb +5 -24
- data/lib/puppet/parser/ast/caseopt.rb +4 -4
- data/lib/puppet/parser/ast/casestatement.rb +4 -5
- data/lib/puppet/parser/ast/collection.rb +3 -5
- data/lib/puppet/parser/ast/collexpr.rb +3 -5
- data/lib/puppet/parser/ast/definition.rb +148 -159
- data/lib/puppet/parser/ast/else.rb +2 -3
- data/lib/puppet/parser/ast/function.rb +3 -10
- data/lib/puppet/parser/ast/hostclass.rb +66 -59
- data/lib/puppet/parser/ast/ifstatement.rb +4 -5
- data/lib/puppet/parser/ast/leaf.rb +6 -6
- data/lib/puppet/parser/ast/node.rb +26 -58
- data/lib/puppet/parser/ast/resource.rb +5 -7
- data/lib/puppet/parser/ast/resource_defaults.rb +2 -4
- data/lib/puppet/parser/ast/resource_override.rb +4 -6
- data/lib/puppet/parser/ast/resource_reference.rb +2 -4
- data/lib/puppet/parser/ast/resourceparam.rb +2 -4
- data/lib/puppet/parser/ast/selector.rb +5 -6
- data/lib/puppet/parser/ast/tag.rb +2 -4
- data/lib/puppet/parser/ast/vardef.rb +3 -4
- data/lib/puppet/parser/collector.rb +5 -5
- data/lib/puppet/parser/{compile.rb → compiler.rb} +69 -107
- data/lib/puppet/parser/functions.rb +3 -3
- data/lib/puppet/parser/interpreter.rb +32 -23
- data/lib/puppet/parser/lexer.rb +391 -282
- data/lib/puppet/parser/parser.rb +5 -4
- data/lib/puppet/parser/parser_support.rb +3 -6
- data/lib/puppet/parser/resource.rb +24 -36
- data/lib/puppet/parser/resource/param.rb +1 -1
- data/lib/puppet/parser/resource/reference.rb +7 -3
- data/lib/puppet/parser/scope.rb +12 -7
- data/lib/puppet/parser/templatewrapper.rb +1 -1
- data/lib/puppet/pgraph.rb +9 -98
- data/lib/puppet/provider/interface/redhat.rb +65 -65
- data/lib/puppet/provider/mount/parsed.rb +1 -1
- data/lib/puppet/provider/naginator.rb +55 -0
- data/lib/puppet/provider/nameservice/directoryservice.rb +6 -7
- data/lib/puppet/provider/package/fink.rb +0 -2
- data/lib/puppet/provider/package/gem.rb +9 -5
- data/lib/puppet/provider/package/openbsd.rb +1 -1
- data/lib/puppet/provider/package/pkgdmg.rb +3 -8
- data/lib/puppet/provider/package/portage.rb +4 -4
- data/lib/puppet/provider/package/yumhelper.py +8 -6
- data/lib/puppet/provider/parsedfile.rb +7 -1
- data/lib/puppet/provider/service/debian.rb +2 -0
- data/lib/puppet/provider/service/gentoo.rb +4 -0
- data/lib/puppet/provider/service/init.rb +1 -1
- data/lib/puppet/provider/sshkey/parsed.rb +2 -0
- data/lib/puppet/provider/user/useradd.rb +1 -1
- data/lib/puppet/rails.rb +4 -0
- data/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb +17 -0
- data/lib/puppet/rails/fact_value.rb +4 -0
- data/lib/puppet/rails/host.rb +1 -2
- data/lib/puppet/rails/param_value.rb +4 -0
- data/lib/puppet/rails/resource_tag.rb +4 -0
- data/lib/puppet/rails/source_file.rb +4 -1
- data/lib/puppet/relationship.rb +5 -1
- data/lib/puppet/reports/tagmail.rb +12 -1
- data/lib/puppet/resource_reference.rb +1 -1
- data/lib/puppet/simple_graph.rb +78 -11
- data/lib/puppet/sslcertificates.rb +1 -1
- data/lib/puppet/sslcertificates/ca.rb +3 -3
- data/lib/puppet/transaction.rb +7 -4
- data/lib/puppet/transportable.rb +1 -1
- data/lib/puppet/type.rb +3 -10
- data/lib/puppet/type/cron.rb +18 -0
- data/lib/puppet/type/exec.rb +18 -12
- data/lib/puppet/type/{pfile.rb → file.rb} +66 -84
- data/lib/puppet/type/file/checksum.rb +271 -0
- data/lib/puppet/type/{pfile → file}/content.rb +10 -15
- data/lib/puppet/type/{pfile → file}/ensure.rb +15 -8
- data/lib/puppet/type/{pfile → file}/group.rb +0 -0
- data/lib/puppet/type/{pfile → file}/mode.rb +0 -0
- data/lib/puppet/type/{pfile → file}/owner.rb +0 -0
- data/lib/puppet/type/{pfile → file}/source.rb +34 -48
- data/lib/puppet/type/{pfile → file}/target.rb +0 -0
- data/lib/puppet/type/{pfile → file}/type.rb +0 -0
- data/lib/puppet/type/{pfilebucket.rb → filebucket.rb} +0 -0
- data/lib/puppet/type/host.rb +13 -0
- data/lib/puppet/type/mailalias.rb +1 -1
- data/lib/puppet/type/nagios_command.rb +3 -0
- data/lib/puppet/type/nagios_contact.rb +3 -0
- data/lib/puppet/type/nagios_contactgroup.rb +3 -0
- data/lib/puppet/type/nagios_host.rb +3 -0
- data/lib/puppet/type/nagios_hostextinfo.rb +3 -0
- data/lib/puppet/type/nagios_hostgroup.rb +3 -0
- data/lib/puppet/type/nagios_hostgroupescalation.rb +3 -0
- data/lib/puppet/type/nagios_service.rb +3 -0
- data/lib/puppet/type/nagios_servicedependency.rb +3 -0
- data/lib/puppet/type/nagios_serviceescalation.rb +3 -0
- data/lib/puppet/type/nagios_serviceextinfo.rb +3 -0
- data/lib/puppet/type/nagios_timeperiod.rb +3 -0
- data/lib/puppet/type/package.rb +4 -12
- data/lib/puppet/type/service.rb +9 -0
- data/lib/puppet/type/sshkey.rb +3 -3
- data/lib/puppet/util/autoload.rb +5 -5
- data/lib/puppet/util/checksums.rb +51 -13
- data/lib/puppet/util/constant_inflector.rb +14 -0
- data/lib/puppet/util/filetype.rb +1 -1
- data/lib/puppet/util/graph.rb +3 -9
- data/lib/puppet/util/nagios_maker.rb +57 -0
- data/lib/puppet/util/settings.rb +19 -16
- data/lib/puppet/util/tagging.rb +39 -0
- data/test/executables/puppetbin.rb +17 -0
- data/test/language/ast.rb +8 -58
- data/test/language/ast/casestatement.rb +3 -3
- data/test/language/ast/resource.rb +6 -7
- data/test/language/ast/resource_reference.rb +12 -12
- data/test/language/ast/selector.rb +2 -2
- data/test/language/ast/variable.rb +2 -2
- data/test/language/functions.rb +24 -24
- data/test/language/parser.rb +20 -8
- data/test/language/resource.rb +5 -42
- data/test/language/scope.rb +21 -37
- data/test/language/snippets.rb +7 -0
- data/test/lib/puppettest.rb +28 -14
- data/test/lib/puppettest/parsertesting.rb +10 -10
- data/test/lib/puppettest/support/resources.rb +1 -1
- data/test/network/client/master.rb +10 -0
- data/test/network/handler/fileserver.rb +51 -49
- data/test/network/server/webrick.rb +1 -1
- data/test/other/dsl.rb +3 -4
- data/test/other/transactions.rb +6 -4
- data/test/rails/ast.rb +2 -2
- data/test/rails/configuration.rb +1 -1
- data/test/rails/railsparameter.rb +2 -0
- data/test/rails/railsresource.rb +1 -0
- data/test/ral/manager/type.rb +4 -4
- data/test/ral/providers/cron/crontab.rb +3 -1
- data/test/ral/providers/package.rb +1 -1
- data/test/ral/{types → type}/basic.rb +2 -2
- data/test/ral/{types → type}/cron.rb +0 -0
- data/test/ral/{types → type}/exec.rb +42 -2
- data/test/ral/{types → type}/file.rb +34 -79
- data/test/ral/{types → type}/file/target.rb +0 -0
- data/test/ral/{types → type}/filebucket.rb +0 -0
- data/test/ral/{types → type}/fileignoresource.rb +0 -0
- data/test/ral/{types → type}/filesources.rb +8 -27
- data/test/ral/{types → type}/group.rb +0 -0
- data/test/ral/{types → type}/host.rb +16 -0
- data/test/ral/{types → type}/mailalias.rb +0 -0
- data/test/ral/{types → type}/parameter.rb +0 -0
- data/test/ral/{types → type}/port.rb +0 -0
- data/test/ral/{types → type}/property.rb +0 -0
- data/test/ral/{types → type}/resources.rb +0 -0
- data/test/ral/{types → type}/service.rb +0 -0
- data/test/ral/{types → type}/sshkey.rb +0 -0
- data/test/ral/{types → type}/tidy.rb +1 -0
- data/test/ral/{types → type}/user.rb +0 -0
- data/test/ral/{types → type}/yumrepo.rb +0 -0
- data/test/ral/{types → type}/zone.rb +0 -0
- data/test/util/autoload.rb +24 -5
- metadata +60 -107
- data/conf/gentoo/puppet/puppetca.conf +0 -29
- data/conf/gentoo/puppet/puppetd.conf +0 -29
- data/conf/gentoo/puppet/puppetmasterd.conf +0 -29
- data/examples/root/etc/puppet/puppetd.conf +0 -4
- data/lib/puppet/external/gratr.rb +0 -33
- data/lib/puppet/external/gratr/adjacency_graph.rb +0 -257
- data/lib/puppet/external/gratr/base.rb +0 -34
- data/lib/puppet/external/gratr/biconnected.rb +0 -116
- data/lib/puppet/external/gratr/chinese_postman.rb +0 -123
- data/lib/puppet/external/gratr/common.rb +0 -73
- data/lib/puppet/external/gratr/comparability.rb +0 -92
- data/lib/puppet/external/gratr/digraph.rb +0 -116
- data/lib/puppet/external/gratr/digraph_distance.rb +0 -185
- data/lib/puppet/external/gratr/dot.rb +0 -90
- data/lib/puppet/external/gratr/edge.rb +0 -145
- data/lib/puppet/external/gratr/graph.rb +0 -303
- data/lib/puppet/external/gratr/graph_api.rb +0 -83
- data/lib/puppet/external/gratr/import.rb +0 -44
- data/lib/puppet/external/gratr/labels.rb +0 -90
- data/lib/puppet/external/gratr/maximum_flow.rb +0 -64
- data/lib/puppet/external/gratr/search.rb +0 -409
- data/lib/puppet/external/gratr/strong_components.rb +0 -127
- data/lib/puppet/external/gratr/undirected_graph.rb +0 -153
- data/lib/puppet/rails/external/tagging/acts_as_taggable.rb +0 -62
- data/lib/puppet/rails/external/tagging/init.rb +0 -5
- data/lib/puppet/rails/external/tagging/tag.rb +0 -50
- data/lib/puppet/rails/external/tagging/tagging.rb +0 -12
- data/lib/puppet/rails/puppet_class.rb +0 -6
- data/lib/puppet/reference/node_source.rb +0 -9
- data/lib/puppet/reference/report.rb +0 -21
- data/lib/puppet/type/pfile/checksum.rb +0 -326
- data/test/language/ast/definition.rb +0 -166
- data/test/language/ast/hostclass.rb +0 -184
- data/test/language/compile.rb +0 -569
- data/test/language/lexer.rb +0 -276
- data/test/lib/mocha.rb +0 -19
- data/test/lib/mocha/any_instance_method.rb +0 -35
- data/test/lib/mocha/auto_verify.rb +0 -113
- data/test/lib/mocha/central.rb +0 -35
- data/test/lib/mocha/class_method.rb +0 -62
- data/test/lib/mocha/deprecation.rb +0 -22
- data/test/lib/mocha/exception_raiser.rb +0 -17
- data/test/lib/mocha/expectation.rb +0 -378
- data/test/lib/mocha/expectation_error.rb +0 -6
- data/test/lib/mocha/infinite_range.rb +0 -25
- data/test/lib/mocha/inspect.rb +0 -39
- data/test/lib/mocha/instance_method.rb +0 -8
- data/test/lib/mocha/is_a.rb +0 -9
- data/test/lib/mocha/metaclass.rb +0 -7
- data/test/lib/mocha/missing_expectation.rb +0 -27
- data/test/lib/mocha/mock.rb +0 -207
- data/test/lib/mocha/multiple_yields.rb +0 -20
- data/test/lib/mocha/no_yields.rb +0 -11
- data/test/lib/mocha/object.rb +0 -110
- data/test/lib/mocha/parameter_matchers.rb +0 -9
- data/test/lib/mocha/parameter_matchers/all_of.rb +0 -39
- data/test/lib/mocha/parameter_matchers/any_of.rb +0 -44
- data/test/lib/mocha/parameter_matchers/anything.rb +0 -30
- data/test/lib/mocha/parameter_matchers/has_entry.rb +0 -39
- data/test/lib/mocha/parameter_matchers/has_key.rb +0 -39
- data/test/lib/mocha/parameter_matchers/has_value.rb +0 -39
- data/test/lib/mocha/parameter_matchers/includes.rb +0 -37
- data/test/lib/mocha/pretty_parameters.rb +0 -28
- data/test/lib/mocha/return_values.rb +0 -31
- data/test/lib/mocha/setup_and_teardown.rb +0 -23
- data/test/lib/mocha/single_return_value.rb +0 -24
- data/test/lib/mocha/single_yield.rb +0 -18
- data/test/lib/mocha/standalone.rb +0 -32
- data/test/lib/mocha/stub.rb +0 -18
- data/test/lib/mocha/test_case_adapter.rb +0 -49
- data/test/lib/mocha/yield_parameters.rb +0 -31
@@ -1,25 +0,0 @@
|
|
1
|
-
class Range
|
2
|
-
|
3
|
-
def self.at_least(minimum_value)
|
4
|
-
Range.new(minimum_value, infinite)
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.at_most(maximum_value)
|
8
|
-
Range.new(-infinite, maximum_value, false)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.infinite
|
12
|
-
1/0.0
|
13
|
-
end
|
14
|
-
|
15
|
-
def mocha_inspect
|
16
|
-
if first.respond_to?(:to_f) and first.to_f.infinite? then
|
17
|
-
return "at most #{last}"
|
18
|
-
elsif last.respond_to?(:to_f) and last.to_f.infinite? then
|
19
|
-
return "at least #{first}"
|
20
|
-
else
|
21
|
-
to_s
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
data/test/lib/mocha/inspect.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'date'
|
2
|
-
|
3
|
-
class Object
|
4
|
-
def mocha_inspect
|
5
|
-
address = self.__id__ * 2
|
6
|
-
address += 0x100000000 if address < 0
|
7
|
-
inspect =~ /#</ ? "#<#{self.class}:0x#{'%x' % address}>" : inspect
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class String
|
12
|
-
def mocha_inspect
|
13
|
-
inspect.gsub(/\"/, "'")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Array
|
18
|
-
def mocha_inspect
|
19
|
-
"[#{collect { |member| member.mocha_inspect }.join(', ')}]"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class Hash
|
24
|
-
def mocha_inspect
|
25
|
-
"{#{collect { |key, value| "#{key.mocha_inspect} => #{value.mocha_inspect}" }.join(', ')}}"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class Time
|
30
|
-
def mocha_inspect
|
31
|
-
"#{inspect} (#{to_f} secs)"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class Date
|
36
|
-
def mocha_inspect
|
37
|
-
to_s
|
38
|
-
end
|
39
|
-
end
|
data/test/lib/mocha/is_a.rb
DELETED
data/test/lib/mocha/metaclass.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'mocha/expectation'
|
2
|
-
|
3
|
-
module Mocha # :nodoc:
|
4
|
-
|
5
|
-
class MissingExpectation < Expectation # :nodoc:
|
6
|
-
|
7
|
-
def initialize(mock, method_name)
|
8
|
-
super
|
9
|
-
@invoked_count = true
|
10
|
-
end
|
11
|
-
|
12
|
-
def verify
|
13
|
-
msg = error_message(0, 1)
|
14
|
-
similar_expectations_list = similar_expectations.collect { |expectation| expectation.method_signature }.join("\n")
|
15
|
-
msg << "\nSimilar expectations:\n#{similar_expectations_list}" unless similar_expectations.empty?
|
16
|
-
error = ExpectationError.new(msg)
|
17
|
-
error.set_backtrace(filtered_backtrace)
|
18
|
-
raise error if @invoked_count
|
19
|
-
end
|
20
|
-
|
21
|
-
def similar_expectations
|
22
|
-
@mock.expectations.select { |expectation| expectation.method_name == self.method_name }
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
data/test/lib/mocha/mock.rb
DELETED
@@ -1,207 +0,0 @@
|
|
1
|
-
require 'mocha/expectation'
|
2
|
-
require 'mocha/stub'
|
3
|
-
require 'mocha/missing_expectation'
|
4
|
-
require 'mocha/metaclass'
|
5
|
-
|
6
|
-
module Mocha # :nodoc:
|
7
|
-
|
8
|
-
# Traditional mock object.
|
9
|
-
#
|
10
|
-
# Methods return an Expectation which can be further modified by methods on Expectation.
|
11
|
-
class Mock
|
12
|
-
|
13
|
-
# :stopdoc:
|
14
|
-
|
15
|
-
def initialize(stub_everything = false, name = nil)
|
16
|
-
@stub_everything = stub_everything
|
17
|
-
@mock_name = name
|
18
|
-
@expectations = []
|
19
|
-
@responder = nil
|
20
|
-
end
|
21
|
-
|
22
|
-
attr_reader :stub_everything, :expectations
|
23
|
-
|
24
|
-
# :startdoc:
|
25
|
-
|
26
|
-
# :call-seq: expects(method_name) -> expectation
|
27
|
-
# expects(method_names) -> last expectation
|
28
|
-
#
|
29
|
-
# Adds an expectation that a method identified by +method_name+ symbol must be called exactly once with any parameters.
|
30
|
-
# Returns the new expectation which can be further modified by methods on Expectation.
|
31
|
-
# object = mock()
|
32
|
-
# object.expects(:method1)
|
33
|
-
# object.method1
|
34
|
-
# # no error raised
|
35
|
-
#
|
36
|
-
# object = mock()
|
37
|
-
# object.expects(:method1)
|
38
|
-
# # error raised, because method1 not called exactly once
|
39
|
-
# If +method_names+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+.
|
40
|
-
# object = mock()
|
41
|
-
# object.expects(:method1 => :result1, :method2 => :result2)
|
42
|
-
#
|
43
|
-
# # exactly equivalent to
|
44
|
-
#
|
45
|
-
# object = mock()
|
46
|
-
# object.expects(:method1).returns(:result1)
|
47
|
-
# object.expects(:method2).returns(:result2)
|
48
|
-
#
|
49
|
-
# Aliased by <tt>\_\_expects\_\_</tt>
|
50
|
-
def expects(method_name_or_hash, backtrace = nil)
|
51
|
-
if method_name_or_hash.is_a?(Hash) then
|
52
|
-
method_name_or_hash.each do |method_name, return_value|
|
53
|
-
add_expectation(Expectation.new(self, method_name, backtrace).returns(return_value))
|
54
|
-
end
|
55
|
-
else
|
56
|
-
add_expectation(Expectation.new(self, method_name_or_hash, backtrace))
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# :call-seq: stubs(method_name) -> expectation
|
61
|
-
# stubs(method_names) -> last expectation
|
62
|
-
#
|
63
|
-
# Adds an expectation that a method identified by +method_name+ symbol may be called any number of times with any parameters.
|
64
|
-
# Returns the new expectation which can be further modified by methods on Expectation.
|
65
|
-
# object = mock()
|
66
|
-
# object.stubs(:method1)
|
67
|
-
# object.method1
|
68
|
-
# object.method1
|
69
|
-
# # no error raised
|
70
|
-
# If +method_names+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+.
|
71
|
-
# object = mock()
|
72
|
-
# object.stubs(:method1 => :result1, :method2 => :result2)
|
73
|
-
#
|
74
|
-
# # exactly equivalent to
|
75
|
-
#
|
76
|
-
# object = mock()
|
77
|
-
# object.stubs(:method1).returns(:result1)
|
78
|
-
# object.stubs(:method2).returns(:result2)
|
79
|
-
#
|
80
|
-
# Aliased by <tt>\_\_stubs\_\_</tt>
|
81
|
-
def stubs(method_name_or_hash, backtrace = nil)
|
82
|
-
if method_name_or_hash.is_a?(Hash) then
|
83
|
-
method_name_or_hash.each do |method_name, return_value|
|
84
|
-
add_expectation(Stub.new(self, method_name, backtrace).returns(return_value))
|
85
|
-
end
|
86
|
-
else
|
87
|
-
add_expectation(Stub.new(self, method_name_or_hash, backtrace))
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
# :call-seq: responds_like(responder) -> mock
|
92
|
-
#
|
93
|
-
# Constrains the +mock+ so that it can only expect or stub methods to which +responder+ responds. The constraint is only applied at method invocation time.
|
94
|
-
#
|
95
|
-
# A +NoMethodError+ will be raised if the +responder+ does not <tt>respond_to?</tt> a method invocation (even if the method has been expected or stubbed).
|
96
|
-
#
|
97
|
-
# The +mock+ will delegate its <tt>respond_to?</tt> method to the +responder+.
|
98
|
-
# class Sheep
|
99
|
-
# def chew(grass); end
|
100
|
-
# def self.number_of_legs; end
|
101
|
-
# end
|
102
|
-
#
|
103
|
-
# sheep = mock('sheep')
|
104
|
-
# sheep.expects(:chew)
|
105
|
-
# sheep.expects(:foo)
|
106
|
-
# sheep.respond_to?(:chew) # => true
|
107
|
-
# sheep.respond_to?(:foo) # => true
|
108
|
-
# sheep.chew
|
109
|
-
# sheep.foo
|
110
|
-
# # no error raised
|
111
|
-
#
|
112
|
-
# sheep = mock('sheep')
|
113
|
-
# sheep.responds_like(Sheep.new)
|
114
|
-
# sheep.expects(:chew)
|
115
|
-
# sheep.expects(:foo)
|
116
|
-
# sheep.respond_to?(:chew) # => true
|
117
|
-
# sheep.respond_to?(:foo) # => false
|
118
|
-
# sheep.chew
|
119
|
-
# sheep.foo # => raises NoMethodError exception
|
120
|
-
#
|
121
|
-
# sheep_class = mock('sheep_class')
|
122
|
-
# sheep_class.responds_like(Sheep)
|
123
|
-
# sheep_class.stubs(:number_of_legs).returns(4)
|
124
|
-
# sheep_class.expects(:foo)
|
125
|
-
# sheep_class.respond_to?(:number_of_legs) # => true
|
126
|
-
# sheep_class.respond_to?(:foo) # => false
|
127
|
-
# assert_equal 4, sheep_class.number_of_legs
|
128
|
-
# sheep_class.foo # => raises NoMethodError exception
|
129
|
-
#
|
130
|
-
# Aliased by +quacks_like+
|
131
|
-
def responds_like(object)
|
132
|
-
@responder = object
|
133
|
-
self
|
134
|
-
end
|
135
|
-
|
136
|
-
# :stopdoc:
|
137
|
-
|
138
|
-
alias_method :__expects__, :expects
|
139
|
-
|
140
|
-
alias_method :__stubs__, :stubs
|
141
|
-
|
142
|
-
alias_method :quacks_like, :responds_like
|
143
|
-
|
144
|
-
def add_expectation(expectation)
|
145
|
-
@expectations << expectation
|
146
|
-
method_name = expectation.method_name
|
147
|
-
self.__metaclass__.send(:undef_method, method_name) if self.__metaclass__.method_defined?(method_name)
|
148
|
-
expectation
|
149
|
-
end
|
150
|
-
|
151
|
-
def method_missing(symbol, *arguments, &block)
|
152
|
-
if @responder and not @responder.respond_to?(symbol)
|
153
|
-
raise NoMethodError, "undefined method `#{symbol}' for #{self.mocha_inspect} which responds like #{@responder.mocha_inspect}"
|
154
|
-
end
|
155
|
-
matching_expectation = matching_expectation(symbol, *arguments)
|
156
|
-
if matching_expectation then
|
157
|
-
matching_expectation.invoke(&block)
|
158
|
-
elsif stub_everything then
|
159
|
-
return
|
160
|
-
else
|
161
|
-
begin
|
162
|
-
super_method_missing(symbol, *arguments, &block)
|
163
|
-
rescue NoMethodError
|
164
|
-
unexpected_method_called(symbol, *arguments)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def respond_to?(symbol)
|
170
|
-
if @responder then
|
171
|
-
@responder.respond_to?(symbol)
|
172
|
-
else
|
173
|
-
@expectations.any? { |expectation| expectation.method_name == symbol }
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
def super_method_missing(symbol, *arguments, &block)
|
178
|
-
raise NoMethodError
|
179
|
-
end
|
180
|
-
|
181
|
-
def unexpected_method_called(symbol, *arguments)
|
182
|
-
MissingExpectation.new(self, symbol).with(*arguments).verify
|
183
|
-
end
|
184
|
-
|
185
|
-
def matching_expectation(symbol, *arguments)
|
186
|
-
@expectations.reverse.detect { |expectation| expectation.match?(symbol, *arguments) }
|
187
|
-
end
|
188
|
-
|
189
|
-
def verify(&block)
|
190
|
-
@expectations.each { |expectation| expectation.verify(&block) }
|
191
|
-
end
|
192
|
-
|
193
|
-
def mocha_inspect
|
194
|
-
address = self.__id__ * 2
|
195
|
-
address += 0x100000000 if address < 0
|
196
|
-
@mock_name ? "#<Mock:#{@mock_name}>" : "#<Mock:0x#{'%x' % address}>"
|
197
|
-
end
|
198
|
-
|
199
|
-
def inspect
|
200
|
-
mocha_inspect
|
201
|
-
end
|
202
|
-
|
203
|
-
# :startdoc:
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
|
-
end
|
@@ -1,20 +0,0 @@
|
|
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
|
-
|
data/test/lib/mocha/no_yields.rb
DELETED
data/test/lib/mocha/object.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
require 'mocha/mock'
|
2
|
-
require 'mocha/instance_method'
|
3
|
-
require 'mocha/class_method'
|
4
|
-
require 'mocha/any_instance_method'
|
5
|
-
|
6
|
-
# Methods added all objects to allow mocking and stubbing on real objects.
|
7
|
-
#
|
8
|
-
# Methods return a Mocha::Expectation which can be further modified by methods on Mocha::Expectation.
|
9
|
-
class Object
|
10
|
-
|
11
|
-
def mocha # :nodoc:
|
12
|
-
@mocha ||= Mocha::Mock.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def reset_mocha # :nodoc:
|
16
|
-
@mocha = nil
|
17
|
-
end
|
18
|
-
|
19
|
-
def stubba_method # :nodoc:
|
20
|
-
Mocha::InstanceMethod
|
21
|
-
end
|
22
|
-
|
23
|
-
def stubba_object # :nodoc:
|
24
|
-
self
|
25
|
-
end
|
26
|
-
|
27
|
-
# :call-seq: expects(symbol) -> expectation
|
28
|
-
#
|
29
|
-
# Adds an expectation that a method identified by +symbol+ must be called exactly once with any parameters.
|
30
|
-
# Returns the new expectation which can be further modified by methods on Mocha::Expectation.
|
31
|
-
# product = Product.new
|
32
|
-
# product.expects(:save).returns(true)
|
33
|
-
# assert_equal false, product.save
|
34
|
-
#
|
35
|
-
# The original implementation of <tt>Product#save</tt> is replaced temporarily.
|
36
|
-
#
|
37
|
-
# The original implementation of <tt>Product#save</tt> is restored at the end of the test.
|
38
|
-
def expects(symbol)
|
39
|
-
method = stubba_method.new(stubba_object, symbol)
|
40
|
-
$stubba.stub(method)
|
41
|
-
mocha.expects(symbol, caller)
|
42
|
-
end
|
43
|
-
|
44
|
-
# :call-seq: stubs(symbol) -> expectation
|
45
|
-
#
|
46
|
-
# Adds an expectation that a method identified by +symbol+ may be called any number of times with any parameters.
|
47
|
-
# Returns the new expectation which can be further modified by methods on Mocha::Expectation.
|
48
|
-
# product = Product.new
|
49
|
-
# product.stubs(:save).returns(true)
|
50
|
-
# assert_equal false, product.save
|
51
|
-
#
|
52
|
-
# The original implementation of <tt>Product#save</tt> is replaced temporarily.
|
53
|
-
#
|
54
|
-
# The original implementation of <tt>Product#save</tt> is restored at the end of the test.
|
55
|
-
def stubs(symbol)
|
56
|
-
method = stubba_method.new(stubba_object, symbol)
|
57
|
-
$stubba.stub(method)
|
58
|
-
mocha.stubs(symbol, caller)
|
59
|
-
end
|
60
|
-
|
61
|
-
def verify # :nodoc:
|
62
|
-
mocha.verify
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
class Module # :nodoc:
|
68
|
-
|
69
|
-
def stubba_method
|
70
|
-
Mocha::ClassMethod
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
class Class
|
76
|
-
|
77
|
-
def stubba_method # :nodoc:
|
78
|
-
Mocha::ClassMethod
|
79
|
-
end
|
80
|
-
|
81
|
-
class AnyInstance # :nodoc:
|
82
|
-
|
83
|
-
def initialize(klass)
|
84
|
-
@stubba_object = klass
|
85
|
-
end
|
86
|
-
|
87
|
-
def stubba_method
|
88
|
-
Mocha::AnyInstanceMethod
|
89
|
-
end
|
90
|
-
|
91
|
-
def stubba_object
|
92
|
-
@stubba_object
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
# :call-seq: any_instance -> mock object
|
98
|
-
#
|
99
|
-
# Returns a mock object which will detect calls to any instance of this class.
|
100
|
-
# Product.any_instance.stubs(:save).returns(false)
|
101
|
-
# product_1 = Product.new
|
102
|
-
# assert_equal false, product_1.save
|
103
|
-
# product_2 = Product.new
|
104
|
-
# assert_equal false, product_2.save
|
105
|
-
def any_instance
|
106
|
-
@any_instance ||= AnyInstance.new(self)
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|