vim-jar 0.0.2 → 0.0.3

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 (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,223 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Thor::Shell::Basic do
4
+ def shell
5
+ @shell ||= Thor::Shell::Basic.new
6
+ end
7
+
8
+ describe "#padding" do
9
+ it "cannot be set to below zero" do
10
+ shell.padding = 10
11
+ shell.padding.should == 10
12
+
13
+ shell.padding = -1
14
+ shell.padding.should == 0
15
+ end
16
+ end
17
+
18
+ describe "#ask" do
19
+ it "prints a message to the user and gets the response" do
20
+ $stdout.should_receive(:print).with("Should I overwrite it? ")
21
+ $stdin.should_receive(:gets).and_return('Sure')
22
+ shell.ask("Should I overwrite it?").should == "Sure"
23
+ end
24
+ end
25
+
26
+ describe "#yes?" do
27
+ it "asks the user and returns true if the user replies yes" do
28
+ $stdout.should_receive(:print).with("Should I overwrite it? ")
29
+ $stdin.should_receive(:gets).and_return('y')
30
+ shell.yes?("Should I overwrite it?").should === true
31
+
32
+ $stdout.should_receive(:print).with("Should I overwrite it? ")
33
+ $stdin.should_receive(:gets).and_return('n')
34
+ shell.yes?("Should I overwrite it?").should_not === true
35
+ end
36
+ end
37
+
38
+ describe "#no?" do
39
+ it "asks the user and returns true if the user replies no" do
40
+ $stdout.should_receive(:print).with("Should I overwrite it? ")
41
+ $stdin.should_receive(:gets).and_return('n')
42
+ shell.no?("Should I overwrite it?").should === true
43
+
44
+ $stdout.should_receive(:print).with("Should I overwrite it? ")
45
+ $stdin.should_receive(:gets).and_return('Yes')
46
+ shell.no?("Should I overwrite it?").should === false
47
+ end
48
+ end
49
+
50
+ describe "#say" do
51
+ it "prints a message to the user" do
52
+ $stdout.should_receive(:puts).with("Running...")
53
+ shell.say("Running...")
54
+ end
55
+
56
+ it "prints a message to the user without new line if it ends with a whitespace" do
57
+ $stdout.should_receive(:print).with("Running... ")
58
+ shell.say("Running... ")
59
+ end
60
+
61
+ it "prints a message to the user without new line" do
62
+ $stdout.should_receive(:print).with("Running...")
63
+ shell.say("Running...", nil, false)
64
+ end
65
+ end
66
+
67
+ describe "#say_status" do
68
+ it "prints a message to the user with status" do
69
+ $stdout.should_receive(:puts).with(" create ~/.thor/task.thor")
70
+ shell.say_status(:create, "~/.thor/task.thor")
71
+ end
72
+
73
+ it "always use new line" do
74
+ $stdout.should_receive(:puts).with(" create ")
75
+ shell.say_status(:create, "")
76
+ end
77
+
78
+ it "does not print a message if base is muted" do
79
+ shell.should_receive(:mute?).and_return(true)
80
+ $stdout.should_not_receive(:puts)
81
+
82
+ shell.mute do
83
+ shell.say_status(:created, "~/.thor/task.thor")
84
+ end
85
+ end
86
+
87
+ it "does not print a message if base is set to quiet" do
88
+ base = MyCounter.new [1,2]
89
+ base.should_receive(:options).and_return(:quiet => true)
90
+
91
+ $stdout.should_not_receive(:puts)
92
+ shell.base = base
93
+ shell.say_status(:created, "~/.thor/task.thor")
94
+ end
95
+
96
+ it "does not print a message if log status is set to false" do
97
+ $stdout.should_not_receive(:puts)
98
+ shell.say_status(:created, "~/.thor/task.thor", false)
99
+ end
100
+
101
+ it "uses padding to set messages left margin" do
102
+ shell.padding = 2
103
+ $stdout.should_receive(:puts).with(" create ~/.thor/task.thor")
104
+ shell.say_status(:create, "~/.thor/task.thor")
105
+ end
106
+ end
107
+
108
+ describe "#print_table" do
109
+ before(:each) do
110
+ @table = []
111
+ @table << ["abc", "#123", "first three"]
112
+ @table << ["", "#0", "empty"]
113
+ @table << ["xyz", "#786", "last three"]
114
+ end
115
+
116
+ it "prints a table" do
117
+ content = capture(:stdout){ shell.print_table(@table) }
118
+ content.should == <<-TABLE
119
+ abc #123 first three
120
+ #0 empty
121
+ xyz #786 last three
122
+ TABLE
123
+ end
124
+
125
+ it "prints a table with identation" do
126
+ content = capture(:stdout){ shell.print_table(@table, :ident => 2) }
127
+ content.should == <<-TABLE
128
+ abc #123 first three
129
+ #0 empty
130
+ xyz #786 last three
131
+ TABLE
132
+ end
133
+
134
+ it "uses maximum terminal width" do
135
+ shell.should_receive(:terminal_width).and_return(20)
136
+ content = capture(:stdout){ shell.print_table(@table, :ident => 2, :truncate => true) }
137
+ content.should == <<-TABLE
138
+ abc #123 firs...
139
+ #0 empty
140
+ xyz #786 last...
141
+ TABLE
142
+ end
143
+
144
+ it "honors the colwidth option" do
145
+ content = capture(:stdout){ shell.print_table(@table, :colwidth => 10)}
146
+ content.should == <<-TABLE
147
+ abc #123 first three
148
+ #0 empty
149
+ xyz #786 last three
150
+ TABLE
151
+ end
152
+ end
153
+
154
+ describe "#file_collision" do
155
+ it "shows a menu with options" do
156
+ $stdout.should_receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqh] ')
157
+ $stdin.should_receive(:gets).and_return('n')
158
+ shell.file_collision('foo')
159
+ end
160
+
161
+ it "returns true if the user choose default option" do
162
+ $stdout.stub!(:print)
163
+ $stdin.should_receive(:gets).and_return('')
164
+ shell.file_collision('foo').should be_true
165
+ end
166
+
167
+ it "returns false if the user choose no" do
168
+ $stdout.stub!(:print)
169
+ $stdin.should_receive(:gets).and_return('n')
170
+ shell.file_collision('foo').should be_false
171
+ end
172
+
173
+ it "returns true if the user choose yes" do
174
+ $stdout.stub!(:print)
175
+ $stdin.should_receive(:gets).and_return('y')
176
+ shell.file_collision('foo').should be_true
177
+ end
178
+
179
+ it "shows help usage if the user choose help" do
180
+ $stdout.stub!(:print)
181
+ $stdin.should_receive(:gets).and_return('h')
182
+ $stdin.should_receive(:gets).and_return('n')
183
+ help = capture(:stdout){ shell.file_collision('foo') }
184
+ help.should =~ /h \- help, show this help/
185
+ end
186
+
187
+ it "quits if the user choose quit" do
188
+ $stdout.stub!(:print)
189
+ $stdout.should_receive(:puts).with('Aborting...')
190
+ $stdin.should_receive(:gets).and_return('q')
191
+
192
+ lambda {
193
+ shell.file_collision('foo')
194
+ }.should raise_error(SystemExit)
195
+ end
196
+
197
+ it "always returns true if the user choose always" do
198
+ $stdout.should_receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqh] ')
199
+ $stdin.should_receive(:gets).and_return('a')
200
+
201
+ shell.file_collision('foo').should be_true
202
+
203
+ $stdout.should_not_receive(:print)
204
+ shell.file_collision('foo').should be_true
205
+ end
206
+
207
+ describe "when a block is given" do
208
+ it "displays diff options to the user" do
209
+ $stdout.should_receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqdh] ')
210
+ $stdin.should_receive(:gets).and_return('s')
211
+ shell.file_collision('foo'){ }
212
+ end
213
+
214
+ it "invokes the diff command" do
215
+ $stdout.stub!(:print)
216
+ $stdin.should_receive(:gets).and_return('d')
217
+ $stdin.should_receive(:gets).and_return('n')
218
+ shell.should_receive(:system).with(/diff -u/)
219
+ capture(:stdout){ shell.file_collision('foo'){ } }
220
+ end
221
+ end
222
+ end
223
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Thor::Shell::Color do
4
+ def shell
5
+ @shell ||= Thor::Shell::Color.new
6
+ end
7
+
8
+ describe "#say" do
9
+ it "set the color if specified" do
10
+ $stdout.should_receive(:puts).with("\e[32mWow! Now we have colors!\e[0m")
11
+ shell.say "Wow! Now we have colors!", :green
12
+ end
13
+
14
+ it "does not use a new line even with colors" do
15
+ $stdout.should_receive(:print).with("\e[32mWow! Now we have colors! \e[0m")
16
+ shell.say "Wow! Now we have colors! ", :green
17
+ end
18
+ end
19
+
20
+ describe "#say_status" do
21
+ it "uses color to say status" do
22
+ $stdout.should_receive(:puts).with("\e[1m\e[31m conflict\e[0m README")
23
+ shell.say_status :conflict, "README", :red
24
+ end
25
+ end
26
+
27
+ describe "#file_collision" do
28
+ describe "when a block is given" do
29
+ it "invokes the diff command" do
30
+ $stdout.stub!(:print)
31
+ $stdin.should_receive(:gets).and_return('d')
32
+ $stdin.should_receive(:gets).and_return('n')
33
+
34
+ output = capture(:stdout){ shell.file_collision('spec/fixtures/doc/README'){ "README\nEND\n" } }
35
+ output.should =~ /\e\[31m\- __start__\e\[0m/
36
+ output.should =~ /^ README/
37
+ output.should =~ /\e\[32m\+ END\e\[0m/
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Thor::Shell::HTML do
4
+ def shell
5
+ @shell ||= Thor::Shell::HTML.new
6
+ end
7
+
8
+ describe "#say" do
9
+ it "set the color if specified" do
10
+ $stdout.should_receive(:puts).with('<span style="color: green;">Wow! Now we have colors!</span>')
11
+ shell.say "Wow! Now we have colors!", :green
12
+ end
13
+
14
+ it "does not use a new line even with colors" do
15
+ $stdout.should_receive(:print).with('<span style="color: green;">Wow! Now we have colors! </span>')
16
+ shell.say "Wow! Now we have colors! ", :green
17
+ end
18
+ end
19
+
20
+ describe "#say_status" do
21
+ it "uses color to say status" do
22
+ $stdout.should_receive(:puts).with('<strong><span style="color: red;"> conflict</span></strong> README')
23
+ shell.say_status :conflict, "README", :red
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,47 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Thor::Shell do
4
+ def shell
5
+ @shell ||= Thor::Base.shell.new
6
+ end
7
+
8
+ describe "#initialize" do
9
+ it "sets shell value" do
10
+ base = MyCounter.new [1, 2], { }, :shell => shell
11
+ base.shell.should == shell
12
+ end
13
+
14
+ it "sets the base value on the shell if an accessor is available" do
15
+ base = MyCounter.new [1, 2], { }, :shell => shell
16
+ shell.base.should == base
17
+ end
18
+ end
19
+
20
+ describe "#shell" do
21
+ it "returns the shell in use" do
22
+ MyCounter.new([1,2]).shell.should be_kind_of(Thor::Base.shell)
23
+ end
24
+
25
+ it "uses $THOR_SHELL" do
26
+ class Thor::Shell::TestShell < Thor::Shell::Basic; end
27
+
28
+ Thor::Base.shell.should == shell.class
29
+ ENV['THOR_SHELL'] = 'TestShell'
30
+ Thor::Base.shell = nil
31
+ Thor::Base.shell.should == Thor::Shell::TestShell
32
+ ENV['THOR_SHELL'] = ''
33
+ Thor::Base.shell = shell.class
34
+ Thor::Base.shell.should == shell.class
35
+ end
36
+ end
37
+
38
+ describe "with_padding" do
39
+ it "uses padding for inside block outputs" do
40
+ base = MyCounter.new([1,2])
41
+ base.with_padding do
42
+ capture(:stdout){ base.say_status :padding, "cool" }.strip.should == "padding cool"
43
+ end
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,54 @@
1
+ $TESTING=true
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_group 'Libraries', 'lib'
6
+ add_group 'Specs', 'spec'
7
+ end
8
+
9
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
10
+ require 'thor'
11
+ require 'thor/group'
12
+ require 'stringio'
13
+
14
+ require 'rdoc'
15
+ require 'rspec'
16
+ require 'diff/lcs' # You need diff/lcs installed to run specs (but not to run Thor).
17
+ require 'fakeweb' # You need fakeweb installed to run specs (but not to run Thor).
18
+
19
+ # Set shell to basic
20
+ $0 = "thor"
21
+ $thor_runner = true
22
+ ARGV.clear
23
+ Thor::Base.shell = Thor::Shell::Basic
24
+
25
+ # Load fixtures
26
+ load File.join(File.dirname(__FILE__), "fixtures", "task.thor")
27
+ load File.join(File.dirname(__FILE__), "fixtures", "group.thor")
28
+ load File.join(File.dirname(__FILE__), "fixtures", "script.thor")
29
+ load File.join(File.dirname(__FILE__), "fixtures", "invoke.thor")
30
+
31
+ RSpec.configure do |config|
32
+ def capture(stream)
33
+ begin
34
+ stream = stream.to_s
35
+ eval "$#{stream} = StringIO.new"
36
+ yield
37
+ result = eval("$#{stream}").string
38
+ ensure
39
+ eval("$#{stream} = #{stream.upcase}")
40
+ end
41
+
42
+ result
43
+ end
44
+
45
+ def source_root
46
+ File.join(File.dirname(__FILE__), 'fixtures')
47
+ end
48
+
49
+ def destination_root
50
+ File.join(File.dirname(__FILE__), 'sandbox')
51
+ end
52
+
53
+ alias :silence :capture
54
+ end
@@ -0,0 +1,69 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Thor::Task do
4
+ def task(options={})
5
+ options.each do |key, value|
6
+ options[key] = Thor::Option.parse(key, value)
7
+ end
8
+
9
+ @task ||= Thor::Task.new(:can_has, "I can has cheezburger", "I can has cheezburger\nLots and lots of it", "can_has", options)
10
+ end
11
+
12
+ describe "#formatted_usage" do
13
+ it "includes namespace within usage" do
14
+ Object.stub!(:namespace).and_return("foo")
15
+ Object.stub!(:arguments).and_return([])
16
+ task(:bar => :required).formatted_usage(Object).should == "foo:can_has --bar=BAR"
17
+ end
18
+
19
+ it "removes default from namespace" do
20
+ Object.stub!(:namespace).and_return("default:foo")
21
+ Object.stub!(:arguments).and_return([])
22
+ task(:bar => :required).formatted_usage(Object).should == ":foo:can_has --bar=BAR"
23
+ end
24
+
25
+ it "injects arguments into usage" do
26
+ Object.stub!(:namespace).and_return("foo")
27
+ Object.stub!(:arguments).and_return([ Thor::Argument.new(:bar, nil, true, :string) ])
28
+ task(:foo => :required).formatted_usage(Object).should == "foo:can_has BAR --foo=FOO"
29
+ end
30
+ end
31
+
32
+ describe "#dynamic" do
33
+ it "creates a dynamic task with the given name" do
34
+ Thor::DynamicTask.new('task').name.should == 'task'
35
+ Thor::DynamicTask.new('task').description.should == 'A dynamically-generated task'
36
+ Thor::DynamicTask.new('task').usage.should == 'task'
37
+ Thor::DynamicTask.new('task').options.should == {}
38
+ end
39
+
40
+ it "does not invoke an existing method" do
41
+ mock = mock()
42
+ mock.class.should_receive(:handle_no_task_error).with("to_s")
43
+ Thor::DynamicTask.new('to_s').run(mock)
44
+ end
45
+ end
46
+
47
+ describe "#dup" do
48
+ it "dup options hash" do
49
+ task = Thor::Task.new("can_has", nil, nil, nil, :foo => true, :bar => :required)
50
+ task.dup.options.delete(:foo)
51
+ task.options[:foo].should_not be_nil
52
+ end
53
+ end
54
+
55
+ describe "#run" do
56
+ it "runs a task by calling a method in the given instance" do
57
+ mock = mock()
58
+ mock.should_receive(:send).with("can_has", 1, 2, 3)
59
+ task.run(mock, [1, 2, 3])
60
+ end
61
+
62
+ it "raises an error if the method to be invoked is private" do
63
+ mock = mock()
64
+ mock.should_receive(:private_methods).and_return(['can_has'])
65
+ mock.class.should_receive(:handle_no_task_error).with("can_has")
66
+ task.run(mock)
67
+ end
68
+ end
69
+ end