puppet-module 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. data/CHANGES.markdown +91 -0
  2. data/LICENSE +17 -0
  3. data/README.markdown +221 -0
  4. data/Rakefile +87 -0
  5. data/VERSION +1 -0
  6. data/bin/puppet-module +7 -0
  7. data/lib/puppet/module/tool.rb +124 -0
  8. data/lib/puppet/module/tool/applications.rb +18 -0
  9. data/lib/puppet/module/tool/applications/application.rb +83 -0
  10. data/lib/puppet/module/tool/applications/builder.rb +88 -0
  11. data/lib/puppet/module/tool/applications/checksummer.rb +38 -0
  12. data/lib/puppet/module/tool/applications/cleaner.rb +14 -0
  13. data/lib/puppet/module/tool/applications/freezer.rb +20 -0
  14. data/lib/puppet/module/tool/applications/generator.rb +117 -0
  15. data/lib/puppet/module/tool/applications/installer.rb +83 -0
  16. data/lib/puppet/module/tool/applications/registrar.rb +34 -0
  17. data/lib/puppet/module/tool/applications/releaser.rb +48 -0
  18. data/lib/puppet/module/tool/applications/searcher.rb +34 -0
  19. data/lib/puppet/module/tool/applications/unpacker.rb +69 -0
  20. data/lib/puppet/module/tool/applications/unreleaser.rb +42 -0
  21. data/lib/puppet/module/tool/cache.rb +56 -0
  22. data/lib/puppet/module/tool/checksums.rb +52 -0
  23. data/lib/puppet/module/tool/cli.rb +127 -0
  24. data/lib/puppet/module/tool/contents_description.rb +84 -0
  25. data/lib/puppet/module/tool/dependency.rb +26 -0
  26. data/lib/puppet/module/tool/metadata.rb +80 -0
  27. data/lib/puppet/module/tool/modulefile.rb +47 -0
  28. data/lib/puppet/module/tool/repository.rb +74 -0
  29. data/lib/puppet/module/tool/skeleton.rb +39 -0
  30. data/lib/puppet/module/tool/utils.rb +9 -0
  31. data/lib/puppet/module/tool/utils/interrogation.rb +39 -0
  32. data/lib/puppet/module/tool/utils/settings.rb +36 -0
  33. data/lib/puppet/module/tool/utils/uri.rb +16 -0
  34. data/spec/fixtures/releases/jamtur01-apache/Modulefile +2 -0
  35. data/spec/fixtures/releases/jamtur01-apache/files/httpd +24 -0
  36. data/spec/fixtures/releases/jamtur01-apache/files/test.vhost +18 -0
  37. data/spec/fixtures/releases/jamtur01-apache/lib/puppet/provider/a2mod/debian.rb +21 -0
  38. data/spec/fixtures/releases/jamtur01-apache/lib/puppet/type/a2mod.rb +12 -0
  39. data/spec/fixtures/releases/jamtur01-apache/manifests/dev.pp +5 -0
  40. data/spec/fixtures/releases/jamtur01-apache/manifests/init.pp +34 -0
  41. data/spec/fixtures/releases/jamtur01-apache/manifests/params.pp +17 -0
  42. data/spec/fixtures/releases/jamtur01-apache/manifests/php.pp +5 -0
  43. data/spec/fixtures/releases/jamtur01-apache/manifests/ssl.pp +15 -0
  44. data/spec/fixtures/releases/jamtur01-apache/manifests/vhost.pp +15 -0
  45. data/spec/fixtures/releases/jamtur01-apache/metadata.json +1 -0
  46. data/spec/fixtures/releases/jamtur01-apache/templates/vhost-default.conf.erb +20 -0
  47. data/spec/fixtures/releases/jamtur01-apache/tests/apache.pp +1 -0
  48. data/spec/fixtures/releases/jamtur01-apache/tests/dev.pp +1 -0
  49. data/spec/fixtures/releases/jamtur01-apache/tests/init.pp +1 -0
  50. data/spec/fixtures/releases/jamtur01-apache/tests/php.pp +1 -0
  51. data/spec/fixtures/releases/jamtur01-apache/tests/ssl.pp +1 -0
  52. data/spec/fixtures/releases/jamtur01-apache/tests/vhost.pp +2 -0
  53. data/spec/integration/cli_spec.rb +373 -0
  54. data/spec/spec.opts +1 -0
  55. data/spec/spec_helper.rb +15 -0
  56. data/spec/support/output_support.rb +19 -0
  57. data/spec/support/stub_http_support.rb +14 -0
  58. data/spec/support/testdir_support.rb +26 -0
  59. data/spec/unit/application_spec.rb +25 -0
  60. data/spec/unit/repository_spec.rb +51 -0
  61. data/templates/generator/Modulefile.erb +5 -0
  62. data/templates/generator/README.erb +3 -0
  63. data/templates/generator/files/README.markdown +22 -0
  64. data/templates/generator/lib/puppet/facter/README.markdown +22 -0
  65. data/templates/generator/lib/puppet/parser/functions/README.markdown +17 -0
  66. data/templates/generator/lib/puppet/provider/README.markdown +14 -0
  67. data/templates/generator/lib/puppet/type/README.markdown +14 -0
  68. data/templates/generator/manifests/README.markdown +28 -0
  69. data/templates/generator/manifests/init.pp.erb +17 -0
  70. data/templates/generator/metadata.json +12 -0
  71. data/templates/generator/spec/README.markdown +7 -0
  72. data/templates/generator/spec/spec.opts +6 -0
  73. data/templates/generator/spec/spec_helper.rb +18 -0
  74. data/templates/generator/spec/unit/puppet/provider/README.markdown +4 -0
  75. data/templates/generator/spec/unit/puppet/type/README.markdown +4 -0
  76. data/templates/generator/templates/README.markdown +23 -0
  77. data/templates/generator/tests/init.pp.erb +1 -0
  78. data/vendor/facets-2.8.2-partial/lib/facets/kernel/returning.rb +23 -0
  79. data/vendor/facets-2.8.2-partial/lib/facets/kernel/tap.rb +39 -0
  80. data/vendor/multipart-post-1.0/Manifest.txt +9 -0
  81. data/vendor/multipart-post-1.0/README.txt +61 -0
  82. data/vendor/multipart-post-1.0/Rakefile +21 -0
  83. data/vendor/multipart-post-1.0/lib/composite_io.rb +89 -0
  84. data/vendor/multipart-post-1.0/lib/multipartable.rb +13 -0
  85. data/vendor/multipart-post-1.0/lib/net/http/post/multipart.rb +27 -0
  86. data/vendor/multipart-post-1.0/lib/parts.rb +66 -0
  87. data/vendor/multipart-post-1.0/test/net/http/post/test_multipart.rb +55 -0
  88. data/vendor/multipart-post-1.0/test/test_composite_io.rb +50 -0
  89. data/vendor/thor-852190ae/CHANGELOG.rdoc +89 -0
  90. data/vendor/thor-852190ae/LICENSE +20 -0
  91. data/vendor/thor-852190ae/README.rdoc +297 -0
  92. data/vendor/thor-852190ae/REVISION +1 -0
  93. data/vendor/thor-852190ae/Thorfile +69 -0
  94. data/vendor/thor-852190ae/bin/rake2thor +86 -0
  95. data/vendor/thor-852190ae/bin/thor +6 -0
  96. data/vendor/thor-852190ae/lib/thor.rb +244 -0
  97. data/vendor/thor-852190ae/lib/thor/actions.rb +275 -0
  98. data/vendor/thor-852190ae/lib/thor/actions/create_file.rb +103 -0
  99. data/vendor/thor-852190ae/lib/thor/actions/directory.rb +91 -0
  100. data/vendor/thor-852190ae/lib/thor/actions/empty_directory.rb +134 -0
  101. data/vendor/thor-852190ae/lib/thor/actions/file_manipulation.rb +223 -0
  102. data/vendor/thor-852190ae/lib/thor/actions/inject_into_file.rb +104 -0
  103. data/vendor/thor-852190ae/lib/thor/base.rb +540 -0
  104. data/vendor/thor-852190ae/lib/thor/core_ext/file_binary_read.rb +9 -0
  105. data/vendor/thor-852190ae/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  106. data/vendor/thor-852190ae/lib/thor/core_ext/ordered_hash.rb +100 -0
  107. data/vendor/thor-852190ae/lib/thor/error.rb +30 -0
  108. data/vendor/thor-852190ae/lib/thor/group.rb +271 -0
  109. data/vendor/thor-852190ae/lib/thor/invocation.rb +180 -0
  110. data/vendor/thor-852190ae/lib/thor/parser.rb +4 -0
  111. data/vendor/thor-852190ae/lib/thor/parser/argument.rb +67 -0
  112. data/vendor/thor-852190ae/lib/thor/parser/arguments.rb +150 -0
  113. data/vendor/thor-852190ae/lib/thor/parser/option.rb +128 -0
  114. data/vendor/thor-852190ae/lib/thor/parser/options.rb +169 -0
  115. data/vendor/thor-852190ae/lib/thor/rake_compat.rb +66 -0
  116. data/vendor/thor-852190ae/lib/thor/runner.rb +314 -0
  117. data/vendor/thor-852190ae/lib/thor/shell.rb +83 -0
  118. data/vendor/thor-852190ae/lib/thor/shell/basic.rb +239 -0
  119. data/vendor/thor-852190ae/lib/thor/shell/color.rb +108 -0
  120. data/vendor/thor-852190ae/lib/thor/task.rb +102 -0
  121. data/vendor/thor-852190ae/lib/thor/util.rb +230 -0
  122. data/vendor/thor-852190ae/lib/thor/version.rb +3 -0
  123. data/vendor/thor-852190ae/spec/actions/create_file_spec.rb +170 -0
  124. data/vendor/thor-852190ae/spec/actions/directory_spec.rb +131 -0
  125. data/vendor/thor-852190ae/spec/actions/empty_directory_spec.rb +91 -0
  126. data/vendor/thor-852190ae/spec/actions/file_manipulation_spec.rb +271 -0
  127. data/vendor/thor-852190ae/spec/actions/inject_into_file_spec.rb +135 -0
  128. data/vendor/thor-852190ae/spec/actions_spec.rb +292 -0
  129. data/vendor/thor-852190ae/spec/base_spec.rb +263 -0
  130. data/vendor/thor-852190ae/spec/core_ext/hash_with_indifferent_access_spec.rb +43 -0
  131. data/vendor/thor-852190ae/spec/core_ext/ordered_hash_spec.rb +115 -0
  132. data/vendor/thor-852190ae/spec/fixtures/application.rb +2 -0
  133. data/vendor/thor-852190ae/spec/fixtures/bundle/execute.rb +6 -0
  134. data/vendor/thor-852190ae/spec/fixtures/bundle/main.thor +1 -0
  135. data/vendor/thor-852190ae/spec/fixtures/doc/%file_name%.rb.tt +1 -0
  136. data/vendor/thor-852190ae/spec/fixtures/doc/README +3 -0
  137. data/vendor/thor-852190ae/spec/fixtures/doc/config.rb +1 -0
  138. data/vendor/thor-852190ae/spec/fixtures/group.thor +83 -0
  139. data/vendor/thor-852190ae/spec/fixtures/invoke.thor +112 -0
  140. data/vendor/thor-852190ae/spec/fixtures/script.thor +140 -0
  141. data/vendor/thor-852190ae/spec/fixtures/task.thor +10 -0
  142. data/vendor/thor-852190ae/spec/group_spec.rb +171 -0
  143. data/vendor/thor-852190ae/spec/invocation_spec.rb +107 -0
  144. data/vendor/thor-852190ae/spec/parser/argument_spec.rb +47 -0
  145. data/vendor/thor-852190ae/spec/parser/arguments_spec.rb +64 -0
  146. data/vendor/thor-852190ae/spec/parser/option_spec.rb +202 -0
  147. data/vendor/thor-852190ae/spec/parser/options_spec.rb +292 -0
  148. data/vendor/thor-852190ae/spec/rake_compat_spec.rb +68 -0
  149. data/vendor/thor-852190ae/spec/runner_spec.rb +202 -0
  150. data/vendor/thor-852190ae/spec/shell/basic_spec.rb +205 -0
  151. data/vendor/thor-852190ae/spec/shell/color_spec.rb +41 -0
  152. data/vendor/thor-852190ae/spec/shell_spec.rb +34 -0
  153. data/vendor/thor-852190ae/spec/spec.opts +1 -0
  154. data/vendor/thor-852190ae/spec/spec_helper.rb +54 -0
  155. data/vendor/thor-852190ae/spec/task_spec.rb +69 -0
  156. data/vendor/thor-852190ae/spec/thor_spec.rb +237 -0
  157. data/vendor/thor-852190ae/spec/util_spec.rb +167 -0
  158. data/vendor/thor-852190ae/thor.gemspec +120 -0
  159. metadata +229 -0
@@ -0,0 +1,230 @@
1
+ require 'rbconfig'
2
+
3
+ class Thor
4
+ module Sandbox #:nodoc:
5
+ end
6
+
7
+ # This module holds several utilities:
8
+ #
9
+ # 1) Methods to convert thor namespaces to constants and vice-versa.
10
+ #
11
+ # Thor::Utils.namespace_from_thor_class(Foo::Bar::Baz) #=> "foo:bar:baz"
12
+ #
13
+ # 2) Loading thor files and sandboxing:
14
+ #
15
+ # Thor::Utils.load_thorfile("~/.thor/foo")
16
+ #
17
+ module Util
18
+
19
+ # Receives a namespace and search for it in the Thor::Base subclasses.
20
+ #
21
+ # ==== Parameters
22
+ # namespace<String>:: The namespace to search for.
23
+ #
24
+ def self.find_by_namespace(namespace)
25
+ namespace = "default#{namespace}" if namespace.empty? || namespace =~ /^:/
26
+ Thor::Base.subclasses.find { |klass| klass.namespace == namespace }
27
+ end
28
+
29
+ # Receives a constant and converts it to a Thor namespace. Since Thor tasks
30
+ # can be added to a sandbox, this method is also responsable for removing
31
+ # the sandbox namespace.
32
+ #
33
+ # This method should not be used in general because it's used to deal with
34
+ # older versions of Thor. On current versions, if you need to get the
35
+ # namespace from a class, just call namespace on it.
36
+ #
37
+ # ==== Parameters
38
+ # constant<Object>:: The constant to be converted to the thor path.
39
+ #
40
+ # ==== Returns
41
+ # String:: If we receive Foo::Bar::Baz it returns "foo:bar:baz"
42
+ #
43
+ def self.namespace_from_thor_class(constant)
44
+ constant = constant.to_s.gsub(/^Thor::Sandbox::/, "")
45
+ constant = snake_case(constant).squeeze(":")
46
+ constant
47
+ end
48
+
49
+ # Given the contents, evaluate it inside the sandbox and returns the
50
+ # namespaces defined in the sandbox.
51
+ #
52
+ # ==== Parameters
53
+ # contents<String>
54
+ #
55
+ # ==== Returns
56
+ # Array[Object]
57
+ #
58
+ def self.namespaces_in_content(contents, file=__FILE__)
59
+ old_constants = Thor::Base.subclasses.dup
60
+ Thor::Base.subclasses.clear
61
+
62
+ load_thorfile(file, contents)
63
+
64
+ new_constants = Thor::Base.subclasses.dup
65
+ Thor::Base.subclasses.replace(old_constants)
66
+
67
+ new_constants.map!{ |c| c.namespace }
68
+ new_constants.compact!
69
+ new_constants
70
+ end
71
+
72
+ # Returns the thor classes declared inside the given class.
73
+ #
74
+ def self.thor_classes_in(klass)
75
+ stringfied_constants = klass.constants.map { |c| c.to_s }
76
+ Thor::Base.subclasses.select do |subclass|
77
+ next unless subclass.name
78
+ stringfied_constants.include?(subclass.name.gsub("#{klass.name}::", ''))
79
+ end
80
+ end
81
+
82
+ # Receives a string and convert it to snake case. SnakeCase returns snake_case.
83
+ #
84
+ # ==== Parameters
85
+ # String
86
+ #
87
+ # ==== Returns
88
+ # String
89
+ #
90
+ def self.snake_case(str)
91
+ return str.downcase if str =~ /^[A-Z_]+$/
92
+ str.gsub(/\B[A-Z]/, '_\&').squeeze('_') =~ /_*(.*)/
93
+ return $+.downcase
94
+ end
95
+
96
+ # Receives a string and convert it to camel case. camel_case returns CamelCase.
97
+ #
98
+ # ==== Parameters
99
+ # String
100
+ #
101
+ # ==== Returns
102
+ # String
103
+ #
104
+ def self.camel_case(str)
105
+ return str if str !~ /_/ && str =~ /[A-Z]+.*/
106
+ str.split('_').map { |i| i.capitalize }.join
107
+ end
108
+
109
+ # Receives a namespace and tries to retrieve a Thor or Thor::Group class
110
+ # from it. It first searches for a class using the all the given namespace,
111
+ # if it's not found, removes the highest entry and searches for the class
112
+ # again. If found, returns the highest entry as the class name.
113
+ #
114
+ # ==== Examples
115
+ #
116
+ # class Foo::Bar < Thor
117
+ # def baz
118
+ # end
119
+ # end
120
+ #
121
+ # class Baz::Foo < Thor::Group
122
+ # end
123
+ #
124
+ # Thor::Util.namespace_to_thor_class("foo:bar") #=> Foo::Bar, nil # will invoke default task
125
+ # Thor::Util.namespace_to_thor_class("baz:foo") #=> Baz::Foo, nil
126
+ # Thor::Util.namespace_to_thor_class("foo:bar:baz") #=> Foo::Bar, "baz"
127
+ #
128
+ # ==== Parameters
129
+ # namespace<String>
130
+ #
131
+ def self.find_class_and_task_by_namespace(namespace)
132
+ if namespace.include?(?:)
133
+ pieces = namespace.split(":")
134
+ task = pieces.pop
135
+ klass = Thor::Util.find_by_namespace(pieces.join(":"))
136
+ end
137
+
138
+ unless klass
139
+ klass, task = Thor::Util.find_by_namespace(namespace), nil
140
+ end
141
+
142
+ return klass, task
143
+ end
144
+
145
+ # The same as namespace_to_thor_class_and_task!, but raises an error if a klass
146
+ # could not be found.
147
+ def self.find_class_and_task_by_namespace!(namespace)
148
+ klass, task = find_class_and_task_by_namespace(namespace)
149
+ raise Error, "Could not find namespace or task #{namespace.inspect}." unless klass
150
+ return klass, task
151
+ end
152
+
153
+ # Receives a path and load the thor file in the path. The file is evaluated
154
+ # inside the sandbox to avoid namespacing conflicts.
155
+ #
156
+ def self.load_thorfile(path, content=nil)
157
+ content ||= File.binread(path)
158
+
159
+ begin
160
+ Thor::Sandbox.class_eval(content, path)
161
+ rescue Exception => e
162
+ $stderr.puts "WARNING: unable to load thorfile #{path.inspect}: #{e.message}"
163
+ end
164
+ end
165
+
166
+ def self.user_home
167
+ @@user_home ||= if ENV["HOME"]
168
+ ENV["HOME"]
169
+ elsif ENV["USERPROFILE"]
170
+ ENV["USERPROFILE"]
171
+ elsif ENV["HOMEDRIVE"] && ENV["HOMEPATH"]
172
+ File.join(ENV["HOMEDRIVE"], ENV["HOMEPATH"])
173
+ elsif ENV["APPDATA"]
174
+ ENV["APPDATA"]
175
+ else
176
+ begin
177
+ File.expand_path("~")
178
+ rescue
179
+ if File::ALT_SEPARATOR
180
+ "C:/"
181
+ else
182
+ "/"
183
+ end
184
+ end
185
+ end
186
+ end
187
+
188
+ # Returns the root where thor files are located, dependending on the OS.
189
+ #
190
+ def self.thor_root
191
+ File.join(user_home, ".thor").gsub(/\\/, '/')
192
+ end
193
+
194
+ # Returns the files in the thor root. On Windows thor_root will be something
195
+ # like this:
196
+ #
197
+ # C:\Documents and Settings\james\.thor
198
+ #
199
+ # If we don't #gsub the \ character, Dir.glob will fail.
200
+ #
201
+ def self.thor_root_glob
202
+ files = Dir["#{thor_root}/*"]
203
+
204
+ files.map! do |file|
205
+ File.directory?(file) ? File.join(file, "main.thor") : file
206
+ end
207
+ end
208
+
209
+ # Where to look for Thor files.
210
+ #
211
+ def self.globs_for(path)
212
+ ["#{path}/Thorfile", "#{path}/*.thor", "#{path}/tasks/*.thor", "#{path}/lib/tasks/*.thor"]
213
+ end
214
+
215
+ # Return the path to the ruby interpreter taking into account multiple
216
+ # installations and windows extensions.
217
+ #
218
+ def self.ruby_command
219
+ @ruby_command ||= begin
220
+ ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
221
+ ruby << Config::CONFIG['EXEEXT']
222
+
223
+ # escape string in case path to ruby executable contain spaces.
224
+ ruby.sub!(/.*\s.*/m, '"\&"')
225
+ ruby
226
+ end
227
+ end
228
+
229
+ end
230
+ end
@@ -0,0 +1,3 @@
1
+ class Thor
2
+ VERSION = "0.13.4".freeze
3
+ end
@@ -0,0 +1,170 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'thor/actions'
3
+
4
+ describe Thor::Actions::CreateFile do
5
+ before(:each) do
6
+ ::FileUtils.rm_rf(destination_root)
7
+ end
8
+
9
+ def create_file(destination=nil, config={}, options={})
10
+ @base = MyCounter.new([1,2], options, { :destination_root => destination_root })
11
+ @base.stub!(:file_name).and_return('rdoc')
12
+
13
+ @action = Thor::Actions::CreateFile.new(@base, destination, "CONFIGURATION",
14
+ { :verbose => !@silence }.merge(config))
15
+ end
16
+
17
+ def invoke!
18
+ capture(:stdout){ @action.invoke! }
19
+ end
20
+
21
+ def revoke!
22
+ capture(:stdout){ @action.revoke! }
23
+ end
24
+
25
+ def silence!
26
+ @silence = true
27
+ end
28
+
29
+ describe "#invoke!" do
30
+ it "creates a file" do
31
+ create_file("doc/config.rb")
32
+ invoke!
33
+ File.exists?(File.join(destination_root, "doc/config.rb")).must be_true
34
+ end
35
+
36
+ it "does not create a file if pretending" do
37
+ create_file("doc/config.rb", {}, :pretend => true)
38
+ invoke!
39
+ File.exists?(File.join(destination_root, "doc/config.rb")).must be_false
40
+ end
41
+
42
+ it "shows created status to the user" do
43
+ create_file("doc/config.rb")
44
+ invoke!.must == " create doc/config.rb\n"
45
+ end
46
+
47
+ it "does not show any information if log status is false" do
48
+ silence!
49
+ create_file("doc/config.rb")
50
+ invoke!.must be_empty
51
+ end
52
+
53
+ it "returns the given destination" do
54
+ capture(:stdout) do
55
+ create_file("doc/config.rb").invoke!.must == "doc/config.rb"
56
+ end
57
+ end
58
+
59
+ it "converts encoded instructions" do
60
+ create_file("doc/%file_name%.rb.tt")
61
+ invoke!
62
+ File.exists?(File.join(destination_root, "doc/rdoc.rb.tt")).must be_true
63
+ end
64
+
65
+ describe "when file exists" do
66
+ before(:each) do
67
+ create_file("doc/config.rb")
68
+ invoke!
69
+ end
70
+
71
+ describe "and is identical" do
72
+ it "shows identical status" do
73
+ create_file("doc/config.rb")
74
+ invoke!
75
+ invoke!.must == " identical doc/config.rb\n"
76
+ end
77
+ end
78
+
79
+ describe "and is not identical" do
80
+ before(:each) do
81
+ File.open(File.join(destination_root, 'doc/config.rb'), 'w'){ |f| f.write("FOO = 3") }
82
+ end
83
+
84
+ it "shows forced status to the user if force is given" do
85
+ create_file("doc/config.rb", {}, :force => true).must_not be_identical
86
+ invoke!.must == " force doc/config.rb\n"
87
+ end
88
+
89
+ it "shows skipped status to the user if skip is given" do
90
+ create_file("doc/config.rb", {}, :skip => true).must_not be_identical
91
+ invoke!.must == " skip doc/config.rb\n"
92
+ end
93
+
94
+ it "shows forced status to the user if force is configured" do
95
+ create_file("doc/config.rb", :force => true).must_not be_identical
96
+ invoke!.must == " force doc/config.rb\n"
97
+ end
98
+
99
+ it "shows skipped status to the user if skip is configured" do
100
+ create_file("doc/config.rb", :skip => true).must_not be_identical
101
+ invoke!.must == " skip doc/config.rb\n"
102
+ end
103
+
104
+ it "shows conflict status to ther user" do
105
+ create_file("doc/config.rb").must_not be_identical
106
+ $stdin.should_receive(:gets).and_return('s')
107
+ file = File.join(destination_root, 'doc/config.rb')
108
+
109
+ content = invoke!
110
+ content.must =~ /conflict doc\/config\.rb/
111
+ content.must =~ /Overwrite #{file}\? \(enter "h" for help\) \[Ynaqdh\]/
112
+ content.must =~ /skip doc\/config\.rb/
113
+ end
114
+
115
+ it "creates the file if the file collision menu returns true" do
116
+ create_file("doc/config.rb")
117
+ $stdin.should_receive(:gets).and_return('y')
118
+ invoke!.must =~ /force doc\/config\.rb/
119
+ end
120
+
121
+ it "skips the file if the file collision menu returns false" do
122
+ create_file("doc/config.rb")
123
+ $stdin.should_receive(:gets).and_return('n')
124
+ invoke!.must =~ /skip doc\/config\.rb/
125
+ end
126
+
127
+ it "executes the block given to show file content" do
128
+ create_file("doc/config.rb")
129
+ $stdin.should_receive(:gets).and_return('d')
130
+ $stdin.should_receive(:gets).and_return('n')
131
+ @base.shell.should_receive(:system).with(/diff -u/)
132
+ invoke!
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ describe "#revoke!" do
139
+ it "removes the destination file" do
140
+ create_file("doc/config.rb")
141
+ invoke!
142
+ revoke!
143
+ File.exists?(@action.destination).must be_false
144
+ end
145
+
146
+ it "does not raise an error if the file does not exist" do
147
+ create_file("doc/config.rb")
148
+ revoke!
149
+ File.exists?(@action.destination).must be_false
150
+ end
151
+ end
152
+
153
+ describe "#exists?" do
154
+ it "returns true if the destination file exists" do
155
+ create_file("doc/config.rb")
156
+ @action.exists?.must be_false
157
+ invoke!
158
+ @action.exists?.must be_true
159
+ end
160
+ end
161
+
162
+ describe "#identical?" do
163
+ it "returns true if the destination file and is identical" do
164
+ create_file("doc/config.rb")
165
+ @action.identical?.must be_false
166
+ invoke!
167
+ @action.identical?.must be_true
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,131 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'thor/actions'
3
+
4
+ describe Thor::Actions::Directory do
5
+ before(:each) do
6
+ ::FileUtils.rm_rf(destination_root)
7
+ invoker.stub!(:file_name).and_return("rdoc")
8
+ end
9
+
10
+ def invoker
11
+ @invoker ||= WhinyGenerator.new([1,2], {}, { :destination_root => destination_root })
12
+ end
13
+
14
+ def revoker
15
+ @revoker ||= WhinyGenerator.new([1,2], {}, { :destination_root => destination_root, :behavior => :revoke })
16
+ end
17
+
18
+ def invoke!(*args, &block)
19
+ capture(:stdout){ invoker.directory(*args, &block) }
20
+ end
21
+
22
+ def revoke!(*args, &block)
23
+ capture(:stdout){ revoker.directory(*args, &block) }
24
+ end
25
+
26
+ def exists_and_identical?(source_path, destination_path)
27
+ %w(config.rb README).each do |file|
28
+ source = File.join(source_root, source_path, file)
29
+ destination = File.join(destination_root, destination_path, file)
30
+
31
+ File.exists?(destination).must be_true
32
+ FileUtils.identical?(source, destination).must be_true
33
+ end
34
+ end
35
+
36
+ describe "#invoke!" do
37
+ it "raises an error if the source does not exist" do
38
+ lambda {
39
+ invoke! "unknown"
40
+ }.must raise_error(Thor::Error, /Could not find "unknown" in source paths/)
41
+ end
42
+
43
+ it "copies the whole directory recursively to the default destination" do
44
+ invoke! "doc"
45
+ exists_and_identical?("doc", "doc")
46
+ end
47
+
48
+ it "copies the whole directory recursively to the specified destination" do
49
+ invoke! "doc", "docs"
50
+ exists_and_identical?("doc", "docs")
51
+ end
52
+
53
+ it "copies only the first level files if recursive" do
54
+ invoke! ".", "tasks", :recursive => false
55
+
56
+ file = File.join(destination_root, "tasks", "group.thor")
57
+ File.exists?(file).must be_true
58
+
59
+ file = File.join(destination_root, "tasks", "doc")
60
+ File.exists?(file).must be_false
61
+
62
+ file = File.join(destination_root, "tasks", "doc", "README")
63
+ File.exists?(file).must be_false
64
+ end
65
+
66
+ it "copies files from the source relative to the current path" do
67
+ invoker.inside "doc" do
68
+ invoke! "."
69
+ end
70
+ exists_and_identical?("doc", "doc")
71
+ end
72
+
73
+ it "copies and evaluates templates" do
74
+ invoke! "doc", "docs"
75
+ file = File.join(destination_root, "docs", "rdoc.rb")
76
+ File.exists?(file).must be_true
77
+ File.read(file).must == "FOO = FOO\n"
78
+ end
79
+
80
+ it "copies directories" do
81
+ invoke! "doc", "docs"
82
+ file = File.join(destination_root, "docs", "components")
83
+ File.exists?(file).must be_true
84
+ File.directory?(file).must be_true
85
+ end
86
+
87
+ it "does not copy .empty_diretories files" do
88
+ invoke! "doc", "docs"
89
+ file = File.join(destination_root, "docs", "components", ".empty_directory")
90
+ File.exists?(file).must be_false
91
+ end
92
+
93
+ it "copies directories even if they are empty" do
94
+ invoke! "doc/components", "docs/components"
95
+ file = File.join(destination_root, "docs", "components")
96
+ File.exists?(file).must be_true
97
+ end
98
+
99
+ it "does not copy empty directories twice" do
100
+ content = invoke!("doc/components", "docs/components")
101
+ content.must_not =~ /exist/
102
+ end
103
+
104
+ it "logs status" do
105
+ content = invoke!("doc")
106
+ content.must =~ /create doc\/README/
107
+ content.must =~ /create doc\/config\.rb/
108
+ content.must =~ /create doc\/rdoc\.rb/
109
+ content.must =~ /create doc\/components/
110
+ end
111
+
112
+ it "yields a block" do
113
+ checked = false
114
+ invoke!("doc") do |content|
115
+ checked ||= !!(content =~ /FOO/)
116
+ end
117
+ checked.must be_true
118
+ end
119
+ end
120
+
121
+ describe "#revoke!" do
122
+ it "removes the destination file" do
123
+ invoke! "doc"
124
+ revoke! "doc"
125
+
126
+ File.exists?(File.join(destination_root, "doc", "README")).must be_false
127
+ File.exists?(File.join(destination_root, "doc", "config.rb")).must be_false
128
+ File.exists?(File.join(destination_root, "doc", "components")).must be_false
129
+ end
130
+ end
131
+ end