thor 0.14.6 → 0.19.4

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 (84) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/{CHANGELOG.rdoc → CHANGELOG.md} +91 -31
  4. data/CONTRIBUTING.md +15 -0
  5. data/{LICENSE → LICENSE.md} +2 -2
  6. data/README.md +36 -296
  7. data/bin/thor +1 -1
  8. data/lib/thor/actions/create_file.rb +33 -35
  9. data/lib/thor/actions/create_link.rb +7 -5
  10. data/lib/thor/actions/directory.rb +49 -24
  11. data/lib/thor/actions/empty_directory.rb +68 -67
  12. data/lib/thor/actions/file_manipulation.rb +85 -28
  13. data/lib/thor/actions/inject_into_file.rb +26 -32
  14. data/lib/thor/actions.rb +70 -66
  15. data/lib/thor/base.rb +314 -237
  16. data/lib/thor/command.rb +133 -0
  17. data/lib/thor/core_ext/hash_with_indifferent_access.rb +34 -24
  18. data/lib/thor/core_ext/io_binary_read.rb +12 -0
  19. data/lib/thor/core_ext/ordered_hash.rb +94 -65
  20. data/lib/thor/error.rb +10 -8
  21. data/lib/thor/group.rb +74 -66
  22. data/lib/thor/invocation.rb +65 -56
  23. data/lib/thor/line_editor/basic.rb +35 -0
  24. data/lib/thor/line_editor/readline.rb +88 -0
  25. data/lib/thor/line_editor.rb +17 -0
  26. data/lib/thor/parser/argument.rb +32 -29
  27. data/lib/thor/parser/arguments.rb +107 -93
  28. data/lib/thor/parser/option.rb +39 -13
  29. data/lib/thor/parser/options.rb +144 -97
  30. data/lib/thor/parser.rb +4 -4
  31. data/lib/thor/rake_compat.rb +21 -16
  32. data/lib/thor/runner.rb +166 -153
  33. data/lib/thor/shell/basic.rb +268 -122
  34. data/lib/thor/shell/color.rb +84 -43
  35. data/lib/thor/shell/html.rb +71 -66
  36. data/lib/thor/shell.rb +30 -37
  37. data/lib/thor/util.rb +227 -188
  38. data/lib/thor/version.rb +1 -1
  39. data/lib/thor.rb +289 -131
  40. data/thor.gemspec +21 -0
  41. metadata +50 -189
  42. data/Thorfile +0 -24
  43. data/bin/rake2thor +0 -86
  44. data/lib/thor/core_ext/file_binary_read.rb +0 -9
  45. data/lib/thor/task.rb +0 -114
  46. data/spec/actions/create_file_spec.rb +0 -170
  47. data/spec/actions/directory_spec.rb +0 -136
  48. data/spec/actions/empty_directory_spec.rb +0 -98
  49. data/spec/actions/file_manipulation_spec.rb +0 -310
  50. data/spec/actions/inject_into_file_spec.rb +0 -135
  51. data/spec/actions_spec.rb +0 -322
  52. data/spec/base_spec.rb +0 -269
  53. data/spec/core_ext/hash_with_indifferent_access_spec.rb +0 -43
  54. data/spec/core_ext/ordered_hash_spec.rb +0 -115
  55. data/spec/fixtures/application.rb +0 -2
  56. data/spec/fixtures/bundle/execute.rb +0 -6
  57. data/spec/fixtures/bundle/main.thor +0 -1
  58. data/spec/fixtures/doc/%file_name%.rb.tt +0 -1
  59. data/spec/fixtures/doc/README +0 -3
  60. data/spec/fixtures/doc/block_helper.rb +0 -3
  61. data/spec/fixtures/doc/components/.empty_directory +0 -0
  62. data/spec/fixtures/doc/config.rb +0 -1
  63. data/spec/fixtures/group.thor +0 -114
  64. data/spec/fixtures/invoke.thor +0 -112
  65. data/spec/fixtures/path with spaces +0 -0
  66. data/spec/fixtures/script.thor +0 -184
  67. data/spec/fixtures/task.thor +0 -10
  68. data/spec/group_spec.rb +0 -178
  69. data/spec/invocation_spec.rb +0 -100
  70. data/spec/parser/argument_spec.rb +0 -47
  71. data/spec/parser/arguments_spec.rb +0 -64
  72. data/spec/parser/option_spec.rb +0 -202
  73. data/spec/parser/options_spec.rb +0 -319
  74. data/spec/rake_compat_spec.rb +0 -68
  75. data/spec/register_spec.rb +0 -92
  76. data/spec/runner_spec.rb +0 -210
  77. data/spec/shell/basic_spec.rb +0 -223
  78. data/spec/shell/color_spec.rb +0 -41
  79. data/spec/shell/html_spec.rb +0 -27
  80. data/spec/shell_spec.rb +0 -47
  81. data/spec/spec_helper.rb +0 -54
  82. data/spec/task_spec.rb +0 -69
  83. data/spec/thor_spec.rb +0 -334
  84. data/spec/util_spec.rb +0 -163
metadata CHANGED
@@ -1,129 +1,42 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: thor
3
- version: !ruby/object:Gem::Version
4
- hash: 43
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 14
9
- - 6
10
- version: 0.14.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.19.4
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Yehuda Katz
14
- - "Jos\xC3\xA9 Valim"
8
+ - José Valim
15
9
  autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
-
19
- date: 2010-11-20 00:00:00 +01:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
12
+ date: 2016-11-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
23
15
  name: bundler
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ~>
29
- - !ruby/object:Gem::Version
30
- hash: 15
31
- segments:
32
- - 1
33
- - 0
34
- version: "1.0"
35
- type: :development
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: fakeweb
39
- prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 9
46
- segments:
47
- - 1
48
- - 3
49
- version: "1.3"
50
- type: :development
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: rdoc
54
- prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
56
- none: false
57
- requirements:
58
- - - ~>
59
- - !ruby/object:Gem::Version
60
- hash: 9
61
- segments:
62
- - 2
63
- - 5
64
- version: "2.5"
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
65
21
  type: :development
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: rake
69
22
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 27
76
- segments:
77
- - 0
78
- - 8
79
- version: "0.8"
80
- type: :development
81
- version_requirements: *id004
82
- - !ruby/object:Gem::Dependency
83
- name: rspec
84
- prerelease: false
85
- requirement: &id005 !ruby/object:Gem::Requirement
86
- none: false
87
- requirements:
88
- - - ~>
89
- - !ruby/object:Gem::Version
90
- hash: 1
91
- segments:
92
- - 2
93
- - 1
94
- version: "2.1"
95
- type: :development
96
- version_requirements: *id005
97
- - !ruby/object:Gem::Dependency
98
- name: simplecov
99
- prerelease: false
100
- requirement: &id006 !ruby/object:Gem::Requirement
101
- none: false
102
- requirements:
103
- - - ~>
104
- - !ruby/object:Gem::Version
105
- hash: 13
106
- segments:
107
- - 0
108
- - 3
109
- version: "0.3"
110
- type: :development
111
- version_requirements: *id006
112
- description: A scripting framework that replaces rake, sake and rubigen
113
- email:
114
- - ruby-thor@googlegroups.com
115
- executables:
116
- - rake2thor
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
28
+ description: Thor is a toolkit for building powerful command-line interfaces.
29
+ email: ruby-thor@googlegroups.com
30
+ executables:
117
31
  - thor
118
32
  extensions: []
119
-
120
- extra_rdoc_files:
121
- - CHANGELOG.rdoc
122
- - LICENSE
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".document"
36
+ - CHANGELOG.md
37
+ - CONTRIBUTING.md
38
+ - LICENSE.md
123
39
  - README.md
124
- - Thorfile
125
- files:
126
- - bin/rake2thor
127
40
  - bin/thor
128
41
  - lib/thor.rb
129
42
  - lib/thor/actions.rb
@@ -134,12 +47,16 @@ files:
134
47
  - lib/thor/actions/file_manipulation.rb
135
48
  - lib/thor/actions/inject_into_file.rb
136
49
  - lib/thor/base.rb
137
- - lib/thor/core_ext/file_binary_read.rb
50
+ - lib/thor/command.rb
138
51
  - lib/thor/core_ext/hash_with_indifferent_access.rb
52
+ - lib/thor/core_ext/io_binary_read.rb
139
53
  - lib/thor/core_ext/ordered_hash.rb
140
54
  - lib/thor/error.rb
141
55
  - lib/thor/group.rb
142
56
  - lib/thor/invocation.rb
57
+ - lib/thor/line_editor.rb
58
+ - lib/thor/line_editor/basic.rb
59
+ - lib/thor/line_editor/readline.rb
143
60
  - lib/thor/parser.rb
144
61
  - lib/thor/parser/argument.rb
145
62
  - lib/thor/parser/arguments.rb
@@ -151,87 +68,31 @@ files:
151
68
  - lib/thor/shell/basic.rb
152
69
  - lib/thor/shell/color.rb
153
70
  - lib/thor/shell/html.rb
154
- - lib/thor/task.rb
155
71
  - lib/thor/util.rb
156
72
  - lib/thor/version.rb
157
- - spec/actions/create_file_spec.rb
158
- - spec/actions/directory_spec.rb
159
- - spec/actions/empty_directory_spec.rb
160
- - spec/actions/file_manipulation_spec.rb
161
- - spec/actions/inject_into_file_spec.rb
162
- - spec/actions_spec.rb
163
- - spec/base_spec.rb
164
- - spec/core_ext/hash_with_indifferent_access_spec.rb
165
- - spec/core_ext/ordered_hash_spec.rb
166
- - spec/fixtures/application.rb
167
- - spec/fixtures/bundle/execute.rb
168
- - spec/fixtures/bundle/main.thor
169
- - spec/fixtures/doc/%file_name%.rb.tt
170
- - spec/fixtures/doc/README
171
- - spec/fixtures/doc/block_helper.rb
172
- - spec/fixtures/doc/components/.empty_directory
173
- - spec/fixtures/doc/config.rb
174
- - spec/fixtures/group.thor
175
- - spec/fixtures/invoke.thor
176
- - spec/fixtures/path with spaces
177
- - spec/fixtures/script.thor
178
- - spec/fixtures/task.thor
179
- - spec/group_spec.rb
180
- - spec/invocation_spec.rb
181
- - spec/parser/argument_spec.rb
182
- - spec/parser/arguments_spec.rb
183
- - spec/parser/option_spec.rb
184
- - spec/parser/options_spec.rb
185
- - spec/rake_compat_spec.rb
186
- - spec/register_spec.rb
187
- - spec/runner_spec.rb
188
- - spec/shell/basic_spec.rb
189
- - spec/shell/color_spec.rb
190
- - spec/shell/html_spec.rb
191
- - spec/shell_spec.rb
192
- - spec/spec_helper.rb
193
- - spec/task_spec.rb
194
- - spec/thor_spec.rb
195
- - spec/util_spec.rb
196
- - CHANGELOG.rdoc
197
- - LICENSE
198
- - README.md
199
- - Thorfile
200
- has_rdoc: true
201
- homepage: http://github.com/wycats/thor
202
- licenses: []
203
-
73
+ - thor.gemspec
74
+ homepage: http://whatisthor.com/
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
204
78
  post_install_message:
205
- rdoc_options:
206
- - --charset=UTF-8
207
- require_paths:
79
+ rdoc_options: []
80
+ require_paths:
208
81
  - lib
209
- required_ruby_version: !ruby/object:Gem::Requirement
210
- none: false
211
- requirements:
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
212
84
  - - ">="
213
- - !ruby/object:Gem::Version
214
- hash: 3
215
- segments:
216
- - 0
217
- version: "0"
218
- required_rubygems_version: !ruby/object:Gem::Requirement
219
- none: false
220
- requirements:
85
+ - !ruby/object:Gem::Version
86
+ version: 1.8.7
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
221
89
  - - ">="
222
- - !ruby/object:Gem::Version
223
- hash: 23
224
- segments:
225
- - 1
226
- - 3
227
- - 6
228
- version: 1.3.6
90
+ - !ruby/object:Gem::Version
91
+ version: 1.3.5
229
92
  requirements: []
230
-
231
93
  rubyforge_project:
232
- rubygems_version: 1.3.7
94
+ rubygems_version: 2.5.2
233
95
  signing_key:
234
- specification_version: 3
235
- summary: A scripting framework that replaces rake, sake and rubigen
96
+ specification_version: 4
97
+ summary: Thor is a toolkit for building powerful command-line interfaces.
236
98
  test_files: []
237
-
data/Thorfile DELETED
@@ -1,24 +0,0 @@
1
- # enconding: utf-8
2
- require 'thor/rake_compat'
3
-
4
- class Default < Thor
5
- include Thor::RakeCompat
6
-
7
- require 'rspec/core/rake_task'
8
- RSpec::Core::RakeTask.new(:spec)
9
-
10
- require 'bundler'
11
- Bundler::GemHelper.install_tasks
12
-
13
- require 'rdoc/task'
14
- if defined?(RDoc)
15
- RDoc::Task.new do |rdoc|
16
- rdoc.main = 'README.md'
17
- rdoc.rdoc_dir = 'rdoc'
18
- rdoc.title = 'thor'
19
- rdoc.rdoc_files.include('README.md', 'LICENSE', 'CHANGELOG.rdoc', 'Thorfile')
20
- rdoc.rdoc_files.include('lib/**/*.rb')
21
- rdoc.options << '--line-numbers' << '--inline-source'
22
- end
23
- end
24
- end
data/bin/rake2thor DELETED
@@ -1,86 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'ruby2ruby'
4
- require 'parse_tree'
5
- if Ruby2Ruby::VERSION >= "1.2.0"
6
- require 'parse_tree_extensions'
7
- end
8
- require 'rake'
9
-
10
- input = ARGV[0] || 'Rakefile'
11
- output = ARGV[1] || 'Thorfile'
12
-
13
- $requires = []
14
-
15
- module Kernel
16
- def require_with_record(file)
17
- $requires << file if caller[1] =~ /rake2thor:/
18
- require_without_record file
19
- end
20
- alias_method :require_without_record, :require
21
- alias_method :require, :require_with_record
22
- end
23
-
24
- load input
25
-
26
- @private_methods = []
27
-
28
- def file_task_name(name)
29
- "compile_" + name.gsub('/', '_slash_').gsub('.', '_dot_').gsub(/\W/, '_')
30
- end
31
-
32
- def method_for_task(task)
33
- file_task = task.is_a?(Rake::FileTask)
34
- comment = task.instance_variable_get('@comment')
35
- prereqs = task.instance_variable_get('@prerequisites').select(&Rake::Task.method(:task_defined?))
36
- actions = task.instance_variable_get('@actions')
37
- name = task.name.gsub(/^([^:]+:)+/, '')
38
- name = file_task_name(name) if file_task
39
- meth = ''
40
-
41
- meth << "desc #{name.inspect}, #{comment.inspect}\n" if comment
42
- meth << "def #{name}\n"
43
-
44
- meth << prereqs.map do |pre|
45
- pre = pre.to_s
46
- pre = file_task_name(pre) if Rake::Task[pre].is_a?(Rake::FileTask)
47
- ' ' + pre
48
- end.join("\n")
49
-
50
- meth << "\n\n" unless prereqs.empty? || actions.empty?
51
-
52
- meth << actions.map do |act|
53
- act = act.to_ruby
54
- unless act.gsub!(/^proc \{ \|(\w+)\|\n/,
55
- " \\1 = Struct.new(:name).new(#{name.inspect}) # A crude mock Rake::Task object\n")
56
- act.gsub!(/^proc \{\n/, '')
57
- end
58
- act.gsub(/\n\}$/, '')
59
- end.join("\n")
60
-
61
- meth << "\nend"
62
-
63
- if file_task
64
- @private_methods << meth
65
- return
66
- end
67
-
68
- meth
69
- end
70
-
71
- body = Rake::Task.tasks.map(&method(:method_for_task)).compact.map { |meth| meth.gsub(/^/, ' ') }.join("\n\n")
72
-
73
- unless @private_methods.empty?
74
- body << "\n\n private\n\n"
75
- body << @private_methods.map { |meth| meth.gsub(/^/, ' ') }.join("\n\n")
76
- end
77
-
78
- requires = $requires.map { |r| "require #{r.inspect}" }.join("\n")
79
-
80
- File.open(output, 'w') { |f| f.write(<<END.lstrip) }
81
- #{requires}
82
-
83
- class Default < Thor
84
- #{body}
85
- end
86
- END
@@ -1,9 +0,0 @@
1
- class File #:nodoc:
2
-
3
- unless File.respond_to?(:binread)
4
- def self.binread(file)
5
- File.open(file, 'rb') { |f| f.read }
6
- end
7
- end
8
-
9
- end
data/lib/thor/task.rb DELETED
@@ -1,114 +0,0 @@
1
- class Thor
2
- class Task < Struct.new(:name, :description, :long_description, :usage, :options)
3
- FILE_REGEXP = /^#{Regexp.escape(File.dirname(__FILE__))}/
4
-
5
- def initialize(name, description, long_description, usage, options=nil)
6
- super(name.to_s, description, long_description, usage, options || {})
7
- end
8
-
9
- def initialize_copy(other) #:nodoc:
10
- super(other)
11
- self.options = other.options.dup if other.options
12
- end
13
-
14
- def hidden?
15
- false
16
- end
17
-
18
- # By default, a task invokes a method in the thor class. You can change this
19
- # implementation to create custom tasks.
20
- def run(instance, args=[])
21
- public_method?(instance) ?
22
- instance.send(name, *args) : instance.class.handle_no_task_error(name)
23
- rescue ArgumentError => e
24
- handle_argument_error?(instance, e, caller) ?
25
- instance.class.handle_argument_error(self, e) : (raise e)
26
- rescue NoMethodError => e
27
- handle_no_method_error?(instance, e, caller) ?
28
- instance.class.handle_no_task_error(name) : (raise e)
29
- end
30
-
31
- # Returns the formatted usage by injecting given required arguments
32
- # and required options into the given usage.
33
- def formatted_usage(klass, namespace = true, subcommand = false)
34
- if namespace
35
- namespace = klass.namespace
36
- formatted = "#{namespace.gsub(/^(default)/,'')}:"
37
- formatted.sub!(/.$/, ' ') if subcommand
38
- end
39
-
40
- formatted ||= ""
41
-
42
- # Add usage with required arguments
43
- formatted << if klass && !klass.arguments.empty?
44
- usage.to_s.gsub(/^#{name}/) do |match|
45
- match << " " << klass.arguments.map{ |a| a.usage }.compact.join(' ')
46
- end
47
- else
48
- usage.to_s
49
- end
50
-
51
- # Add required options
52
- formatted << " #{required_options}"
53
-
54
- # Strip and go!
55
- formatted.strip
56
- end
57
-
58
- protected
59
-
60
- def not_debugging?(instance)
61
- !(instance.class.respond_to?(:debugging) && instance.class.debugging)
62
- end
63
-
64
- def required_options
65
- @required_options ||= options.map{ |_, o| o.usage if o.required? }.compact.sort.join(" ")
66
- end
67
-
68
- # Given a target, checks if this class name is not a private/protected method.
69
- def public_method?(instance) #:nodoc:
70
- collection = instance.private_methods + instance.protected_methods
71
- (collection & [name.to_s, name.to_sym]).empty?
72
- end
73
-
74
- def sans_backtrace(backtrace, caller) #:nodoc:
75
- saned = backtrace.reject { |frame| frame =~ FILE_REGEXP }
76
- saned -= caller
77
- end
78
-
79
- def handle_argument_error?(instance, error, caller)
80
- not_debugging?(instance) && error.message =~ /wrong number of arguments/ && begin
81
- saned = sans_backtrace(error.backtrace, caller)
82
- # Ruby 1.9 always include the called method in the backtrace
83
- saned.empty? || (saned.size == 1 && RUBY_VERSION >= "1.9")
84
- end
85
- end
86
-
87
- def handle_no_method_error?(instance, error, caller)
88
- not_debugging?(instance) &&
89
- error.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/
90
- end
91
- end
92
-
93
- # A task that is hidden in help messages but still invocable.
94
- class HiddenTask < Task
95
- def hidden?
96
- true
97
- end
98
- end
99
-
100
- # A dynamic task that handles method missing scenarios.
101
- class DynamicTask < Task
102
- def initialize(name, options=nil)
103
- super(name.to_s, "A dynamically-generated task", name.to_s, name.to_s, options)
104
- end
105
-
106
- def run(instance, args=[])
107
- if (instance.methods & [name.to_s, name.to_sym]).empty?
108
- super
109
- else
110
- instance.class.handle_no_task_error(name)
111
- end
112
- end
113
- end
114
- end
@@ -1,170 +0,0 @@
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