thor 0.14.4 → 0.14.5

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.
@@ -28,8 +28,8 @@ describe Thor::Actions::Directory do
28
28
  source = File.join(source_root, source_path, file)
29
29
  destination = File.join(destination_root, destination_path, file)
30
30
 
31
- File.exists?(destination).must be_true
32
- FileUtils.identical?(source, destination).must be_true
31
+ File.exists?(destination).should be_true
32
+ FileUtils.identical?(source, destination).should be_true
33
33
  end
34
34
  end
35
35
 
@@ -37,12 +37,12 @@ describe Thor::Actions::Directory do
37
37
  it "raises an error if the source does not exist" do
38
38
  lambda {
39
39
  invoke! "unknown"
40
- }.must raise_error(Thor::Error, /Could not find "unknown" in any of your source paths/)
40
+ }.should raise_error(Thor::Error, /Could not find "unknown" in any of your source paths/)
41
41
  end
42
-
42
+
43
43
  it "should not create a directory in pretend mode" do
44
44
  invoke! "doc", "ghost", :pretend => true
45
- File.exists?("ghost").must be_false
45
+ File.exists?("ghost").should be_false
46
46
  end
47
47
 
48
48
  it "copies the whole directory recursively to the default destination" do
@@ -59,13 +59,13 @@ describe Thor::Actions::Directory do
59
59
  invoke! ".", "tasks", :recursive => false
60
60
 
61
61
  file = File.join(destination_root, "tasks", "group.thor")
62
- File.exists?(file).must be_true
62
+ File.exists?(file).should be_true
63
63
 
64
64
  file = File.join(destination_root, "tasks", "doc")
65
- File.exists?(file).must be_false
65
+ File.exists?(file).should be_false
66
66
 
67
67
  file = File.join(destination_root, "tasks", "doc", "README")
68
- File.exists?(file).must be_false
68
+ File.exists?(file).should be_false
69
69
  end
70
70
 
71
71
  it "copies files from the source relative to the current path" do
@@ -78,40 +78,40 @@ describe Thor::Actions::Directory do
78
78
  it "copies and evaluates templates" do
79
79
  invoke! "doc", "docs"
80
80
  file = File.join(destination_root, "docs", "rdoc.rb")
81
- File.exists?(file).must be_true
82
- File.read(file).must == "FOO = FOO\n"
81
+ File.exists?(file).should be_true
82
+ File.read(file).should == "FOO = FOO\n"
83
83
  end
84
84
 
85
85
  it "copies directories" do
86
86
  invoke! "doc", "docs"
87
87
  file = File.join(destination_root, "docs", "components")
88
- File.exists?(file).must be_true
89
- File.directory?(file).must be_true
88
+ File.exists?(file).should be_true
89
+ File.directory?(file).should be_true
90
90
  end
91
91
 
92
92
  it "does not copy .empty_directory files" do
93
93
  invoke! "doc", "docs"
94
94
  file = File.join(destination_root, "docs", "components", ".empty_directory")
95
- File.exists?(file).must be_false
95
+ File.exists?(file).should be_false
96
96
  end
97
97
 
98
98
  it "copies directories even if they are empty" do
99
99
  invoke! "doc/components", "docs/components"
100
100
  file = File.join(destination_root, "docs", "components")
101
- File.exists?(file).must be_true
101
+ File.exists?(file).should be_true
102
102
  end
103
103
 
104
104
  it "does not copy empty directories twice" do
105
105
  content = invoke!("doc/components", "docs/components")
106
- content.must_not =~ /exist/
106
+ content.should_not =~ /exist/
107
107
  end
108
108
 
109
109
  it "logs status" do
110
110
  content = invoke!("doc")
111
- content.must =~ /create doc\/README/
112
- content.must =~ /create doc\/config\.rb/
113
- content.must =~ /create doc\/rdoc\.rb/
114
- content.must =~ /create doc\/components/
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
115
  end
116
116
 
117
117
  it "yields a block" do
@@ -119,7 +119,7 @@ describe Thor::Actions::Directory do
119
119
  invoke!("doc") do |content|
120
120
  checked ||= !!(content =~ /FOO/)
121
121
  end
122
- checked.must be_true
122
+ checked.should be_true
123
123
  end
124
124
  end
125
125
 
@@ -128,9 +128,9 @@ describe Thor::Actions::Directory do
128
128
  invoke! "doc"
129
129
  revoke! "doc"
130
130
 
131
- File.exists?(File.join(destination_root, "doc", "README")).must be_false
132
- File.exists?(File.join(destination_root, "doc", "config.rb")).must be_false
133
- File.exists?(File.join(destination_root, "doc", "components")).must be_false
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
134
  end
135
135
  end
136
136
  end
@@ -19,17 +19,17 @@ describe Thor::Actions::EmptyDirectory do
19
19
  end
20
20
 
21
21
  def base
22
- @base ||= MyCounter.new([1,2], options, { :destination_root => destination_root })
22
+ @base ||= MyCounter.new([1,2], {}, { :destination_root => destination_root })
23
23
  end
24
24
 
25
25
  describe "#destination" do
26
26
  it "returns the full destination with the destination_root" do
27
- empty_directory('doc').destination.must == File.join(destination_root, 'doc')
27
+ empty_directory('doc').destination.should == File.join(destination_root, 'doc')
28
28
  end
29
29
 
30
30
  it "takes relative root into account" do
31
31
  base.inside('doc') do
32
- empty_directory('contents').destination.must == File.join(destination_root, 'doc', 'contents')
32
+ empty_directory('contents').destination.should == File.join(destination_root, 'doc', 'contents')
33
33
  end
34
34
  end
35
35
  end
@@ -37,7 +37,7 @@ describe Thor::Actions::EmptyDirectory do
37
37
  describe "#relative_destination" do
38
38
  it "returns the relative destination to the original destination root" do
39
39
  base.inside('doc') do
40
- empty_directory('contents').relative_destination.must == 'doc/contents'
40
+ empty_directory('contents').relative_destination.should == 'doc/contents'
41
41
  end
42
42
  end
43
43
  end
@@ -45,7 +45,7 @@ describe Thor::Actions::EmptyDirectory do
45
45
  describe "#given_destination" do
46
46
  it "returns the destination supplied by the user" do
47
47
  base.inside('doc') do
48
- empty_directory('contents').given_destination.must == 'contents'
48
+ empty_directory('contents').given_destination.should == 'contents'
49
49
  end
50
50
  end
51
51
  end
@@ -54,26 +54,26 @@ describe Thor::Actions::EmptyDirectory do
54
54
  it "copies the file to the specified destination" do
55
55
  empty_directory("doc")
56
56
  invoke!
57
- File.exists?(File.join(destination_root, "doc")).must be_true
57
+ File.exists?(File.join(destination_root, "doc")).should be_true
58
58
  end
59
59
 
60
60
  it "shows created status to the user" do
61
61
  empty_directory("doc")
62
- invoke!.must == " create doc\n"
62
+ invoke!.should == " create doc\n"
63
63
  end
64
64
 
65
65
  it "does not create a directory if pretending" do
66
66
  base.inside("foo", :pretend => true) do
67
67
  empty_directory("ghost")
68
68
  end
69
- File.exists?(File.join(base.destination_root, "ghost")).must be_false
69
+ File.exists?(File.join(base.destination_root, "ghost")).should be_false
70
70
  end
71
71
 
72
72
  describe "when directory exists" do
73
73
  it "shows exist status" do
74
74
  empty_directory("doc")
75
75
  invoke!
76
- invoke!.must == " exist doc\n"
76
+ invoke!.should == " exist doc\n"
77
77
  end
78
78
  end
79
79
  end
@@ -83,16 +83,16 @@ describe Thor::Actions::EmptyDirectory do
83
83
  empty_directory("doc")
84
84
  invoke!
85
85
  revoke!
86
- File.exists?(@action.destination).must be_false
86
+ File.exists?(@action.destination).should be_false
87
87
  end
88
88
  end
89
89
 
90
90
  describe "#exists?" do
91
91
  it "returns true if the destination file exists" do
92
92
  empty_directory("doc")
93
- @action.exists?.must be_false
93
+ @action.exists?.should be_false
94
94
  invoke!
95
- @action.exists?.must be_true
95
+ @action.exists?.should be_true
96
96
  end
97
97
  end
98
98
  end
@@ -13,10 +13,10 @@ describe Thor::Actions do
13
13
 
14
14
  def exists_and_identical?(source, destination)
15
15
  destination = File.join(destination_root, destination)
16
- File.exists?(destination).must be_true
16
+ File.exists?(destination).should be_true
17
17
 
18
18
  source = File.join(source_root, source)
19
- FileUtils.must be_identical(source, destination)
19
+ FileUtils.should be_identical(source, destination)
20
20
  end
21
21
 
22
22
  def file
@@ -41,12 +41,12 @@ describe Thor::Actions do
41
41
 
42
42
  it "logs status" do
43
43
  FileUtils.should_receive(:chmod_R).with(0755, file)
44
- action(:chmod, "foo", 0755).must == " chmod foo\n"
44
+ action(:chmod, "foo", 0755).should == " chmod foo\n"
45
45
  end
46
46
 
47
47
  it "does not log status if required" do
48
48
  FileUtils.should_receive(:chmod_R).with(0755, file)
49
- action(:chmod, "foo", 0755, :verbose => false).must be_empty
49
+ action(:chmod, "foo", 0755, :verbose => false).should be_empty
50
50
  end
51
51
  end
52
52
 
@@ -69,14 +69,37 @@ describe Thor::Actions do
69
69
  end
70
70
 
71
71
  it "logs status" do
72
- action(:copy_file, "task.thor").must == " create task.thor\n"
72
+ action(:copy_file, "task.thor").should == " create task.thor\n"
73
73
  end
74
74
 
75
75
  it "accepts a block to change output" do
76
76
  action :copy_file, "task.thor" do |content|
77
77
  "OMG" + content
78
78
  end
79
- File.read(File.join(destination_root, "task.thor")).must =~ /^OMG/
79
+ File.read(File.join(destination_root, "task.thor")).should =~ /^OMG/
80
+ end
81
+ end
82
+
83
+ describe "#link_file" do
84
+ it "links file from source to default destination" do
85
+ action :link_file, "task.thor"
86
+ exists_and_identical?("task.thor", "task.thor")
87
+ end
88
+
89
+ it "links file from source to the specified destination" do
90
+ action :link_file, "task.thor", "foo.thor"
91
+ exists_and_identical?("task.thor", "foo.thor")
92
+ end
93
+
94
+ it "links file from the source relative to the current path" do
95
+ runner.inside("doc") do
96
+ action :link_file, "README"
97
+ end
98
+ exists_and_identical?("doc/README", "doc/README")
99
+ end
100
+
101
+ it "logs status" do
102
+ action(:link_file, "task.thor").should == " create task.thor\n"
80
103
  end
81
104
  end
82
105
 
@@ -98,19 +121,19 @@ describe Thor::Actions do
98
121
 
99
122
  it "yields file content to a block" do
100
123
  action :get, "doc/README" do |content|
101
- content.must == "__start__\nREADME\n__end__\n"
124
+ content.should == "__start__\nREADME\n__end__\n"
102
125
  end
103
126
  end
104
127
 
105
128
  it "logs status" do
106
- action(:get, "doc/README", "docs/README").must == " create docs/README\n"
129
+ action(:get, "doc/README", "docs/README").should == " create docs/README\n"
107
130
  end
108
131
 
109
132
  it "accepts http remote sources" do
110
133
  body = "__start__\nHTTPFILE\n__end__\n"
111
134
  FakeWeb.register_uri(:get, 'http://example.com/file.txt', :body => body)
112
135
  action :get, 'http://example.com/file.txt' do |content|
113
- content.must == body
136
+ content.should == body
114
137
  end
115
138
  FakeWeb.clean_registry
116
139
  end
@@ -119,7 +142,7 @@ describe Thor::Actions do
119
142
  body = "__start__\nHTTPSFILE\n__end__\n"
120
143
  FakeWeb.register_uri(:get, 'https://example.com/file.txt', :body => body)
121
144
  action :get, 'https://example.com/file.txt' do |content|
122
- content.must == body
145
+ content.should == body
123
146
  end
124
147
  FakeWeb.clean_registry
125
148
  end
@@ -130,7 +153,7 @@ describe Thor::Actions do
130
153
  action :template, "doc/block_helper.rb"
131
154
 
132
155
  file = File.join(destination_root, "doc/block_helper.rb")
133
- File.read(file).must == "Hello world!"
156
+ File.read(file).should == "Hello world!"
134
157
  end
135
158
 
136
159
  it "evaluates the template given as source" do
@@ -138,31 +161,31 @@ describe Thor::Actions do
138
161
  action :template, "doc/config.rb"
139
162
 
140
163
  file = File.join(destination_root, "doc/config.rb")
141
- File.read(file).must == "class Config; end\n"
164
+ File.read(file).should == "class Config; end\n"
142
165
  end
143
166
 
144
167
  it "copies the template to the specified destination" do
145
168
  action :template, "doc/config.rb", "doc/configuration.rb"
146
169
  file = File.join(destination_root, "doc/configuration.rb")
147
- File.exists?(file).must be_true
170
+ File.exists?(file).should be_true
148
171
  end
149
172
 
150
173
  it "converts enconded instructions" do
151
174
  runner.should_receive(:file_name).and_return("rdoc")
152
175
  action :template, "doc/%file_name%.rb.tt"
153
176
  file = File.join(destination_root, "doc/rdoc.rb.tt")
154
- File.exists?(file).must be_true
177
+ File.exists?(file).should be_true
155
178
  end
156
179
 
157
180
  it "logs status" do
158
- capture(:stdout){ runner.template("doc/config.rb") }.must == " create doc/config.rb\n"
181
+ capture(:stdout){ runner.template("doc/config.rb") }.should == " create doc/config.rb\n"
159
182
  end
160
183
 
161
184
  it "accepts a block to change output" do
162
185
  action :template, "doc/config.rb" do |content|
163
186
  "OMG" + content
164
187
  end
165
- File.read(File.join(destination_root, "doc/config.rb")).must =~ /^OMG/
188
+ File.read(File.join(destination_root, "doc/config.rb")).should =~ /^OMG/
166
189
  end
167
190
  end
168
191
 
@@ -178,84 +201,84 @@ describe Thor::Actions do
178
201
  describe "#remove_file" do
179
202
  it "removes the file given" do
180
203
  action :remove_file, "doc/README"
181
- File.exists?(file).must be_false
204
+ File.exists?(file).should be_false
182
205
  end
183
206
 
184
207
  it "removes directories too" do
185
208
  action :remove_dir, "doc"
186
- File.exists?(File.join(destination_root, "doc")).must be_false
209
+ File.exists?(File.join(destination_root, "doc")).should be_false
187
210
  end
188
211
 
189
212
  it "does not remove if pretending" do
190
213
  runner(:pretend => true)
191
214
  action :remove_file, "doc/README"
192
- File.exists?(file).must be_true
215
+ File.exists?(file).should be_true
193
216
  end
194
217
 
195
218
  it "logs status" do
196
- action(:remove_file, "doc/README").must == " remove doc/README\n"
219
+ action(:remove_file, "doc/README").should == " remove doc/README\n"
197
220
  end
198
221
 
199
222
  it "does not log status if required" do
200
- action(:remove_file, "doc/README", :verbose => false).must be_empty
223
+ action(:remove_file, "doc/README", :verbose => false).should be_empty
201
224
  end
202
225
  end
203
226
 
204
227
  describe "#gsub_file" do
205
228
  it "replaces the content in the file" do
206
229
  action :gsub_file, "doc/README", "__start__", "START"
207
- File.binread(file).must == "START\nREADME\n__end__\n"
230
+ File.binread(file).should == "START\nREADME\n__end__\n"
208
231
  end
209
232
 
210
233
  it "does not replace if pretending" do
211
234
  runner(:pretend => true)
212
235
  action :gsub_file, "doc/README", "__start__", "START"
213
- File.binread(file).must == "__start__\nREADME\n__end__\n"
236
+ File.binread(file).should == "__start__\nREADME\n__end__\n"
214
237
  end
215
238
 
216
239
  it "accepts a block" do
217
240
  action(:gsub_file, "doc/README", "__start__"){ |match| match.gsub('__', '').upcase }
218
- File.binread(file).must == "START\nREADME\n__end__\n"
241
+ File.binread(file).should == "START\nREADME\n__end__\n"
219
242
  end
220
243
 
221
244
  it "logs status" do
222
- action(:gsub_file, "doc/README", "__start__", "START").must == " gsub doc/README\n"
245
+ action(:gsub_file, "doc/README", "__start__", "START").should == " gsub doc/README\n"
223
246
  end
224
247
 
225
248
  it "does not log status if required" do
226
- action(:gsub_file, file, "__", :verbose => false){ |match| match * 2 }.must be_empty
249
+ action(:gsub_file, file, "__", :verbose => false){ |match| match * 2 }.should be_empty
227
250
  end
228
251
  end
229
252
 
230
- describe "#append_file" do
253
+ describe "#append_to_file" do
231
254
  it "appends content to the file" do
232
- action :append_file, "doc/README", "END\n"
233
- File.binread(file).must == "__start__\nREADME\n__end__\nEND\n"
255
+ action :append_to_file, "doc/README", "END\n"
256
+ File.binread(file).should == "__start__\nREADME\n__end__\nEND\n"
234
257
  end
235
258
 
236
259
  it "accepts a block" do
237
- action(:append_file, "doc/README"){ "END\n" }
238
- File.binread(file).must == "__start__\nREADME\n__end__\nEND\n"
260
+ action(:append_to_file, "doc/README"){ "END\n" }
261
+ File.binread(file).should == "__start__\nREADME\n__end__\nEND\n"
239
262
  end
240
263
 
241
264
  it "logs status" do
242
- action(:append_file, "doc/README", "END").must == " append doc/README\n"
265
+ action(:append_to_file, "doc/README", "END").should == " append doc/README\n"
243
266
  end
244
267
  end
245
268
 
246
- describe "#prepend_file" do
269
+ describe "#prepend_to_file" do
247
270
  it "prepends content to the file" do
248
- action :prepend_file, "doc/README", "START\n"
249
- File.binread(file).must == "START\n__start__\nREADME\n__end__\n"
271
+ action :prepend_to_file, "doc/README", "START\n"
272
+ File.binread(file).should == "START\n__start__\nREADME\n__end__\n"
250
273
  end
251
274
 
252
275
  it "accepts a block" do
253
- action(:prepend_file, "doc/README"){ "START\n" }
254
- File.binread(file).must == "START\n__start__\nREADME\n__end__\n"
276
+ action(:prepend_to_file, "doc/README"){ "START\n" }
277
+ File.binread(file).should == "START\n__start__\nREADME\n__end__\n"
255
278
  end
256
279
 
257
280
  it "logs status" do
258
- action(:prepend_file, "doc/README", "START").must == " prepend doc/README\n"
281
+ action(:prepend_to_file, "doc/README", "START").should == " prepend doc/README\n"
259
282
  end
260
283
  end
261
284
 
@@ -266,21 +289,21 @@ describe Thor::Actions do
266
289
 
267
290
  it "appends content to a class" do
268
291
  action :inject_into_class, "application.rb", Application, " filter_parameters :password\n"
269
- File.binread(file).must == "class Application < Base\n filter_parameters :password\nend\n"
292
+ File.binread(file).should == "class Application < Base\n filter_parameters :password\nend\n"
270
293
  end
271
294
 
272
295
  it "accepts a block" do
273
296
  action(:inject_into_class, "application.rb", Application){ " filter_parameters :password\n" }
274
- File.binread(file).must == "class Application < Base\n filter_parameters :password\nend\n"
297
+ File.binread(file).should == "class Application < Base\n filter_parameters :password\nend\n"
275
298
  end
276
299
 
277
300
  it "logs status" do
278
- action(:inject_into_class, "application.rb", Application, " filter_parameters :password\n").must == " inject application.rb\n"
301
+ action(:inject_into_class, "application.rb", Application, " filter_parameters :password\n").should == " insert application.rb\n"
279
302
  end
280
303
 
281
304
  it "does not append if class name does not match" do
282
305
  action :inject_into_class, "application.rb", "App", " filter_parameters :password\n"
283
- File.binread(file).must == "class Application < Base\nend\n"
306
+ File.binread(file).should == "class Application < Base\nend\n"
284
307
  end
285
308
  end
286
309
  end