Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Autotest.add_hook :initialize do |at| | ||
at.clear_mappings | ||
at.add_exception(/\.git/) | ||
at.add_exception(/spec\/sandbox/) | ||
at.add_mapping(%r{^spec/.*_spec}) {|filename,_| at.files_matching %r{#{filename}}} | ||
at.add_mapping(%r{^bin/thor}) {|_,_| at.files_matching %r{spec/thor_runner_spec}} | ||
at.add_mapping(%r{}) {|_,_| at.files_matching %r{spec/.*_spec}} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
require 'thor/actions' | ||
|
||
describe Thor::Actions::CopyFile do | ||
before(:each) do | ||
::FileUtils.rm_r(destination_root, :force => true) | ||
end | ||
|
||
def copy_file(source, destination=nil) | ||
@base ||= begin | ||
base = Object.new | ||
mock(base).source_root{ source_root } | ||
mock(base).destination_root{ destination_root } | ||
base | ||
end | ||
|
||
@action ||= Thor::Actions::CopyFile.new(base, source, destination || source) | ||
end | ||
|
||
describe "#source" do | ||
it "sets the source based on the source root" do | ||
copy_file("task.thor").source.must == File.join(source_root, 'task.thor') | ||
end | ||
end | ||
|
||
describe "#destination" do | ||
it "sets the destination based on the destinatino root" do | ||
copy_file("task.thor").destination.must == File.join(destination_root, 'task.thor') | ||
end | ||
end | ||
|
||
describe "#invoke!" do | ||
it "copies the file to the destination root" do | ||
copy_file("task.thor").invoke! | ||
File.exists?(@action.destination).must be_true | ||
FileUtils.identical?(@action.source, @action.destination).must be_true | ||
end | ||
end | ||
|
||
describe "#revoke!" do | ||
it "removes the destination file" do | ||
copy_file("task.thor").invoke! | ||
@action.revoke! | ||
File.exists?(@action.destination).must be_false | ||
end | ||
end | ||
|
||
describe "#show" do | ||
it "shows file content" do | ||
copy_file("task.thor").show.must == File.read(File.join(source_root, "task.thor")) | ||
end | ||
end | ||
|
||
describe "#exists?" do | ||
it "returns true if the destination file exists" do | ||
copy_file("task.thor") | ||
@action.exists?.must be_false | ||
@action.invoke! | ||
@action.exists?.must be_true | ||
end | ||
end | ||
|
||
describe "#identical?" do | ||
it "returns true if the destination file and is identical" do | ||
copy_file("task.thor") | ||
@action.identical?.must be_false | ||
@action.invoke! | ||
@action.identical?.must be_true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters