poolparty 0.0.4 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. data/History.txt +25 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +203 -0
  4. data/PostInstall.txt +18 -0
  5. data/README.txt +21 -82
  6. data/Rakefile +25 -18
  7. data/bin/cloud +31 -0
  8. data/bin/cloud-add-keypair +23 -0
  9. data/bin/cloud-configure +31 -0
  10. data/bin/cloud-contract +27 -0
  11. data/bin/cloud-expand +27 -0
  12. data/bin/cloud-list +32 -0
  13. data/bin/cloud-maintain +36 -0
  14. data/bin/cloud-osxcopy +22 -0
  15. data/bin/cloud-provision +31 -0
  16. data/bin/cloud-refresh +26 -0
  17. data/bin/cloud-ssh +18 -0
  18. data/bin/cloud-start +32 -0
  19. data/bin/cloud-terminate +23 -0
  20. data/bin/pool +25 -27
  21. data/bin/pool-console +12 -0
  22. data/bin/pool-describe +9 -0
  23. data/bin/pool-list +28 -0
  24. data/bin/pool-provision +34 -0
  25. data/bin/pool-spec +17 -0
  26. data/bin/pool-start +32 -0
  27. data/bin/pool-start-monitor +1 -0
  28. data/config/hoe.rb +115 -0
  29. data/config/requirements.rb +15 -0
  30. data/examples/basic.rb +20 -0
  31. data/examples/plugin_without_plugin_directory.rb +13 -0
  32. data/examples/poolparty.rb +12 -0
  33. data/examples/with_apache_plugin.rb +22 -0
  34. data/generators/poolspec/USAGE +5 -0
  35. data/generators/poolspec/poolspec_generator.rb +65 -0
  36. data/generators/poolspec/templates/pool_spec_template.erb +9 -0
  37. data/lib/erlang/eb_server.erl +27 -0
  38. data/lib/poolparty.rb +56 -0
  39. data/lib/poolparty/base_packages/haproxy.rb +42 -0
  40. data/lib/poolparty/base_packages/heartbeat.rb +45 -0
  41. data/lib/poolparty/base_packages/poolparty.rb +36 -0
  42. data/lib/poolparty/base_packages/ruby.rb +43 -0
  43. data/lib/poolparty/core/array.rb +24 -0
  44. data/lib/{core → poolparty/core}/exception.rb +0 -0
  45. data/lib/poolparty/core/float.rb +13 -0
  46. data/lib/poolparty/core/hash.rb +29 -0
  47. data/lib/poolparty/core/kernel.rb +37 -0
  48. data/lib/{core → poolparty/core}/module.rb +18 -0
  49. data/lib/poolparty/core/my_open_struct.rb +18 -0
  50. data/lib/poolparty/core/object.rb +54 -0
  51. data/lib/poolparty/core/proc.rb +7 -0
  52. data/lib/poolparty/core/string.rb +72 -0
  53. data/lib/poolparty/core/symbol.rb +8 -0
  54. data/lib/{core → poolparty/core}/time.rb +15 -0
  55. data/lib/poolparty/exceptions/RemoteException.rb +12 -0
  56. data/lib/poolparty/exceptions/ResourceException.rb +7 -0
  57. data/lib/poolparty/exceptions/RuntimeException.rb +7 -0
  58. data/lib/poolparty/exceptions/SpecException.rb +7 -0
  59. data/lib/poolparty/exceptions/TemplateNotFound.rb +7 -0
  60. data/lib/poolparty/helpers/binary.rb +31 -0
  61. data/lib/poolparty/helpers/console.rb +30 -0
  62. data/lib/poolparty/helpers/display.rb +34 -0
  63. data/lib/poolparty/helpers/optioner.rb +64 -0
  64. data/lib/poolparty/helpers/provisioner_base.rb +250 -0
  65. data/lib/poolparty/helpers/provisioners/master.rb +136 -0
  66. data/lib/poolparty/helpers/provisioners/slave.rb +44 -0
  67. data/lib/poolparty/modules/cloud_resourcer.rb +89 -0
  68. data/lib/poolparty/modules/configurable.rb +34 -0
  69. data/lib/poolparty/modules/definable_resource.rb +59 -0
  70. data/lib/poolparty/modules/file_writer.rb +55 -0
  71. data/lib/poolparty/modules/method_missing_sugar.rb +53 -0
  72. data/lib/poolparty/modules/output.rb +13 -0
  73. data/lib/poolparty/modules/pretty_printer.rb +39 -0
  74. data/lib/{core/string.rb → poolparty/modules/s3_string.rb} +5 -22
  75. data/lib/{modules → poolparty/modules}/safe_instance.rb +0 -0
  76. data/lib/poolparty/monitors/base_monitor.rb +16 -0
  77. data/lib/poolparty/net/remote.rb +35 -0
  78. data/lib/poolparty/net/remote_bases/ec2.rb +148 -0
  79. data/lib/poolparty/net/remote_instance.rb +69 -0
  80. data/lib/poolparty/net/remoter.rb +224 -0
  81. data/lib/poolparty/net/remoter_base.rb +117 -0
  82. data/lib/poolparty/plugins/gem_package.rb +17 -0
  83. data/lib/poolparty/plugins/git.rb +41 -0
  84. data/lib/poolparty/plugins/line.rb +76 -0
  85. data/lib/poolparty/plugins/svn.rb +48 -0
  86. data/lib/poolparty/pool/base.rb +75 -0
  87. data/lib/poolparty/pool/cloud.rb +164 -0
  88. data/lib/poolparty/pool/custom_resource.rb +61 -0
  89. data/lib/poolparty/pool/loggable.rb +29 -0
  90. data/lib/poolparty/pool/plugin.rb +41 -0
  91. data/lib/poolparty/pool/plugin_model.rb +48 -0
  92. data/lib/poolparty/pool/pool.rb +55 -0
  93. data/lib/poolparty/pool/resource.rb +248 -0
  94. data/lib/poolparty/pool/resources/class_package.rb +64 -0
  95. data/lib/poolparty/pool/resources/conditional.rb +41 -0
  96. data/lib/poolparty/pool/resources/cron.rb +14 -0
  97. data/lib/poolparty/pool/resources/directory.rb +23 -0
  98. data/lib/poolparty/pool/resources/exec.rb +26 -0
  99. data/lib/poolparty/pool/resources/file.rb +23 -0
  100. data/lib/poolparty/pool/resources/gem.rb +14 -0
  101. data/lib/poolparty/pool/resources/host.rb +14 -0
  102. data/lib/poolparty/pool/resources/package.rb +14 -0
  103. data/lib/poolparty/pool/resources/remote_file.rb +22 -0
  104. data/lib/poolparty/pool/resources/service.rb +21 -0
  105. data/lib/poolparty/pool/resources/sshkey.rb +19 -0
  106. data/lib/poolparty/pool/resources/variable.rb +27 -0
  107. data/lib/poolparty/pool/script.rb +44 -0
  108. data/lib/poolparty/templates/authkeys +2 -0
  109. data/{config/monit/nginx.monit.conf → lib/poolparty/templates/cib.xml} +0 -0
  110. data/lib/poolparty/templates/fileserver.conf +4 -0
  111. data/lib/poolparty/templates/gem +25 -0
  112. data/{config/heartbeat.conf → lib/poolparty/templates/ha.cf} +3 -2
  113. data/{config → lib/poolparty/templates}/haproxy.conf +13 -6
  114. data/lib/poolparty/templates/namespaceauth.conf +19 -0
  115. data/lib/poolparty/templates/puppet.conf +17 -0
  116. data/lib/poolparty/version.rb +9 -0
  117. data/lib/poolpartycl.rb +3 -0
  118. data/poolparty.gemspec +56 -47
  119. data/script/destroy +14 -0
  120. data/script/generate +14 -0
  121. data/script/txt2html +82 -0
  122. data/setup.rb +1585 -0
  123. data/spec/poolparty/base_packages/haproxy_spec.rb +13 -0
  124. data/spec/poolparty/base_packages/heartbeat_spec.rb +30 -0
  125. data/spec/poolparty/bin/console_spec.rb +80 -0
  126. data/spec/poolparty/core/array_spec.rb +26 -0
  127. data/spec/poolparty/core/float.rb +13 -0
  128. data/spec/poolparty/core/hash_spec.rb +63 -0
  129. data/spec/poolparty/core/kernel_spec.rb +24 -0
  130. data/spec/poolparty/core/module_spec.rb +15 -0
  131. data/spec/poolparty/core/object_spec.rb +40 -0
  132. data/spec/poolparty/core/string_spec.rb +152 -0
  133. data/spec/poolparty/core/time_spec.rb +52 -0
  134. data/spec/poolparty/helpers/binary_spec.rb +26 -0
  135. data/spec/poolparty/helpers/display_spec.rb +13 -0
  136. data/spec/poolparty/helpers/optioner_spec.rb +39 -0
  137. data/spec/poolparty/helpers/provisioner_base_spec.rb +121 -0
  138. data/spec/poolparty/helpers/provisioners/master_spec.rb +54 -0
  139. data/spec/poolparty/helpers/provisioners/slave_spec.rb +28 -0
  140. data/spec/poolparty/modules/cloud_resourcer_spec.rb +135 -0
  141. data/spec/poolparty/modules/configurable_spec.rb +26 -0
  142. data/spec/poolparty/modules/definable_resource.rb +9 -0
  143. data/spec/poolparty/modules/file_writer_spec.rb +49 -0
  144. data/spec/poolparty/modules/s3_string_spec.rb +15 -0
  145. data/spec/poolparty/modules/tmp/willy/nilly.rb +1 -0
  146. data/spec/poolparty/net/remote_bases/ec2_spec.rb +92 -0
  147. data/spec/poolparty/net/remote_instance_spec.rb +70 -0
  148. data/spec/poolparty/net/remote_spec.rb +286 -0
  149. data/spec/poolparty/net/remoter_base_spec.rb +80 -0
  150. data/spec/poolparty/net/remoter_spec.rb +191 -0
  151. data/spec/poolparty/plugins/git_spec.rb +33 -0
  152. data/spec/poolparty/plugins/line_spec.rb +16 -0
  153. data/spec/poolparty/plugins/svn_spec.rb +16 -0
  154. data/spec/poolparty/pool/base_spec.rb +108 -0
  155. data/spec/poolparty/pool/cloud_spec.rb +299 -0
  156. data/spec/poolparty/pool/configurers/files/ruby_basic.rb +17 -0
  157. data/spec/poolparty/pool/configurers/files/ruby_plugins.rb +16 -0
  158. data/spec/poolparty/pool/configurers/ruby_spec.rb +58 -0
  159. data/spec/poolparty/pool/custom_resource_spec.rb +115 -0
  160. data/spec/poolparty/pool/example_spec.rb +112 -0
  161. data/spec/poolparty/pool/plugin_model_spec.rb +63 -0
  162. data/spec/poolparty/pool/plugin_spec.rb +85 -0
  163. data/spec/poolparty/pool/pool_spec.rb +83 -0
  164. data/spec/poolparty/pool/resource_spec.rb +224 -0
  165. data/spec/poolparty/pool/resources/class_package_spec.rb +84 -0
  166. data/spec/poolparty/pool/resources/conditional_spec.rb +38 -0
  167. data/spec/poolparty/pool/resources/cron_spec.rb +49 -0
  168. data/spec/poolparty/pool/resources/directory_spec.rb +40 -0
  169. data/spec/poolparty/pool/resources/exec_spec.rb +37 -0
  170. data/spec/poolparty/pool/resources/file_spec.rb +40 -0
  171. data/spec/poolparty/pool/resources/gem_spec.rb +16 -0
  172. data/spec/poolparty/pool/resources/host_spec.rb +28 -0
  173. data/spec/poolparty/pool/resources/package_spec.rb +44 -0
  174. data/spec/poolparty/pool/resources/remote_file_spec.rb +40 -0
  175. data/spec/poolparty/pool/resources/service_spec.rb +45 -0
  176. data/spec/poolparty/pool/resources/sshkey_spec.rb +48 -0
  177. data/spec/poolparty/pool/resources/variable_spec.rb +20 -0
  178. data/spec/poolparty/pool/script_spec.rb +51 -0
  179. data/spec/poolparty/pool/test_plugins/sshkey_test +2 -0
  180. data/{test/test_pool_party.rb → spec/poolparty/pool/test_plugins/virtual_host_template.erb} +0 -0
  181. data/spec/poolparty/pool/test_plugins/webserver.rb +46 -0
  182. data/spec/poolparty/poolparty_spec.rb +33 -0
  183. data/spec/poolparty/spec_helper.rb +120 -0
  184. data/tasks/cloud.rake +57 -0
  185. data/tasks/deployment.rake +34 -0
  186. data/tasks/development.rake +78 -0
  187. data/tasks/ec2.rake +20 -0
  188. data/tasks/environment.rake +7 -0
  189. data/tasks/instance.rake +63 -0
  190. data/tasks/server.rake +42 -0
  191. data/tasks/spec.rake +17 -0
  192. data/tasks/website.rake +17 -0
  193. data/test/test_generator_helper.rb +29 -0
  194. data/test/test_helper.rb +2 -0
  195. data/test/test_pool_spec_generator.rb +47 -0
  196. data/test/test_poolparty.rb +11 -0
  197. data/test_manifest.pp +538 -0
  198. data/website/index.html +107 -0
  199. data/website/index.txt +95 -0
  200. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  201. data/website/stylesheets/code.css +29 -0
  202. data/website/stylesheets/screen.css +147 -0
  203. data/website/template.html.erb +49 -0
  204. metadata +282 -101
  205. data/CHANGELOG +0 -4
  206. data/Manifest +0 -55
  207. data/bin/instance +0 -54
  208. data/config/config.yml +0 -23
  209. data/config/create_proxy_ami.sh +0 -582
  210. data/config/heartbeat_authkeys.conf +0 -2
  211. data/config/monit.conf +0 -8
  212. data/config/monit/haproxy.monit.conf +0 -7
  213. data/config/nginx.conf +0 -24
  214. data/lib/core/array.rb +0 -10
  215. data/lib/core/kernel.rb +0 -9
  216. data/lib/core/object.rb +0 -14
  217. data/lib/modules/callback.rb +0 -55
  218. data/lib/modules/ec2_wrapper.rb +0 -74
  219. data/lib/pool_party.rb +0 -69
  220. data/lib/pool_party/application.rb +0 -133
  221. data/lib/pool_party/init.rb +0 -4
  222. data/lib/pool_party/master.rb +0 -189
  223. data/lib/pool_party/monitors.rb +0 -13
  224. data/lib/pool_party/monitors/cpu.rb +0 -18
  225. data/lib/pool_party/monitors/memory.rb +0 -21
  226. data/lib/pool_party/monitors/web.rb +0 -18
  227. data/lib/pool_party/optioner.rb +0 -16
  228. data/lib/pool_party/os.rb +0 -11
  229. data/lib/pool_party/os/ubuntu.rb +0 -78
  230. data/lib/pool_party/remote_instance.rb +0 -180
  231. data/lib/pool_party/remoting.rb +0 -112
  232. data/lib/pool_party/scheduler.rb +0 -93
  233. data/lib/pool_party/tasks.rb +0 -220
  234. data/lib/s3/s3_object_store_folders.rb +0 -44
  235. data/spec/application_spec.rb +0 -32
  236. data/spec/callback_spec.rb +0 -65
  237. data/spec/helpers/ec2_mock.rb +0 -56
  238. data/spec/helpers/remote_instance_mock.rb +0 -11
  239. data/spec/kernel_spec.rb +0 -11
  240. data/spec/master_spec.rb +0 -147
  241. data/spec/monitor_spec.rb +0 -16
  242. data/spec/optioner_spec.rb +0 -22
  243. data/spec/poolparty_spec.rb +0 -8
  244. data/spec/remote_instance_spec.rb +0 -29
  245. data/spec/remoting_spec.rb +0 -75
  246. data/spec/spec_helper.rb +0 -38
  247. data/spec/string_spec.rb +0 -28
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "haproxy base package" do
4
+ before(:each) do
5
+ @ha = PoolPartyHaproxyClass.new do
6
+ end
7
+ stub_list_from_remote_for(@ha)
8
+ @ha.stub!(:list_of_running_instances).and_return []
9
+ end
10
+ it "should have the heartbeat package defined" do
11
+ lambda {PoolPartyHaproxyClass}.should_not raise_error
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "heartbeat base package" do
4
+ # before(:each) do
5
+ # @cloud = Cloud.new(:app, self)
6
+ # @hb = PoolPartyHeartbeatClass.new(@cloud)
7
+ # stub_list_from_remote_for(@cloud)
8
+ # stub_list_of_instances_for(@cloud)
9
+ # end
10
+ # it "should have the heartbeat package defined" do
11
+ # lambda {PoolPartyHeartbeatClass}.should_not raise_error
12
+ # end
13
+ # it "should have a parent set to the cloud" do
14
+ # @hb.parent.should == @cloud
15
+ # end
16
+ # it "should call enable (and setup resources) since there is no block given when it's instantiated" do
17
+ # @hb.resources.should_not be_empty
18
+ # end
19
+ # it "should have no resources when starting with a block (that defines no methods)" do
20
+ # @pphc = PoolPartyHeartbeatClass.new do
21
+ # end
22
+ # @pphc.resources.should be_empty
23
+ # end
24
+ # it "should have a file resource" do
25
+ # @hb.resource(:remotefile).should_not be_empty
26
+ # end
27
+ # it "should have at least 3 remotefiles" do
28
+ # @hb.resource(:remotefile).size.should >= 3
29
+ # end
30
+ end
@@ -0,0 +1,80 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/../../../lib/poolparty/helpers/console'
3
+
4
+ describe "Console" do
5
+ before(:each) do
6
+ ::File.stub!(:file?).with("pop").and_return true
7
+ end
8
+ describe "load_pool" do
9
+ before(:each) do
10
+ reset!
11
+ @string =<<-EOS
12
+ pool :app do
13
+ maximum_instances 2
14
+ cloud :rawr do
15
+ end
16
+ end
17
+ EOS
18
+ self.stub!(:open).and_return @string
19
+ @string.stub!(:read).and_return @string
20
+ end
21
+ it "should give you the load_pool method" do
22
+ self.respond_to?(:load_pool).should == true
23
+ end
24
+ it "should call script inflate on the filename" do
25
+ PoolParty::Script.should_receive(:inflate).once
26
+ load_pool("pop")
27
+ end
28
+ describe "calling" do
29
+ before(:each) do
30
+ reset!
31
+ load_pool("pop")
32
+ end
33
+ it "should instance_eval the string" do
34
+ pool(:app).should_not be_nil
35
+ end
36
+ it "should store the cloud inside the pool after inflating" do
37
+ pool(:app).cloud(:rawr).should_not be_nil
38
+ end
39
+ it "should say that the cloud inside the pool's parent is the containing parent" do
40
+ pool(:app).cloud(:rawr).parent.should == pool(:app)
41
+ end
42
+ it "should say that the maximum_instances on the cloud is the containing pool's option" do
43
+ pool(:app).cloud(:rawr).maximum_instances.should == 2
44
+ end
45
+ end
46
+ end
47
+ describe "reload!" do
48
+ before(:each) do
49
+ reset!
50
+ self.stub!(:require).and_return true
51
+ end
52
+ it "should call reset!" do
53
+ self.should_receive(:reset!).once
54
+ end
55
+ after do
56
+ reload!
57
+ end
58
+ end
59
+ describe "print" do
60
+ before(:each) do
61
+ reset!
62
+ @string =<<-EOS
63
+ pool :app do
64
+ maximum_instances 2
65
+ cloud :rawr do
66
+ end
67
+ end
68
+ EOS
69
+ self.stub!(:open).and_return @string
70
+ @string.stub!(:read).and_return @string
71
+ load_pool("pop")
72
+ end
73
+ it "should be able to print the clouds" do
74
+ pools.should_not be_empty
75
+ hide_output do
76
+ pool_describe.should == pools.size
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Array" do
4
+ before(:each) do
5
+ @array = ["run this", "run that"]
6
+ end
7
+ describe "runnable" do
8
+ it "should be able to produced a runnable string" do;@array.runnable.should == 'run this && run that';end
9
+ it "should be turn into a string" do;@array.runnable.class.should == String;end
10
+ end
11
+ describe "nice_runnable" do
12
+ before(:each) do
13
+ @array << ""
14
+ @array << "peabody"
15
+ end
16
+ it "should reject any empty elements out of the array" do
17
+ (@array << [""]).nice_runnable.should == "run this \n run that \n peabody"
18
+ end
19
+ end
20
+ describe "to_os" do
21
+ it "should be able to turn itself to an open struct" do; @array.first.should_receive(:to_os);end
22
+ after do
23
+ @array.to_os
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Float" do
4
+ it "should be able to round to the nearest integer" do
5
+ 10.95.round_to(1).should == 11
6
+ end
7
+ it "should be able to get the ceiling" do
8
+ 10.54.ceil_to(1).should == 10.6
9
+ end
10
+ it "should be able to get the floor" do
11
+ 10.14.floor_to(1).should == 10.1
12
+ end
13
+ end
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Hash" do
4
+ before(:each) do
5
+ @a = {:a => "10", :b => "20", :c => "30"}
6
+ end
7
+ it "should preserve the contents of the original hash when safe_merge'ing" do
8
+ a = {:a => "10", :b => "20"}
9
+ b = {:b => "30", :c => "40"}
10
+ a.safe_merge(b).should == {:a => "10", :b => "20", :c => "40"}
11
+ end
12
+ it "should preserve the contents of the original hash when safe_merge!'ing" do
13
+ a = {:a => "10", :b => "20"}
14
+ b = {:b => "30", :c => "40"}
15
+ a.safe_merge!(b)
16
+ a.should == {:a => "10", :b => "20", :c => "40"}
17
+ end
18
+ it "should be able to turn itself into an open struct" do
19
+ @a.to_os.class.should == MyOpenStruct
20
+ end
21
+ it "should respond to to_hash" do
22
+ @a.to_os.respond_to?(:to_hash).should == true
23
+ end
24
+ it "should be able to turn itself into an open struct with the method to_hash on the object" do
25
+ @a.to_os.to_hash.should == @a
26
+ end
27
+ it "should not put quotes around integers" do
28
+ {:a => 10, :b => "q"}.flush_out.should == ["a => 10", "b => 'q'"]
29
+ end
30
+ it "should be able to flush out into a string into an array" do
31
+ @a.flush_out.should == ["a => '10'","b => '20'","c => '30'"]
32
+ end
33
+ it "should be able to flush out with prev and posts" do
34
+ @a.flush_out("hi", "ho").should == ["hia => '10'ho","hib => '20'ho","hic => '30'ho"]
35
+ end
36
+ describe "select" do
37
+ before(:each) do
38
+ @selected_hash = @a.select {|k,v| k if k == :a}
39
+ end
40
+ it "should return a hash when selecting" do
41
+ @selected_hash.class.should == Hash
42
+ end
43
+ it "should only have the key a (selected)" do
44
+ @selected_hash.keys.should == [:a]
45
+ end
46
+ end
47
+ describe "extract!" do
48
+ before(:each) do
49
+ @rejected_hash = @a.extract! {|k,v| k == :a }
50
+ end
51
+ it "should have a reject with the keys" do
52
+ @rejected_hash.keys.should == [:a]
53
+ end
54
+ it "should return the old array with the other keys" do
55
+ @a.keys.should == [:b, :c]
56
+ end
57
+ it "should not throw a fit with an empty hash" do
58
+ lambda {
59
+ {}.extract!
60
+ }.should_not raise_error
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Kernel extensions" do
4
+ before(:each) do
5
+ @obj = Object.new
6
+ end
7
+ it "should eval the string into time" do
8
+ @obj.should_receive(:sleep).once.with(10.seconds).and_return true
9
+ @obj.wait "10.seconds"
10
+ end
11
+ end
12
+ describe "Object extensions" do
13
+ before(:each) do
14
+ @klass = Object.new
15
+ @klass.instance_eval <<-EOE
16
+ def hello
17
+ puts "hello"
18
+ end
19
+ EOE
20
+ end
21
+ it "should be able to get a list of the defined methods on the object" do
22
+ @klass.my_methods.should == ["hello"]
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Module" do
4
+ before(:each) do
5
+ @mod = Module.new do
6
+ attr_accessor_with_default :a do
7
+ Hash.new
8
+ end
9
+ end
10
+ @klass = Class.new.extend(@mod)
11
+ end
12
+ it "should be able to set method accessors" do
13
+ @klass.a.should == {}
14
+ end
15
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Object" do
4
+ it "should respond to to_os" do
5
+ Object.new.respond_to?(:to_os).should == true
6
+ end
7
+ describe "with_options" do
8
+ before(:each) do
9
+ @obj = Class.new
10
+ end
11
+ it "should respond to with_options" do
12
+ @obj.respond_to?(:with_options).should == true
13
+ end
14
+ it "should set the options on the parent" do
15
+ allow_message_expectations_on_nil
16
+ @a.should_receive(:clone).and_return @a
17
+ @a.stub!(:options).and_return({})
18
+ with_options({:nick => "name"}, @a) do
19
+ end
20
+ end
21
+
22
+ describe "running" do
23
+ before(:each) do
24
+ Class.stub!(:default_options).and_return({})
25
+ Class.send :include, Configurable
26
+ Class.send :include, MethodMissingSugar
27
+ @a = Class.new
28
+ @b = Class.new
29
+
30
+ with_options({:nick => "name", :b => @b}, @a) do
31
+ b.dude "totally"
32
+ end
33
+
34
+ end
35
+ it "should set the options on the child in the instance eval" do
36
+ @b.dude.should == "totally"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,152 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "String" do
4
+ describe "hasherize" do
5
+ before(:each) do
6
+ @str=<<-EOE
7
+ hello world
8
+ you are my
9
+ hero
10
+ EOE
11
+ @hashed = @str.hasherize(%w(hello you))
12
+ end
13
+ it "should return a hash from the string" do
14
+ @hashed.class.should == Hash
15
+ end
16
+ it "should have hello as a key" do
17
+ @hashed.has_key?(:hello).should == true
18
+ end
19
+ describe "arrayable" do
20
+ it "should be able to turn the string into an array" do
21
+ @str.arrayable.class.should == Array
22
+ end
23
+ end
24
+ end
25
+ before(:each) do
26
+ @string = "string"
27
+ @string.stub!(:bucket_objects).and_return([])
28
+ end
29
+ # Dumb test
30
+ it "should be able to call bucket_objects on itself" do
31
+ @string.should_receive(:bucket_objects)
32
+ @string.bucket_objects
33
+ end
34
+ describe "with config replacements" do
35
+ it "should replace those syms in the string" do
36
+ ("new :port" ^ {:port => 100}).should == "new 100"
37
+ end
38
+ it "should be able to detect vars" do
39
+ @string=<<-EOC
40
+ listen web_proxy 127.0.0.1::client_port
41
+ \tserver web1 127.0.0.1::port weight 1 minconn 3 maxconn 6 check inter 30000
42
+ EOC
43
+ (@string ^ {:client_port => 3000, :port => 3001}).should ==<<-EOO
44
+ listen web_proxy 127.0.0.1:3000
45
+ \tserver web1 127.0.0.1:3001 weight 1 minconn 3 maxconn 6 check inter 30000
46
+ EOO
47
+ end
48
+ end
49
+ describe "collect_each_line_with_index" do
50
+ before(:each) do
51
+ @longer_string = "hot\npotato\nthrough\nthe\nwindow"
52
+ end
53
+ it "should run the same code on the entire string" do
54
+ @longer_string.collect_each_line_with_index do |str, index|
55
+ "#{index}_#{str}"
56
+ end.should == ["0_hot", "1_potato", "2_through", "3_the", "4_window"]
57
+ end
58
+ end
59
+ describe "String" do
60
+ before(:each) do
61
+ @str =<<-EOS
62
+ echo 'hi'
63
+ puts 'hi'
64
+ EOS
65
+ end
66
+ it "should be able to convert a big string with \n to a runnable string" do
67
+ @str.runnable.should == "echo 'hi' && puts 'hi'"
68
+ end
69
+ end
70
+ describe "Constantize" do
71
+ before(:each) do
72
+ @str = "prok"
73
+ end
74
+ it "should be able to turn itself into constant" do
75
+ @str.class_constant.should == PoolPartyProkClass
76
+ end
77
+ it "should turn itself into a class constant" do
78
+ @str.class_constant.class.should == Class
79
+ end
80
+ it "should not recreate the constant if it exists" do
81
+ Class.should_receive(:new).once.and_return Class.new
82
+ @str.class_constant
83
+ @str.class_constant
84
+ end
85
+ it "should set the parent class when sent with the superclass" do
86
+ "stirer".class_constant(String).ancestors[1].should == String
87
+ end
88
+ it "should be able to create a module into a constant" do
89
+ @str.module_constant.should == ProkModule
90
+ end
91
+ it "should turn itself into a class constant" do
92
+ @str.module_constant.class.should == Module
93
+ end
94
+ it "should create the module on preserved module constant" do
95
+ Module.should_receive(:new).once
96
+ @str.preserved_module_constant.should == Prok
97
+ @str.preserved_module_constant
98
+ @str.preserved_module_constant
99
+ end
100
+ describe "with a block" do
101
+ before(:each) do
102
+ @str = "nack"
103
+ end
104
+ it "should be able to yield a block on the module and set methods" do
105
+ "tippy".module_constant do
106
+ def tippy
107
+ puts "etc"
108
+ end
109
+ end
110
+ Class.new.extend("tippy".module_constant).methods.include?("tippy").should == true
111
+ end
112
+ end
113
+ end
114
+ describe "top level class" do
115
+ it "should be able to get the top level class" do
116
+ "PoolParty::Resources::File".top_level_class.should == "file"
117
+ end
118
+ end
119
+ describe "to_option_string" do
120
+ it "should not touch a string, but return the string with single quotes" do
121
+ "rocks".to_option_string.should == "'rocks'"
122
+ end
123
+ it "should return a string of the format Service[nagios] with no single quotes" do
124
+ "Service[nagios]".to_option_string.should == "Service[nagios]"
125
+ end
126
+ it "should also return a string if there is a string within the string" do
127
+ 'Package["heartbeat-2"]'.to_option_string.should == 'Package["heartbeat-2"]'
128
+ end
129
+ it "should return File['/etc/apache2/conf.d/base.conf'] as a string" do
130
+ 'File["/etc/apache2/conf.d/base.conf"]'.to_option_string.should == "File[\"/etc/apache2/conf.d/base.conf\"]"
131
+ end
132
+ end
133
+ describe "sanitize" do
134
+ it "should remove the periods from the string" do
135
+ "xnot.org".sanitize.should == "xnotorg"
136
+ end
137
+ end
138
+ describe "nice_runnable" do
139
+ before(:each) do
140
+ @tasks = ["ls -l", "echo 'hello'"]
141
+ end
142
+ it "should turn an array into a string" do
143
+ @tasks.nice_runnable.class.should == String
144
+ end
145
+ it "should add \\n between the commands" do
146
+ @tasks.nice_runnable.should == "ls -l \n echo 'hello'"
147
+ end
148
+ it "should strip out excess lines" do
149
+ (@tasks << []).nice_runnable.should == "ls -l \n echo 'hello'"
150
+ end
151
+ end
152
+ end