Skip to content

Commit

Permalink
Made specs pass across platforms.
Browse files Browse the repository at this point in the history
Added #tmp() helper to Object to ease the usage of
temporary folders across platforms.

Corrected all the specs to usage of this helper.

Thanks to Brian Ford from MSpec for the helper code.
  • Loading branch information
luislavena committed Nov 17, 2008
1 parent b5914c0 commit 3771000
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 106 deletions.
8 changes: 4 additions & 4 deletions spec/actions/empty_directory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
end

it 'sets destination' do
Templater::Actions::EmptyDirectory.new(@generator, :monkey, '/path/to/destination').
destination.should == '/path/to/destination'
Templater::Actions::EmptyDirectory.new(@generator, :monkey, tmp('/path/to/destination')).
destination.should == tmp('/path/to/destination')
end
end

describe '#relative_destination' do
it "returns the destination relative to the generator's destination root" do
@generator.stub!(:destination_root).and_return('/path/to')
file = Templater::Actions::EmptyDirectory.new(@generator, :monkey, '/path/to/destination/with/some/more/subdirs')
@generator.stub!(:destination_root).and_return(tmp('/path/to'))
file = Templater::Actions::EmptyDirectory.new(@generator, :monkey, tmp('/path/to/destination/with/some/more/subdirs'))
file.relative_destination.should == 'destination/with/some/more/subdirs'
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/actions/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

before do
@generator = mock('a generator')
@generator.stub!(:source_root).and_return('/tmp/source')
@generator.stub!(:destination_root).and_return('/tmp/destination')
@generator.stub!(:source_root).and_return(tmp('source'))
@generator.stub!(:destination_root).and_return(tmp('destination'))
end

describe '.new' do
it "should set name, source and destination" do
file = Templater::Actions::File.new(@generator, :monkey, '/path/to/source', '/path/to/destination')
file = Templater::Actions::File.new(@generator, :monkey, tmp('/path/to/source'), tmp('/path/to/destination'))
file.name.should == :monkey
file.source.should == '/path/to/source'
file.destination.should == '/path/to/destination'
file.source.should == tmp('/path/to/source')
file.destination.should == tmp('/path/to/destination')
end
end

describe '#relative_destination' do
it "should get the destination relative to the generator's destination root" do
@generator.stub!(:destination_root).and_return('/path/to')
file = Templater::Actions::File.new(@generator, :monkey, '/path/to/source', '/path/to/destination/with/some/more/subdirs')
@generator.stub!(:destination_root).and_return(tmp('/path/to'))
file = Templater::Actions::File.new(@generator, :monkey, tmp('/path/to/source'), tmp('/path/to/destination/with/some/more/subdirs'))
file.relative_destination.should == 'destination/with/some/more/subdirs'
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/actions/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

before do
@generator = mock('a generator')
@generator.stub!(:source_root).and_return('/tmp/source')
@generator.stub!(:destination_root).and_return('/tmp/destination')
@generator.stub!(:source_root).and_return(tmp('source'))
@generator.stub!(:destination_root).and_return(tmp('destination'))
end

describe '.new' do
it "should set name, source and destination" do
template = Templater::Actions::Template.new(@generator, :monkey, '/path/to/source', '/path/to/destination')
template = Templater::Actions::Template.new(@generator, :monkey, tmp('/path/to/source'), tmp('/path/to/destination'))
template.name.should == :monkey
template.source.should == '/path/to/source'
template.destination.should == '/path/to/destination'
template.source.should == tmp('/path/to/source')
template.destination.should == tmp('/path/to/destination')
end
end

describe '#relative_destination' do
it "should get the destination relative to the generator's destination root" do
@generator.stub!(:destination_root).and_return('/path/to')
template = Templater::Actions::Template.new(@generator, :monkey, '/path/to/source', '/path/to/destination/with/some/more/subdirs')
@generator.stub!(:destination_root).and_return(tmp('/path/to'))
template = Templater::Actions::Template.new(@generator, :monkey, tmp('/path/to/source'), tmp('/path/to/destination/with/some/more/subdirs'))
template.relative_destination.should == 'destination/with/some/more/subdirs'
end
end
Expand Down
34 changes: 17 additions & 17 deletions spec/generator/empty_directories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,57 @@

it "should add an empty_directory" do
@generator_class.empty_directory(:my_empty_directory, 'path/to/destination.rb')
@instance = @generator_class.new('/tmp/destination')
@instance = @generator_class.new(tmp('destination'))

@instance.stub!(:source_root).and_return('/tmp/source')
@instance.stub!(:source_root).and_return(tmp('source'))

@instance.empty_directory(:my_empty_directory).destination.should == '/tmp/destination/path/to/destination.rb'
@instance.empty_directory(:my_empty_directory).destination.should == tmp('/destination/path/to/destination.rb')
@instance.empty_directory(:my_empty_directory).should be_an_instance_of(Templater::Actions::EmptyDirectory)
end

it "should add a empty_directory and convert an instruction encoded in the destination" do
@generator_class.empty_directory(:my_empty_directory, 'template/%another_method%.rb')
@instance = @generator_class.new('/tmp/destination')
@instance = @generator_class.new(tmp('destination'))

@instance.should_receive(:another_method).at_least(:once).and_return('beast')

@instance.empty_directory(:my_empty_directory).destination.should == "/tmp/destination/template/beast.rb"
@instance.empty_directory(:my_empty_directory).destination.should == tmp("/destination/template/beast.rb")
@instance.empty_directory(:my_empty_directory).should be_an_instance_of(Templater::Actions::EmptyDirectory)
end

it "should add an empty directory with a block" do
@generator_class.empty_directory(:my_empty_directory) do |action|
action.destination = "gurr#{Process.pid.to_s}.rb"
end
@instance = @generator_class.new('/tmp/destination')
@instance = @generator_class.new(tmp('destination'))

@instance.empty_directory(:my_empty_directory).destination.should == "/tmp/destination/gurr#{Process.pid.to_s}.rb"
@instance.empty_directory(:my_empty_directory).destination.should == tmp("/destination/gurr#{Process.pid.to_s}.rb")
@instance.empty_directory(:my_empty_directory).should be_an_instance_of(Templater::Actions::EmptyDirectory)
end

it "should add an empty directory with a complex block" do
@generator_class.empty_directory(:my_empty_directory) do |action|
action.destination = 'gurr' / "gurr#{something}.rb"
end
@instance = @generator_class.new('/tmp/destination')
@instance = @generator_class.new(tmp('destination'))

@instance.stub!(:something).and_return('anotherthing')

@instance.empty_directory(:my_empty_directory).destination.should == "/tmp/destination/gurr/gurranotherthing.rb"
@instance.empty_directory(:my_empty_directory).destination.should == tmp("/destination/gurr/gurranotherthing.rb")
@instance.empty_directory(:my_empty_directory).should be_an_instance_of(Templater::Actions::EmptyDirectory)
end

it "should add a empty_directory and leave an encoded instruction be if it doesn't exist as a method" do
@generator_class.empty_directory(:my_empty_directory, 'template/%some_method%.rb')
@instance = @generator_class.new('/tmp/destination')
@instance = @generator_class.new(tmp('destination'))

@instance.empty_directory(:my_empty_directory).destination.should == "/tmp/destination/template/%some_method%.rb"
@instance.empty_directory(:my_empty_directory).destination.should == tmp("/destination/template/%some_method%.rb")
@instance.empty_directory(:my_empty_directory).should be_an_instance_of(Templater::Actions::EmptyDirectory)
end

it "should pass options on to the empty_directory" do
@generator_class.empty_directory(:my_empty_directory, 'path/to/destination.rb', :before => :monkey, :after => :donkey)
@instance = @generator_class.new('/tmp/destination')
@instance = @generator_class.new(tmp('destination'))

@instance.empty_directory(:my_empty_directory).options[:before].should == :monkey
@instance.empty_directory(:my_empty_directory).options[:after].should == :donkey
Expand All @@ -74,7 +74,7 @@
@generator_class.empty_directory(:blah1, 'blah.rb')
@generator_class.empty_directory(:blah2, 'blah2.rb')

instance = @generator_class.new('/tmp')
instance = @generator_class.new(tmp('tmp'))

instance.empty_directories[0].name.should == :blah1
instance.empty_directories[1].name.should == :blah2
Expand All @@ -87,7 +87,7 @@
@generator_class.empty_directory(:rails, 'blah2.rb', :framework => :rails)
@generator_class.empty_directory(:none, 'blah2.rb')

instance = @generator_class.new('/tmp')
instance = @generator_class.new(tmp('tmp'))

instance.empty_directories[0].name.should == :rails
instance.empty_directories[1].name.should == :none
Expand Down Expand Up @@ -115,10 +115,10 @@
@generator_class.empty_directory(:blah1, 'blah.rb')
@generator_class.empty_directory(:blah2, 'blah2.rb')

instance = @generator_class.new('/tmp')
instance = @generator_class.new(tmp('tmp'))

instance.empty_directory(:blah1).name.should == :blah1
instance.empty_directory(:blah1).destination.should == '/tmp/blah.rb'
instance.empty_directory(:blah1).destination.should == tmp('/tmp/blah.rb')
end

it "should not return a empty_directory with an option that does not match." do
Expand All @@ -128,7 +128,7 @@
@generator_class.empty_directory(:rails, 'blah2.rb', :framework => :rails)
@generator_class.empty_directory(:none, 'blah2.rb')

instance = @generator_class.new('/tmp')
instance = @generator_class.new(tmp('tmp'))

instance.framework = :rails
instance.empty_directory(:rails).name.should == :rails
Expand Down
44 changes: 22 additions & 22 deletions spec/generator/files_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@

before do
@generator_class = Class.new(Templater::Generator)
@generator_class.stub!(:source_root).and_return('/tmp/source')
@generator_class.stub!(:source_root).and_return(tmp('source'))
end

it "should add a file with source and destination" do
@generator_class.file(:my_template, 'path/to/source.rbt', 'path/to/destination.rb')
@instance = @generator_class.new('/tmp/destination')
@instance = @generator_class.new(tmp('destination'))

@instance.file(:my_template).source.should == '/tmp/source/path/to/source.rbt'
@instance.file(:my_template).destination.should == '/tmp/destination/path/to/destination.rb'
@instance.file(:my_template).source.should == tmp('/source/path/to/source.rbt')
@instance.file(:my_template).destination.should == tmp('/destination/path/to/destination.rb')
@instance.file(:my_template).should be_an_instance_of(Templater::Actions::File)
end

it "should add a file with source and infer destination " do
@generator_class.file(:my_template, 'path/to/file.rb')
@instance = @generator_class.new('/tmp/destination')
@instance = @generator_class.new(tmp('destination'))

@instance.file(:my_template).source.should == '/tmp/source/path/to/file.rb'
@instance.file(:my_template).destination.should == '/tmp/destination/path/to/file.rb'
@instance.file(:my_template).source.should == tmp('/source/path/to/file.rb')
@instance.file(:my_template).destination.should == tmp('/destination/path/to/file.rb')
@instance.file(:my_template).should be_an_instance_of(Templater::Actions::File)
end

Expand All @@ -30,10 +30,10 @@
file.source = 'blah.rbt'
file.destination = "gurr#{Process.pid.to_s}.rb"
end
@instance = @generator_class.new('/tmp/destination')
@instance = @generator_class.new(tmp('destination'))

@instance.file(:my_file).source.should == '/tmp/source/blah.rbt'
@instance.file(:my_file).destination.should == "/tmp/destination/gurr#{Process.pid.to_s}.rb"
@instance.file(:my_file).source.should == tmp('/source/blah.rbt')
@instance.file(:my_file).destination.should == tmp("/destination/gurr#{Process.pid.to_s}.rb")
@instance.file(:my_file).should be_an_instance_of(Templater::Actions::File)
end

Expand All @@ -42,32 +42,32 @@
file.source = 'blah' / 'blah.rbt'
file.destination = 'gurr' / "gurr#{something}.rb"
end
@instance = @generator_class.new('/tmp/destination')
@instance = @generator_class.new(tmp('destination'))

@instance.stub!(:something).and_return('anotherthing')

@instance.file(:my_file).source.should == '/tmp/source/blah/blah.rbt'
@instance.file(:my_file).destination.should == "/tmp/destination/gurr/gurranotherthing.rb"
@instance.file(:my_file).source.should == tmp('/source/blah/blah.rbt')
@instance.file(:my_file).destination.should == tmp("/destination/gurr/gurranotherthing.rb")
@instance.file(:my_file).should be_an_instance_of(Templater::Actions::File)
end

it "should add a file and convert an instruction encoded in the destination, but not one encoded in the source" do
@generator_class.file(:my_template, 'template/%some_method%.rbt', 'template/%another_method%.rb')
@instance = @generator_class.new('/tmp/destination')
@instance = @generator_class.new(tmp('destination'))

@instance.should_not_receive(:some_method)
@instance.should_receive(:another_method).at_least(:once).and_return('beast')

@instance.file(:my_template).source.should == '/tmp/source/template/%some_method%.rbt'
@instance.file(:my_template).destination.should == "/tmp/destination/template/beast.rb"
@instance.file(:my_template).source.should == tmp('/source/template/%some_method%.rbt')
@instance.file(:my_template).destination.should == tmp("/destination/template/beast.rb")
@instance.file(:my_template).should be_an_instance_of(Templater::Actions::File)
end

it "should add a file and leave an encoded instruction be if it doesn't exist as a method" do
@generator_class.file(:my_template, 'template/blah.rbt', 'template/%some_method%.rb')
@instance = @generator_class.new('/tmp/destination')
@instance = @generator_class.new(tmp('destination'))

@instance.file(:my_template).destination.should == "/tmp/destination/template/%some_method%.rb"
@instance.file(:my_template).destination.should == tmp("/destination/template/%some_method%.rb")
@instance.file(:my_template).should be_an_instance_of(Templater::Actions::File)
end

Expand Down Expand Up @@ -158,18 +158,18 @@

before do
@generator_class = Class.new(Templater::Generator)
@generator_class.stub!(:source_root).and_return('/tmp/source')
@generator_class.stub!(:source_root).and_return(tmp('source'))
end

it "should find a file by name" do
@generator_class.file(:blah1, 'blah.rb')
@generator_class.file(:blah2, 'blah2.rb')

instance = @generator_class.new('/tmp')
instance = @generator_class.new(tmp('tmp'))

instance.file(:blah1).name.should == :blah1
instance.file(:blah1).source.should == '/tmp/source/blah.rb'
instance.file(:blah1).destination.should == '/tmp/blah.rb'
instance.file(:blah1).source.should == tmp('/source/blah.rb')
instance.file(:blah1).destination.should == tmp('/tmp/blah.rb')
end

it "should not return a file with an option that does not match." do
Expand Down
Loading

0 comments on commit 3771000

Please sign in to comment.