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.

Files changed (266) hide show
  1. data/CHANGELOG +94 -0
  2. data/Rakefile +0 -4
  3. data/bin/puppet +18 -10
  4. data/bin/puppetd +1 -1
  5. data/bin/puppetdoc +14 -4
  6. data/bin/puppetmasterd +1 -1
  7. data/bin/puppetrun +3 -8
  8. data/bin/ralsh +12 -11
  9. data/conf/freebsd/puppetd +1 -1
  10. data/conf/freebsd/puppetmasterd +1 -1
  11. data/conf/gentoo/puppet/puppet.conf +29 -0
  12. data/conf/namespaceauth.conf +20 -0
  13. data/conf/redhat/puppet.spec +4 -1
  14. data/conf/solaris/smf/puppetd.xml +1 -1
  15. data/conf/solaris/smf/puppetmasterd.xml +1 -1
  16. data/conf/suse/puppet.spec +10 -8
  17. data/examples/root/etc/puppet/{puppetmasterd.conf → puppet.conf} +6 -3
  18. data/ext/logcheck/puppet +7 -0
  19. data/ext/puppet-test +28 -5
  20. data/lib/puppet.rb +2 -1
  21. data/lib/puppet/defaults.rb +12 -5
  22. data/lib/puppet/dsl.rb +43 -45
  23. data/lib/puppet/external/{gratr/rdot.rb → dot.rb} +0 -0
  24. data/lib/puppet/external/nagios.rb +50 -0
  25. data/lib/puppet/external/nagios/base.rb +421 -0
  26. data/lib/puppet/external/nagios/parser.rb +816 -0
  27. data/lib/puppet/file_serving/file_base.rb +16 -3
  28. data/lib/puppet/file_serving/metadata.rb +29 -11
  29. data/lib/puppet/indirector/terminus.rb +1 -0
  30. data/lib/puppet/metatype/closure.rb +4 -0
  31. data/lib/puppet/metatype/evaluation.rb +2 -17
  32. data/lib/puppet/metatype/metaparams.rb +1 -1
  33. data/lib/puppet/network.rb +3 -0
  34. data/lib/puppet/network/client.rb +4 -5
  35. data/lib/puppet/network/client/master.rb +10 -7
  36. data/lib/puppet/network/handler/fileserver.rb +22 -45
  37. data/lib/puppet/network/http_pool.rb +3 -0
  38. data/lib/puppet/network/http_server/mongrel.rb +7 -1
  39. data/lib/puppet/network/http_server/webrick.rb +4 -3
  40. data/lib/puppet/network/xmlrpc/client.rb +12 -1
  41. data/lib/puppet/node/catalog.rb +51 -40
  42. data/lib/puppet/parser/ast.rb +27 -49
  43. data/lib/puppet/parser/ast/astarray.rb +5 -24
  44. data/lib/puppet/parser/ast/caseopt.rb +4 -4
  45. data/lib/puppet/parser/ast/casestatement.rb +4 -5
  46. data/lib/puppet/parser/ast/collection.rb +3 -5
  47. data/lib/puppet/parser/ast/collexpr.rb +3 -5
  48. data/lib/puppet/parser/ast/definition.rb +148 -159
  49. data/lib/puppet/parser/ast/else.rb +2 -3
  50. data/lib/puppet/parser/ast/function.rb +3 -10
  51. data/lib/puppet/parser/ast/hostclass.rb +66 -59
  52. data/lib/puppet/parser/ast/ifstatement.rb +4 -5
  53. data/lib/puppet/parser/ast/leaf.rb +6 -6
  54. data/lib/puppet/parser/ast/node.rb +26 -58
  55. data/lib/puppet/parser/ast/resource.rb +5 -7
  56. data/lib/puppet/parser/ast/resource_defaults.rb +2 -4
  57. data/lib/puppet/parser/ast/resource_override.rb +4 -6
  58. data/lib/puppet/parser/ast/resource_reference.rb +2 -4
  59. data/lib/puppet/parser/ast/resourceparam.rb +2 -4
  60. data/lib/puppet/parser/ast/selector.rb +5 -6
  61. data/lib/puppet/parser/ast/tag.rb +2 -4
  62. data/lib/puppet/parser/ast/vardef.rb +3 -4
  63. data/lib/puppet/parser/collector.rb +5 -5
  64. data/lib/puppet/parser/{compile.rb → compiler.rb} +69 -107
  65. data/lib/puppet/parser/functions.rb +3 -3
  66. data/lib/puppet/parser/interpreter.rb +32 -23
  67. data/lib/puppet/parser/lexer.rb +391 -282
  68. data/lib/puppet/parser/parser.rb +5 -4
  69. data/lib/puppet/parser/parser_support.rb +3 -6
  70. data/lib/puppet/parser/resource.rb +24 -36
  71. data/lib/puppet/parser/resource/param.rb +1 -1
  72. data/lib/puppet/parser/resource/reference.rb +7 -3
  73. data/lib/puppet/parser/scope.rb +12 -7
  74. data/lib/puppet/parser/templatewrapper.rb +1 -1
  75. data/lib/puppet/pgraph.rb +9 -98
  76. data/lib/puppet/provider/interface/redhat.rb +65 -65
  77. data/lib/puppet/provider/mount/parsed.rb +1 -1
  78. data/lib/puppet/provider/naginator.rb +55 -0
  79. data/lib/puppet/provider/nameservice/directoryservice.rb +6 -7
  80. data/lib/puppet/provider/package/fink.rb +0 -2
  81. data/lib/puppet/provider/package/gem.rb +9 -5
  82. data/lib/puppet/provider/package/openbsd.rb +1 -1
  83. data/lib/puppet/provider/package/pkgdmg.rb +3 -8
  84. data/lib/puppet/provider/package/portage.rb +4 -4
  85. data/lib/puppet/provider/package/yumhelper.py +8 -6
  86. data/lib/puppet/provider/parsedfile.rb +7 -1
  87. data/lib/puppet/provider/service/debian.rb +2 -0
  88. data/lib/puppet/provider/service/gentoo.rb +4 -0
  89. data/lib/puppet/provider/service/init.rb +1 -1
  90. data/lib/puppet/provider/sshkey/parsed.rb +2 -0
  91. data/lib/puppet/provider/user/useradd.rb +1 -1
  92. data/lib/puppet/rails.rb +4 -0
  93. data/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb +17 -0
  94. data/lib/puppet/rails/fact_value.rb +4 -0
  95. data/lib/puppet/rails/host.rb +1 -2
  96. data/lib/puppet/rails/param_value.rb +4 -0
  97. data/lib/puppet/rails/resource_tag.rb +4 -0
  98. data/lib/puppet/rails/source_file.rb +4 -1
  99. data/lib/puppet/relationship.rb +5 -1
  100. data/lib/puppet/reports/tagmail.rb +12 -1
  101. data/lib/puppet/resource_reference.rb +1 -1
  102. data/lib/puppet/simple_graph.rb +78 -11
  103. data/lib/puppet/sslcertificates.rb +1 -1
  104. data/lib/puppet/sslcertificates/ca.rb +3 -3
  105. data/lib/puppet/transaction.rb +7 -4
  106. data/lib/puppet/transportable.rb +1 -1
  107. data/lib/puppet/type.rb +3 -10
  108. data/lib/puppet/type/cron.rb +18 -0
  109. data/lib/puppet/type/exec.rb +18 -12
  110. data/lib/puppet/type/{pfile.rb → file.rb} +66 -84
  111. data/lib/puppet/type/file/checksum.rb +271 -0
  112. data/lib/puppet/type/{pfile → file}/content.rb +10 -15
  113. data/lib/puppet/type/{pfile → file}/ensure.rb +15 -8
  114. data/lib/puppet/type/{pfile → file}/group.rb +0 -0
  115. data/lib/puppet/type/{pfile → file}/mode.rb +0 -0
  116. data/lib/puppet/type/{pfile → file}/owner.rb +0 -0
  117. data/lib/puppet/type/{pfile → file}/source.rb +34 -48
  118. data/lib/puppet/type/{pfile → file}/target.rb +0 -0
  119. data/lib/puppet/type/{pfile → file}/type.rb +0 -0
  120. data/lib/puppet/type/{pfilebucket.rb → filebucket.rb} +0 -0
  121. data/lib/puppet/type/host.rb +13 -0
  122. data/lib/puppet/type/mailalias.rb +1 -1
  123. data/lib/puppet/type/nagios_command.rb +3 -0
  124. data/lib/puppet/type/nagios_contact.rb +3 -0
  125. data/lib/puppet/type/nagios_contactgroup.rb +3 -0
  126. data/lib/puppet/type/nagios_host.rb +3 -0
  127. data/lib/puppet/type/nagios_hostextinfo.rb +3 -0
  128. data/lib/puppet/type/nagios_hostgroup.rb +3 -0
  129. data/lib/puppet/type/nagios_hostgroupescalation.rb +3 -0
  130. data/lib/puppet/type/nagios_service.rb +3 -0
  131. data/lib/puppet/type/nagios_servicedependency.rb +3 -0
  132. data/lib/puppet/type/nagios_serviceescalation.rb +3 -0
  133. data/lib/puppet/type/nagios_serviceextinfo.rb +3 -0
  134. data/lib/puppet/type/nagios_timeperiod.rb +3 -0
  135. data/lib/puppet/type/package.rb +4 -12
  136. data/lib/puppet/type/service.rb +9 -0
  137. data/lib/puppet/type/sshkey.rb +3 -3
  138. data/lib/puppet/util/autoload.rb +5 -5
  139. data/lib/puppet/util/checksums.rb +51 -13
  140. data/lib/puppet/util/constant_inflector.rb +14 -0
  141. data/lib/puppet/util/filetype.rb +1 -1
  142. data/lib/puppet/util/graph.rb +3 -9
  143. data/lib/puppet/util/nagios_maker.rb +57 -0
  144. data/lib/puppet/util/settings.rb +19 -16
  145. data/lib/puppet/util/tagging.rb +39 -0
  146. data/test/executables/puppetbin.rb +17 -0
  147. data/test/language/ast.rb +8 -58
  148. data/test/language/ast/casestatement.rb +3 -3
  149. data/test/language/ast/resource.rb +6 -7
  150. data/test/language/ast/resource_reference.rb +12 -12
  151. data/test/language/ast/selector.rb +2 -2
  152. data/test/language/ast/variable.rb +2 -2
  153. data/test/language/functions.rb +24 -24
  154. data/test/language/parser.rb +20 -8
  155. data/test/language/resource.rb +5 -42
  156. data/test/language/scope.rb +21 -37
  157. data/test/language/snippets.rb +7 -0
  158. data/test/lib/puppettest.rb +28 -14
  159. data/test/lib/puppettest/parsertesting.rb +10 -10
  160. data/test/lib/puppettest/support/resources.rb +1 -1
  161. data/test/network/client/master.rb +10 -0
  162. data/test/network/handler/fileserver.rb +51 -49
  163. data/test/network/server/webrick.rb +1 -1
  164. data/test/other/dsl.rb +3 -4
  165. data/test/other/transactions.rb +6 -4
  166. data/test/rails/ast.rb +2 -2
  167. data/test/rails/configuration.rb +1 -1
  168. data/test/rails/railsparameter.rb +2 -0
  169. data/test/rails/railsresource.rb +1 -0
  170. data/test/ral/manager/type.rb +4 -4
  171. data/test/ral/providers/cron/crontab.rb +3 -1
  172. data/test/ral/providers/package.rb +1 -1
  173. data/test/ral/{types → type}/basic.rb +2 -2
  174. data/test/ral/{types → type}/cron.rb +0 -0
  175. data/test/ral/{types → type}/exec.rb +42 -2
  176. data/test/ral/{types → type}/file.rb +34 -79
  177. data/test/ral/{types → type}/file/target.rb +0 -0
  178. data/test/ral/{types → type}/filebucket.rb +0 -0
  179. data/test/ral/{types → type}/fileignoresource.rb +0 -0
  180. data/test/ral/{types → type}/filesources.rb +8 -27
  181. data/test/ral/{types → type}/group.rb +0 -0
  182. data/test/ral/{types → type}/host.rb +16 -0
  183. data/test/ral/{types → type}/mailalias.rb +0 -0
  184. data/test/ral/{types → type}/parameter.rb +0 -0
  185. data/test/ral/{types → type}/port.rb +0 -0
  186. data/test/ral/{types → type}/property.rb +0 -0
  187. data/test/ral/{types → type}/resources.rb +0 -0
  188. data/test/ral/{types → type}/service.rb +0 -0
  189. data/test/ral/{types → type}/sshkey.rb +0 -0
  190. data/test/ral/{types → type}/tidy.rb +1 -0
  191. data/test/ral/{types → type}/user.rb +0 -0
  192. data/test/ral/{types → type}/yumrepo.rb +0 -0
  193. data/test/ral/{types → type}/zone.rb +0 -0
  194. data/test/util/autoload.rb +24 -5
  195. metadata +60 -107
  196. data/conf/gentoo/puppet/puppetca.conf +0 -29
  197. data/conf/gentoo/puppet/puppetd.conf +0 -29
  198. data/conf/gentoo/puppet/puppetmasterd.conf +0 -29
  199. data/examples/root/etc/puppet/puppetd.conf +0 -4
  200. data/lib/puppet/external/gratr.rb +0 -33
  201. data/lib/puppet/external/gratr/adjacency_graph.rb +0 -257
  202. data/lib/puppet/external/gratr/base.rb +0 -34
  203. data/lib/puppet/external/gratr/biconnected.rb +0 -116
  204. data/lib/puppet/external/gratr/chinese_postman.rb +0 -123
  205. data/lib/puppet/external/gratr/common.rb +0 -73
  206. data/lib/puppet/external/gratr/comparability.rb +0 -92
  207. data/lib/puppet/external/gratr/digraph.rb +0 -116
  208. data/lib/puppet/external/gratr/digraph_distance.rb +0 -185
  209. data/lib/puppet/external/gratr/dot.rb +0 -90
  210. data/lib/puppet/external/gratr/edge.rb +0 -145
  211. data/lib/puppet/external/gratr/graph.rb +0 -303
  212. data/lib/puppet/external/gratr/graph_api.rb +0 -83
  213. data/lib/puppet/external/gratr/import.rb +0 -44
  214. data/lib/puppet/external/gratr/labels.rb +0 -90
  215. data/lib/puppet/external/gratr/maximum_flow.rb +0 -64
  216. data/lib/puppet/external/gratr/search.rb +0 -409
  217. data/lib/puppet/external/gratr/strong_components.rb +0 -127
  218. data/lib/puppet/external/gratr/undirected_graph.rb +0 -153
  219. data/lib/puppet/rails/external/tagging/acts_as_taggable.rb +0 -62
  220. data/lib/puppet/rails/external/tagging/init.rb +0 -5
  221. data/lib/puppet/rails/external/tagging/tag.rb +0 -50
  222. data/lib/puppet/rails/external/tagging/tagging.rb +0 -12
  223. data/lib/puppet/rails/puppet_class.rb +0 -6
  224. data/lib/puppet/reference/node_source.rb +0 -9
  225. data/lib/puppet/reference/report.rb +0 -21
  226. data/lib/puppet/type/pfile/checksum.rb +0 -326
  227. data/test/language/ast/definition.rb +0 -166
  228. data/test/language/ast/hostclass.rb +0 -184
  229. data/test/language/compile.rb +0 -569
  230. data/test/language/lexer.rb +0 -276
  231. data/test/lib/mocha.rb +0 -19
  232. data/test/lib/mocha/any_instance_method.rb +0 -35
  233. data/test/lib/mocha/auto_verify.rb +0 -113
  234. data/test/lib/mocha/central.rb +0 -35
  235. data/test/lib/mocha/class_method.rb +0 -62
  236. data/test/lib/mocha/deprecation.rb +0 -22
  237. data/test/lib/mocha/exception_raiser.rb +0 -17
  238. data/test/lib/mocha/expectation.rb +0 -378
  239. data/test/lib/mocha/expectation_error.rb +0 -6
  240. data/test/lib/mocha/infinite_range.rb +0 -25
  241. data/test/lib/mocha/inspect.rb +0 -39
  242. data/test/lib/mocha/instance_method.rb +0 -8
  243. data/test/lib/mocha/is_a.rb +0 -9
  244. data/test/lib/mocha/metaclass.rb +0 -7
  245. data/test/lib/mocha/missing_expectation.rb +0 -27
  246. data/test/lib/mocha/mock.rb +0 -207
  247. data/test/lib/mocha/multiple_yields.rb +0 -20
  248. data/test/lib/mocha/no_yields.rb +0 -11
  249. data/test/lib/mocha/object.rb +0 -110
  250. data/test/lib/mocha/parameter_matchers.rb +0 -9
  251. data/test/lib/mocha/parameter_matchers/all_of.rb +0 -39
  252. data/test/lib/mocha/parameter_matchers/any_of.rb +0 -44
  253. data/test/lib/mocha/parameter_matchers/anything.rb +0 -30
  254. data/test/lib/mocha/parameter_matchers/has_entry.rb +0 -39
  255. data/test/lib/mocha/parameter_matchers/has_key.rb +0 -39
  256. data/test/lib/mocha/parameter_matchers/has_value.rb +0 -39
  257. data/test/lib/mocha/parameter_matchers/includes.rb +0 -37
  258. data/test/lib/mocha/pretty_parameters.rb +0 -28
  259. data/test/lib/mocha/return_values.rb +0 -31
  260. data/test/lib/mocha/setup_and_teardown.rb +0 -23
  261. data/test/lib/mocha/single_return_value.rb +0 -24
  262. data/test/lib/mocha/single_yield.rb +0 -18
  263. data/test/lib/mocha/standalone.rb +0 -32
  264. data/test/lib/mocha/stub.rb +0 -18
  265. data/test/lib/mocha/test_case_adapter.rb +0 -49
  266. data/test/lib/mocha/yield_parameters.rb +0 -31
@@ -1,62 +0,0 @@
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, @method = stubbee, method
11
- end
12
-
13
- def stub
14
- hide_original_method
15
- define_new_method
16
- end
17
-
18
- def unstub
19
- remove_new_method
20
- restore_original_method
21
- stubbee.reset_mocha
22
- end
23
-
24
- def mock
25
- stubbee.mocha
26
- end
27
-
28
- def hide_original_method
29
- stubbee.__metaclass__.class_eval "alias_method :#{hidden_method}, :#{method}" if stubbee.__metaclass__.method_defined?(method)
30
- end
31
-
32
- def define_new_method
33
- stubbee.__metaclass__.class_eval "def #{method}(*args, &block); mocha.method_missing(:#{method}, *args, &block); end"
34
- end
35
-
36
- def remove_new_method
37
- stubbee.__metaclass__.class_eval "remove_method :#{method}"
38
- end
39
-
40
- def restore_original_method
41
- stubbee.__metaclass__.class_eval "alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}" if stubbee.__metaclass__.method_defined?(hidden_method)
42
- end
43
-
44
- def hidden_method
45
- method_name = method.to_s.gsub(/\W/) {|s| "_substituted_character_#{s[0]}_" }
46
- "__stubba__#{method_name}__stubba__"
47
- end
48
-
49
- def eql?(other)
50
- return false unless (other.class == self.class)
51
- (stubbee == other.stubbee) and (method == other.method)
52
- end
53
-
54
- alias_method :==, :eql?
55
-
56
- def to_s
57
- "#{stubbee}.#{method}"
58
- end
59
-
60
- end
61
-
62
- end
@@ -1,22 +0,0 @@
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
@@ -1,17 +0,0 @@
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 == Interrupt
11
- raise @exception, @message if @message
12
- raise @exception
13
- end
14
-
15
- end
16
-
17
- end
@@ -1,378 +0,0 @@
1
- require 'mocha/infinite_range'
2
- require 'mocha/pretty_parameters'
3
- require 'mocha/expectation_error'
4
- require 'mocha/return_values'
5
- require 'mocha/exception_raiser'
6
- require 'mocha/yield_parameters'
7
- require 'mocha/is_a'
8
-
9
- module Mocha # :nodoc:
10
-
11
- # Methods on expectations returned from Mock#expects, Mock#stubs, Object#expects and Object#stubs.
12
- class Expectation
13
-
14
- # :stopdoc:
15
-
16
- class AlwaysEqual
17
- def ==(other)
18
- true
19
- end
20
- end
21
-
22
- attr_reader :method_name, :backtrace
23
-
24
- def initialize(mock, method_name, backtrace = nil)
25
- @mock, @method_name = mock, method_name
26
- @expected_count = 1
27
- @parameters, @parameter_block = AlwaysEqual.new, nil
28
- @invoked_count, @return_values = 0, ReturnValues.new
29
- @backtrace = backtrace || caller
30
- @yield_parameters = YieldParameters.new
31
- end
32
-
33
- def match?(method_name, *arguments)
34
- return false unless @method_name == method_name
35
- if @parameter_block then
36
- return false unless @parameter_block.call(*arguments)
37
- else
38
- return false unless (@parameters == arguments)
39
- end
40
- if @expected_count.is_a?(Range) then
41
- return false unless @invoked_count < @expected_count.last
42
- else
43
- return false unless @invoked_count < @expected_count
44
- end
45
- return true
46
- end
47
-
48
- # :startdoc:
49
-
50
- # :call-seq: times(range) -> expectation
51
- #
52
- # Modifies expectation so that the number of calls to the expected method must be within a specific +range+.
53
- #
54
- # +range+ can be specified as an exact integer or as a range of integers
55
- # object = mock()
56
- # object.expects(:expected_method).times(3)
57
- # 3.times { object.expected_method }
58
- # # => verify succeeds
59
- #
60
- # object = mock()
61
- # object.expects(:expected_method).times(3)
62
- # 2.times { object.expected_method }
63
- # # => verify fails
64
- #
65
- # object = mock()
66
- # object.expects(:expected_method).times(2..4)
67
- # 3.times { object.expected_method }
68
- # # => verify succeeds
69
- #
70
- # object = mock()
71
- # object.expects(:expected_method).times(2..4)
72
- # object.expected_method
73
- # # => verify fails
74
- def times(range)
75
- @expected_count = range
76
- self
77
- end
78
-
79
- # :call-seq: once() -> expectation
80
- #
81
- # Modifies expectation so that the expected method must be called exactly once.
82
- # Note that this is the default behaviour for an expectation, but you may wish to use it for clarity/emphasis.
83
- # object = mock()
84
- # object.expects(:expected_method).once
85
- # object.expected_method
86
- # # => verify succeeds
87
- #
88
- # object = mock()
89
- # object.expects(:expected_method).once
90
- # object.expected_method
91
- # object.expected_method
92
- # # => verify fails
93
- #
94
- # object = mock()
95
- # object.expects(:expected_method).once
96
- # # => verify fails
97
- def once()
98
- times(1)
99
- self
100
- end
101
-
102
- # :call-seq: never() -> expectation
103
- #
104
- # Modifies expectation so that the expected method must never be called.
105
- # object = mock()
106
- # object.expects(:expected_method).never
107
- # object.expected_method
108
- # # => verify fails
109
- #
110
- # object = mock()
111
- # object.expects(:expected_method).never
112
- # object.expected_method
113
- # # => verify succeeds
114
- def never
115
- times(0)
116
- self
117
- end
118
-
119
- # :call-seq: at_least(minimum_number_of_times) -> expectation
120
- #
121
- # Modifies expectation so that the expected method must be called at least a +minimum_number_of_times+.
122
- # object = mock()
123
- # object.expects(:expected_method).at_least(2)
124
- # 3.times { object.expected_method }
125
- # # => verify succeeds
126
- #
127
- # object = mock()
128
- # object.expects(:expected_method).at_least(2)
129
- # object.expected_method
130
- # # => verify fails
131
- def at_least(minimum_number_of_times)
132
- times(Range.at_least(minimum_number_of_times))
133
- self
134
- end
135
-
136
- # :call-seq: at_least_once() -> expectation
137
- #
138
- # Modifies expectation so that the expected method must be called at least once.
139
- # object = mock()
140
- # object.expects(:expected_method).at_least_once
141
- # object.expected_method
142
- # # => verify succeeds
143
- #
144
- # object = mock()
145
- # object.expects(:expected_method).at_least_once
146
- # # => verify fails
147
- def at_least_once()
148
- at_least(1)
149
- self
150
- end
151
-
152
- # :call-seq: at_most(maximum_number_of_times) -> expectation
153
- #
154
- # Modifies expectation so that the expected method must be called at most a +maximum_number_of_times+.
155
- # object = mock()
156
- # object.expects(:expected_method).at_most(2)
157
- # 2.times { object.expected_method }
158
- # # => verify succeeds
159
- #
160
- # object = mock()
161
- # object.expects(:expected_method).at_most(2)
162
- # 3.times { object.expected_method }
163
- # # => verify fails
164
- def at_most(maximum_number_of_times)
165
- times(Range.at_most(maximum_number_of_times))
166
- self
167
- end
168
-
169
- # :call-seq: at_most_once() -> expectation
170
- #
171
- # Modifies expectation so that the expected method must be called at most once.
172
- # object = mock()
173
- # object.expects(:expected_method).at_most_once
174
- # object.expected_method
175
- # # => verify succeeds
176
- #
177
- # object = mock()
178
- # object.expects(:expected_method).at_most_once
179
- # 2.times { object.expected_method }
180
- # # => verify fails
181
- def at_most_once()
182
- at_most(1)
183
- self
184
- end
185
-
186
- # :call-seq: with(*arguments, &parameter_block) -> expectation
187
- #
188
- # Modifies expectation so that the expected method must be called with specified +arguments+.
189
- # object = mock()
190
- # object.expects(:expected_method).with(:param1, :param2)
191
- # object.expected_method(:param1, :param2)
192
- # # => verify succeeds
193
- #
194
- # object = mock()
195
- # object.expects(:expected_method).with(:param1, :param2)
196
- # object.expected_method(:param3)
197
- # # => verify fails
198
- # May be used with parameter matchers in Mocha::ParameterMatchers.
199
- #
200
- # If a +parameter_block+ is given, the block is called with the parameters passed to the expected method.
201
- # The expectation is matched if the block evaluates to +true+.
202
- # object = mock()
203
- # object.expects(:expected_method).with() { |value| value % 4 == 0 }
204
- # object.expected_method(16)
205
- # # => verify succeeds
206
- #
207
- # object = mock()
208
- # object.expects(:expected_method).with() { |value| value % 4 == 0 }
209
- # object.expected_method(17)
210
- # # => verify fails
211
- def with(*arguments, &parameter_block)
212
- @parameters, @parameter_block = arguments, parameter_block
213
- class << @parameters; def to_s; join(', '); end; end
214
- self
215
- end
216
-
217
- # :call-seq: yields(*parameters) -> expectation
218
- #
219
- # Modifies expectation so that when the expected method is called, it yields with the specified +parameters+.
220
- # object = mock()
221
- # object.expects(:expected_method).yields('result')
222
- # yielded_value = nil
223
- # object.expected_method { |value| yielded_value = value }
224
- # yielded_value # => 'result'
225
- # May be called multiple times on the same expectation for consecutive invocations. Also see Expectation#then.
226
- # object = mock()
227
- # object.stubs(:expected_method).yields(1).then.yields(2)
228
- # yielded_values_from_first_invocation = []
229
- # yielded_values_from_second_invocation = []
230
- # object.expected_method { |value| yielded_values_from_first_invocation << value } # first invocation
231
- # object.expected_method { |value| yielded_values_from_second_invocation << value } # second invocation
232
- # yielded_values_from_first_invocation # => [1]
233
- # yielded_values_from_second_invocation # => [2]
234
- def yields(*parameters)
235
- @yield_parameters.add(*parameters)
236
- self
237
- end
238
-
239
- # :call-seq: multiple_yields(*parameter_groups) -> expectation
240
- #
241
- # Modifies expectation so that when the expected method is called, it yields multiple times per invocation with the specified +parameter_groups+.
242
- # object = mock()
243
- # object.expects(:expected_method).multiple_yields(['result_1', 'result_2'], ['result_3'])
244
- # yielded_values = []
245
- # object.expected_method { |*values| yielded_values << values }
246
- # yielded_values # => [['result_1', 'result_2'], ['result_3]]
247
- # May be called multiple times on the same expectation for consecutive invocations. Also see Expectation#then.
248
- # object = mock()
249
- # object.stubs(:expected_method).multiple_yields([1, 2], [3]).then.multiple_yields([4], [5, 6])
250
- # yielded_values_from_first_invocation = []
251
- # yielded_values_from_second_invocation = []
252
- # object.expected_method { |*values| yielded_values_from_first_invocation << values } # first invocation
253
- # object.expected_method { |*values| yielded_values_from_second_invocation << values } # second invocation
254
- # yielded_values_from_first_invocation # => [[1, 2], [3]]
255
- # yielded_values_from_second_invocation # => [[4], [5, 6]]
256
- def multiple_yields(*parameter_groups)
257
- @yield_parameters.multiple_add(*parameter_groups)
258
- self
259
- end
260
-
261
- # :call-seq: returns(value) -> expectation
262
- # :call-seq: returns(*values) -> expectation
263
- #
264
- # Modifies expectation so that when the expected method is called, it returns the specified +value+.
265
- # object = mock()
266
- # object.stubs(:stubbed_method).returns('result')
267
- # object.stubbed_method # => 'result'
268
- # object.stubbed_method # => 'result'
269
- # If multiple +values+ are given, these are returned in turn on consecutive calls to the method.
270
- # object = mock()
271
- # object.stubs(:stubbed_method).returns(1, 2)
272
- # object.stubbed_method # => 1
273
- # object.stubbed_method # => 2
274
- # May be called multiple times on the same expectation. Also see Expectation#then.
275
- # object = mock()
276
- # object.stubs(:expected_method).returns(1, 2).then.returns(3)
277
- # object.expected_method # => 1
278
- # object.expected_method # => 2
279
- # object.expected_method # => 3
280
- # May be called in conjunction with Expectation#raises on the same expectation.
281
- # object = mock()
282
- # object.stubs(:expected_method).returns(1, 2).then.raises(Exception)
283
- # object.expected_method # => 1
284
- # object.expected_method # => 2
285
- # object.expected_method # => raises exception of class Exception1
286
- # If +value+ is a +Proc+, then the expected method will return the result of calling <tt>Proc#call</tt>.
287
- #
288
- # This usage is _deprecated_.
289
- # Use explicit multiple return values and/or multiple expectations instead.
290
- #
291
- # A +Proc+ instance will be treated the same as any other value in a future release.
292
- # object = mock()
293
- # object.stubs(:stubbed_method).returns(lambda { rand(100) })
294
- # object.stubbed_method # => 41
295
- # object.stubbed_method # => 77
296
- def returns(*values)
297
- @return_values += ReturnValues.build(*values)
298
- self
299
- end
300
-
301
- # :call-seq: raises(exception = RuntimeError, message = nil) -> expectation
302
- #
303
- # Modifies expectation so that when the expected method is called, it raises the specified +exception+ with the specified +message+.
304
- # object = mock()
305
- # object.expects(:expected_method).raises(Exception, 'message')
306
- # object.expected_method # => raises exception of class Exception and with message 'message'
307
- # May be called multiple times on the same expectation. Also see Expectation#then.
308
- # object = mock()
309
- # object.stubs(:expected_method).raises(Exception1).then.raises(Exception2)
310
- # object.expected_method # => raises exception of class Exception1
311
- # object.expected_method # => raises exception of class Exception2
312
- # May be called in conjunction with Expectation#returns on the same expectation.
313
- # object = mock()
314
- # object.stubs(:expected_method).raises(Exception).then.returns(2, 3)
315
- # object.expected_method # => raises exception of class Exception1
316
- # object.expected_method # => 2
317
- # object.expected_method # => 3
318
- def raises(exception = RuntimeError, message = nil)
319
- @return_values += ReturnValues.new(ExceptionRaiser.new(exception, message))
320
- self
321
- end
322
-
323
- # :call-seq: then() -> expectation
324
- #
325
- # Syntactic sugar to improve readability. Has no effect on state of the expectation.
326
- # object = mock()
327
- # object.stubs(:expected_method).returns(1, 2).then.raises(Exception).then.returns(4)
328
- # object.expected_method # => 1
329
- # object.expected_method # => 2
330
- # object.expected_method # => raises exception of class Exception
331
- # object.expected_method # => 4
332
- def then
333
- self
334
- end
335
-
336
- # :stopdoc:
337
-
338
- def invoke
339
- @invoked_count += 1
340
- if block_given? then
341
- @yield_parameters.next_invocation.each do |yield_parameters|
342
- yield(*yield_parameters)
343
- end
344
- end
345
- @return_values.next
346
- end
347
-
348
- def verify
349
- yield(self) if block_given?
350
- unless (@expected_count === @invoked_count) then
351
- error = ExpectationError.new(error_message(@expected_count, @invoked_count))
352
- error.set_backtrace(filtered_backtrace)
353
- raise error
354
- end
355
- end
356
-
357
- def mocha_lib_directory
358
- File.expand_path(File.join(File.dirname(__FILE__), "..")) + File::SEPARATOR
359
- end
360
-
361
- def filtered_backtrace
362
- backtrace.reject { |location| Regexp.new(mocha_lib_directory).match(File.expand_path(location)) }
363
- end
364
-
365
- def method_signature
366
- return "#{method_name}" if @parameters.__is_a__(AlwaysEqual)
367
- "#{@method_name}(#{PrettyParameters.new(@parameters).pretty})"
368
- end
369
-
370
- def error_message(expected_count, actual_count)
371
- "#{@mock.mocha_inspect}.#{method_signature} - expected calls: #{expected_count.mocha_inspect}, actual calls: #{actual_count}"
372
- end
373
-
374
- # :startdoc:
375
-
376
- end
377
-
378
- end