vim-jar 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/Gemfile.lock +4 -1
  2. data/bin/vim-jar +1 -57
  3. data/bundler/ruby/1.8/bin/rake2thor +19 -0
  4. data/bundler/ruby/1.8/bin/thor +19 -0
  5. data/bundler/ruby/1.8/gems/thor-0.14.6/CHANGELOG.rdoc +103 -0
  6. data/bundler/ruby/1.8/gems/thor-0.14.6/LICENSE +20 -0
  7. data/bundler/ruby/1.8/gems/thor-0.14.6/README.md +307 -0
  8. data/bundler/ruby/1.8/gems/thor-0.14.6/Thorfile +24 -0
  9. data/bundler/ruby/1.8/gems/thor-0.14.6/bin/rake2thor +86 -0
  10. data/bundler/ruby/1.8/gems/thor-0.14.6/bin/thor +6 -0
  11. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/create_file.rb +105 -0
  12. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/create_link.rb +57 -0
  13. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/directory.rb +93 -0
  14. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/empty_directory.rb +134 -0
  15. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/file_manipulation.rb +270 -0
  16. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions/inject_into_file.rb +109 -0
  17. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/actions.rb +314 -0
  18. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/base.rb +579 -0
  19. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/core_ext/file_binary_read.rb +9 -0
  20. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  21. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/core_ext/ordered_hash.rb +100 -0
  22. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/error.rb +30 -0
  23. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/group.rb +273 -0
  24. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/invocation.rb +168 -0
  25. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser/argument.rb +67 -0
  26. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser/arguments.rb +161 -0
  27. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser/option.rb +120 -0
  28. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser/options.rb +173 -0
  29. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/parser.rb +4 -0
  30. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/rake_compat.rb +66 -0
  31. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/runner.rb +309 -0
  32. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/shell/basic.rb +290 -0
  33. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/shell/color.rb +108 -0
  34. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/shell/html.rb +121 -0
  35. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/shell.rb +88 -0
  36. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/task.rb +114 -0
  37. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/util.rb +229 -0
  38. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor/version.rb +3 -0
  39. data/bundler/ruby/1.8/gems/thor-0.14.6/lib/thor.rb +334 -0
  40. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/create_file_spec.rb +170 -0
  41. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/directory_spec.rb +136 -0
  42. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/empty_directory_spec.rb +98 -0
  43. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/file_manipulation_spec.rb +310 -0
  44. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions/inject_into_file_spec.rb +135 -0
  45. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/actions_spec.rb +322 -0
  46. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/base_spec.rb +269 -0
  47. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb +43 -0
  48. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/core_ext/ordered_hash_spec.rb +115 -0
  49. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/application.rb +2 -0
  50. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/bundle/execute.rb +6 -0
  51. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/bundle/main.thor +1 -0
  52. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/%file_name%.rb.tt +1 -0
  53. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/README +3 -0
  54. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/block_helper.rb +3 -0
  55. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/components/.empty_directory +0 -0
  56. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/doc/config.rb +1 -0
  57. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/group.thor +114 -0
  58. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/invoke.thor +112 -0
  59. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/path with spaces +0 -0
  60. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/script.thor +184 -0
  61. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/fixtures/task.thor +10 -0
  62. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/group_spec.rb +178 -0
  63. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/invocation_spec.rb +100 -0
  64. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/parser/argument_spec.rb +47 -0
  65. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/parser/arguments_spec.rb +64 -0
  66. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/parser/option_spec.rb +202 -0
  67. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/parser/options_spec.rb +319 -0
  68. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/rake_compat_spec.rb +68 -0
  69. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/register_spec.rb +92 -0
  70. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/runner_spec.rb +210 -0
  71. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/shell/basic_spec.rb +223 -0
  72. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/shell/color_spec.rb +41 -0
  73. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/shell/html_spec.rb +27 -0
  74. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/shell_spec.rb +47 -0
  75. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/spec_helper.rb +54 -0
  76. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/task_spec.rb +69 -0
  77. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/thor_spec.rb +334 -0
  78. data/bundler/ruby/1.8/gems/thor-0.14.6/spec/util_spec.rb +163 -0
  79. data/bundler/ruby/1.8/specifications/thor-0.14.6.gemspec +48 -0
  80. data/lib/vim-jar/cli.rb +84 -67
  81. data/lib/vim-jar/config.rb +9 -0
  82. data/lib/vim-jar/installer/git.rb +8 -7
  83. data/lib/vim-jar/plugin.rb +61 -18
  84. data/lib/vim-jar/version.rb +1 -1
  85. data/lib/vim-jar.rb +1 -0
  86. data/spec/vim-jar/config_spec.rb +17 -0
  87. data/spec/vim-jar/git-config +16 -0
  88. data/spec/vim-jar/gitmodules +6 -0
  89. data/spec/vim-jar/plugin_spec.rb +46 -0
  90. data/vim-jar.gemspec +1 -0
  91. metadata +104 -9
@@ -0,0 +1,334 @@
1
+ require 'thor/base'
2
+
3
+ class Thor
4
+ class << self
5
+ # Sets the default task when thor is executed without an explicit task to be called.
6
+ #
7
+ # ==== Parameters
8
+ # meth<Symbol>:: name of the defaut task
9
+ #
10
+ def default_task(meth=nil)
11
+ case meth
12
+ when :none
13
+ @default_task = 'help'
14
+ when nil
15
+ @default_task ||= from_superclass(:default_task, 'help')
16
+ else
17
+ @default_task = meth.to_s
18
+ end
19
+ end
20
+
21
+ # Registers another Thor subclass as a command.
22
+ #
23
+ # ==== Parameters
24
+ # klass<Class>:: Thor subclass to register
25
+ # command<String>:: Subcommand name to use
26
+ # usage<String>:: Short usage for the subcommand
27
+ # description<String>:: Description for the subcommand
28
+ def register(klass, subcommand_name, usage, description, options={})
29
+ if klass <= Thor::Group
30
+ desc usage, description, options
31
+ define_method(subcommand_name) { invoke klass }
32
+ else
33
+ desc usage, description, options
34
+ subcommand subcommand_name, klass
35
+ end
36
+ end
37
+
38
+ # Defines the usage and the description of the next task.
39
+ #
40
+ # ==== Parameters
41
+ # usage<String>
42
+ # description<String>
43
+ # options<String>
44
+ #
45
+ def desc(usage, description, options={})
46
+ if options[:for]
47
+ task = find_and_refresh_task(options[:for])
48
+ task.usage = usage if usage
49
+ task.description = description if description
50
+ else
51
+ @usage, @desc, @hide = usage, description, options[:hide] || false
52
+ end
53
+ end
54
+
55
+ # Defines the long description of the next task.
56
+ #
57
+ # ==== Parameters
58
+ # long description<String>
59
+ #
60
+ def long_desc(long_description, options={})
61
+ if options[:for]
62
+ task = find_and_refresh_task(options[:for])
63
+ task.long_description = long_description if long_description
64
+ else
65
+ @long_desc = long_description
66
+ end
67
+ end
68
+
69
+ # Maps an input to a task. If you define:
70
+ #
71
+ # map "-T" => "list"
72
+ #
73
+ # Running:
74
+ #
75
+ # thor -T
76
+ #
77
+ # Will invoke the list task.
78
+ #
79
+ # ==== Parameters
80
+ # Hash[String|Array => Symbol]:: Maps the string or the strings in the array to the given task.
81
+ #
82
+ def map(mappings=nil)
83
+ @map ||= from_superclass(:map, {})
84
+
85
+ if mappings
86
+ mappings.each do |key, value|
87
+ if key.respond_to?(:each)
88
+ key.each {|subkey| @map[subkey] = value}
89
+ else
90
+ @map[key] = value
91
+ end
92
+ end
93
+ end
94
+
95
+ @map
96
+ end
97
+
98
+ # Declares the options for the next task to be declared.
99
+ #
100
+ # ==== Parameters
101
+ # Hash[Symbol => Object]:: The hash key is the name of the option and the value
102
+ # is the type of the option. Can be :string, :array, :hash, :boolean, :numeric
103
+ # or :required (string). If you give a value, the type of the value is used.
104
+ #
105
+ def method_options(options=nil)
106
+ @method_options ||= {}
107
+ build_options(options, @method_options) if options
108
+ @method_options
109
+ end
110
+
111
+ # Adds an option to the set of method options. If :for is given as option,
112
+ # it allows you to change the options from a previous defined task.
113
+ #
114
+ # def previous_task
115
+ # # magic
116
+ # end
117
+ #
118
+ # method_option :foo => :bar, :for => :previous_task
119
+ #
120
+ # def next_task
121
+ # # magic
122
+ # end
123
+ #
124
+ # ==== Parameters
125
+ # name<Symbol>:: The name of the argument.
126
+ # options<Hash>:: Described below.
127
+ #
128
+ # ==== Options
129
+ # :desc - Description for the argument.
130
+ # :required - If the argument is required or not.
131
+ # :default - Default value for this argument. It cannot be required and have default values.
132
+ # :aliases - Aliases for this option.
133
+ # :type - The type of the argument, can be :string, :hash, :array, :numeric or :boolean.
134
+ # :banner - String to show on usage notes.
135
+ #
136
+ def method_option(name, options={})
137
+ scope = if options[:for]
138
+ find_and_refresh_task(options[:for]).options
139
+ else
140
+ method_options
141
+ end
142
+
143
+ build_option(name, options, scope)
144
+ end
145
+
146
+ # Prints help information for the given task.
147
+ #
148
+ # ==== Parameters
149
+ # shell<Thor::Shell>
150
+ # task_name<String>
151
+ #
152
+ def task_help(shell, task_name)
153
+ meth = normalize_task_name(task_name)
154
+ task = all_tasks[meth]
155
+ handle_no_task_error(meth) unless task
156
+
157
+ shell.say "Usage:"
158
+ shell.say " #{banner(task)}"
159
+ shell.say
160
+ class_options_help(shell, nil => task.options.map { |_, o| o })
161
+ if task.long_description
162
+ shell.say "Description:"
163
+ shell.print_wrapped(task.long_description, :ident => 2)
164
+ else
165
+ shell.say task.description
166
+ end
167
+ end
168
+
169
+ # Prints help information for this class.
170
+ #
171
+ # ==== Parameters
172
+ # shell<Thor::Shell>
173
+ #
174
+ def help(shell, subcommand = false)
175
+ list = printable_tasks(true, subcommand)
176
+ Thor::Util.thor_classes_in(self).each do |klass|
177
+ list += klass.printable_tasks(false)
178
+ end
179
+ list.sort!{ |a,b| a[0] <=> b[0] }
180
+
181
+ shell.say "Tasks:"
182
+ shell.print_table(list, :ident => 2, :truncate => true)
183
+ shell.say
184
+ class_options_help(shell)
185
+ end
186
+
187
+ # Returns tasks ready to be printed.
188
+ def printable_tasks(all = true, subcommand = false)
189
+ (all ? all_tasks : tasks).map do |_, task|
190
+ next if task.hidden?
191
+ item = []
192
+ item << banner(task, false, subcommand)
193
+ item << (task.description ? "# #{task.description.gsub(/\s+/m,' ')}" : "")
194
+ item
195
+ end.compact
196
+ end
197
+
198
+ def subcommands
199
+ @subcommands ||= from_superclass(:subcommands, [])
200
+ end
201
+
202
+ def subcommand(subcommand, subcommand_class)
203
+ self.subcommands << subcommand.to_s
204
+ subcommand_class.subcommand_help subcommand
205
+ define_method(subcommand) { |*args| invoke subcommand_class, args }
206
+ end
207
+
208
+ # Extend check unknown options to accept a hash of conditions.
209
+ #
210
+ # === Parameters
211
+ # options<Hash>: A hash containing :only and/or :except keys
212
+ def check_unknown_options!(options={})
213
+ @check_unknown_options ||= Hash.new
214
+ options.each do |key, value|
215
+ if value
216
+ @check_unknown_options[key] = Array(value)
217
+ else
218
+ @check_unknown_options.delete(key)
219
+ end
220
+ end
221
+ @check_unknown_options
222
+ end
223
+
224
+ # Overwrite check_unknown_options? to take subcommands and options into account.
225
+ def check_unknown_options?(config) #:nodoc:
226
+ options = check_unknown_options
227
+ return false unless options
228
+
229
+ task = config[:current_task]
230
+ return true unless task
231
+
232
+ name = task.name
233
+
234
+ if subcommands.include?(name)
235
+ false
236
+ elsif options[:except]
237
+ !options[:except].include?(name.to_sym)
238
+ elsif options[:only]
239
+ options[:only].include?(name.to_sym)
240
+ else
241
+ true
242
+ end
243
+ end
244
+
245
+ protected
246
+
247
+ # The method responsible for dispatching given the args.
248
+ def dispatch(meth, given_args, given_opts, config) #:nodoc:
249
+ meth ||= retrieve_task_name(given_args)
250
+ task = all_tasks[normalize_task_name(meth)]
251
+
252
+ if task
253
+ args, opts = Thor::Options.split(given_args)
254
+ else
255
+ args, opts = given_args, nil
256
+ task = Thor::DynamicTask.new(meth)
257
+ end
258
+
259
+ opts = given_opts || opts || []
260
+ config.merge!(:current_task => task, :task_options => task.options)
261
+
262
+ trailing = args[Range.new(arguments.size, -1)]
263
+ new(args, opts, config).invoke_task(task, trailing || [])
264
+ end
265
+
266
+ # The banner for this class. You can customize it if you are invoking the
267
+ # thor class by another ways which is not the Thor::Runner. It receives
268
+ # the task that is going to be invoked and a boolean which indicates if
269
+ # the namespace should be displayed as arguments.
270
+ #
271
+ def banner(task, namespace = nil, subcommand = false)
272
+ "#{basename} #{task.formatted_usage(self, $thor_runner, subcommand)}"
273
+ end
274
+
275
+ def baseclass #:nodoc:
276
+ Thor
277
+ end
278
+
279
+ def create_task(meth) #:nodoc:
280
+ if @usage && @desc
281
+ base_class = @hide ? Thor::HiddenTask : Thor::Task
282
+ tasks[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)
283
+ @usage, @desc, @long_desc, @method_options, @hide = nil
284
+ true
285
+ elsif self.all_tasks[meth] || meth == "method_missing"
286
+ true
287
+ else
288
+ puts "[WARNING] Attempted to create task #{meth.inspect} without usage or description. " <<
289
+ "Call desc if you want this method to be available as task or declare it inside a " <<
290
+ "no_tasks{} block. Invoked from #{caller[1].inspect}."
291
+ false
292
+ end
293
+ end
294
+
295
+ def initialize_added #:nodoc:
296
+ class_options.merge!(method_options)
297
+ @method_options = nil
298
+ end
299
+
300
+ # Retrieve the task name from given args.
301
+ def retrieve_task_name(args) #:nodoc:
302
+ meth = args.first.to_s unless args.empty?
303
+
304
+ if meth && (map[meth] || meth !~ /^\-/)
305
+ args.shift
306
+ else
307
+ nil
308
+ end
309
+ end
310
+
311
+ # Receives a task name (can be nil), and try to get a map from it.
312
+ # If a map can't be found use the sent name or the default task.
313
+ def normalize_task_name(meth) #:nodoc:
314
+ meth = map[meth.to_s] || meth || default_task
315
+ meth.to_s.gsub('-','_') # treat foo-bar > foo_bar
316
+ end
317
+
318
+ def subcommand_help(cmd)
319
+ desc "help [COMMAND]", "Describe subcommands or one specific subcommand"
320
+ class_eval <<-RUBY
321
+ def help(task = nil, subcommand = true); super; end
322
+ RUBY
323
+ end
324
+ end
325
+
326
+ include Thor::Base
327
+
328
+ map HELP_MAPPINGS => :help
329
+
330
+ desc "help [TASK]", "Describe available tasks or one specific task"
331
+ def help(task = nil, subcommand = false)
332
+ task ? self.class.task_help(shell, task) : self.class.help(shell, subcommand)
333
+ end
334
+ 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")).should 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")).should be_false
40
+ end
41
+
42
+ it "shows created status to the user" do
43
+ create_file("doc/config.rb")
44
+ invoke!.should == " 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!.should be_empty
51
+ end
52
+
53
+ it "returns the given destination" do
54
+ capture(:stdout) do
55
+ create_file("doc/config.rb").invoke!.should == "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")).should 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!.should == " 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).should_not be_identical
86
+ invoke!.should == " 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).should_not be_identical
91
+ invoke!.should == " 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).should_not be_identical
96
+ invoke!.should == " 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).should_not be_identical
101
+ invoke!.should == " skip doc/config.rb\n"
102
+ end
103
+
104
+ it "shows conflict status to ther user" do
105
+ create_file("doc/config.rb").should_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.should =~ /conflict doc\/config\.rb/
111
+ content.should =~ /Overwrite #{file}\? \(enter "h" for help\) \[Ynaqdh\]/
112
+ content.should =~ /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!.should =~ /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!.should =~ /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).should 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).should 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?.should be_false
157
+ invoke!
158
+ @action.exists?.should 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?.should be_false
166
+ invoke!
167
+ @action.identical?.should be_true
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,136 @@
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).should be_true
32
+ FileUtils.identical?(source, destination).should 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
+ }.should raise_error(Thor::Error, /Could not find "unknown" in any of your source paths/)
41
+ end
42
+
43
+ it "should not create a directory in pretend mode" do
44
+ invoke! "doc", "ghost", :pretend => true
45
+ File.exists?("ghost").should be_false
46
+ end
47
+
48
+ it "copies the whole directory recursively to the default destination" do
49
+ invoke! "doc"
50
+ exists_and_identical?("doc", "doc")
51
+ end
52
+
53
+ it "copies the whole directory recursively to the specified destination" do
54
+ invoke! "doc", "docs"
55
+ exists_and_identical?("doc", "docs")
56
+ end
57
+
58
+ it "copies only the first level files if recursive" do
59
+ invoke! ".", "tasks", :recursive => false
60
+
61
+ file = File.join(destination_root, "tasks", "group.thor")
62
+ File.exists?(file).should be_true
63
+
64
+ file = File.join(destination_root, "tasks", "doc")
65
+ File.exists?(file).should be_false
66
+
67
+ file = File.join(destination_root, "tasks", "doc", "README")
68
+ File.exists?(file).should be_false
69
+ end
70
+
71
+ it "copies files from the source relative to the current path" do
72
+ invoker.inside "doc" do
73
+ invoke! "."
74
+ end
75
+ exists_and_identical?("doc", "doc")
76
+ end
77
+
78
+ it "copies and evaluates templates" do
79
+ invoke! "doc", "docs"
80
+ file = File.join(destination_root, "docs", "rdoc.rb")
81
+ File.exists?(file).should be_true
82
+ File.read(file).should == "FOO = FOO\n"
83
+ end
84
+
85
+ it "copies directories" do
86
+ invoke! "doc", "docs"
87
+ file = File.join(destination_root, "docs", "components")
88
+ File.exists?(file).should be_true
89
+ File.directory?(file).should be_true
90
+ end
91
+
92
+ it "does not copy .empty_directory files" do
93
+ invoke! "doc", "docs"
94
+ file = File.join(destination_root, "docs", "components", ".empty_directory")
95
+ File.exists?(file).should be_false
96
+ end
97
+
98
+ it "copies directories even if they are empty" do
99
+ invoke! "doc/components", "docs/components"
100
+ file = File.join(destination_root, "docs", "components")
101
+ File.exists?(file).should be_true
102
+ end
103
+
104
+ it "does not copy empty directories twice" do
105
+ content = invoke!("doc/components", "docs/components")
106
+ content.should_not =~ /exist/
107
+ end
108
+
109
+ it "logs status" do
110
+ content = invoke!("doc")
111
+ content.should =~ /create doc\/README/
112
+ content.should =~ /create doc\/config\.rb/
113
+ content.should =~ /create doc\/rdoc\.rb/
114
+ content.should =~ /create doc\/components/
115
+ end
116
+
117
+ it "yields a block" do
118
+ checked = false
119
+ invoke!("doc") do |content|
120
+ checked ||= !!(content =~ /FOO/)
121
+ end
122
+ checked.should be_true
123
+ end
124
+ end
125
+
126
+ describe "#revoke!" do
127
+ it "removes the destination file" do
128
+ invoke! "doc"
129
+ revoke! "doc"
130
+
131
+ File.exists?(File.join(destination_root, "doc", "README")).should be_false
132
+ File.exists?(File.join(destination_root, "doc", "config.rb")).should be_false
133
+ File.exists?(File.join(destination_root, "doc", "components")).should be_false
134
+ end
135
+ end
136
+ end