Moved the shared 'A working copy against a local repository' behaviour specification to spec/spec_helper.rb. Implemented a single rooted tmp/ for easy cleanup.
git-svn-id: svn+ssh://rubyforge.org/var/svn/piston/trunk@120 d6c2ea82-c31b-0410-8381-e9c44f9824c5
| |   |
| 2 | 2 | require "logger" |
| 3 | 3 | |
| 4 | 4 | $logger = Logger.new($stderr) |
| 5 | | $logger.level = Logger::INFO |
| 5 | $logger.level = Logger::INFO unless $DEBUG |
| 6 | 6 | |
| 7 | 7 | describe "A local repository", :shared => true do |
| 8 | 8 | def logger |
| 9 | 9 | $logger |
| 10 | 10 | end |
| 11 | 11 | |
| 12 | | before do |
| 13 | | @repos_dir = File.expand_path(File.join(File.dirname(__FILE__), "tmp", "repos")) |
| 12 | def tmppath(*paths) |
| 13 | parts = [File.dirname(__FILE__), "tmp"] |
| 14 | parts << (@root_time ||= Time.now.to_i.to_s) |
| 15 | parts += paths |
| 16 | parts << rand().to_s.split(".").last |
| 17 | parts.collect! {|path| path.to_s} |
| 18 | path = File.join(*parts) |
| 19 | attempts = 10 |
| 20 | while File.exists?(path) |
| 21 | path.succ! |
| 22 | attempts -= 1 |
| 23 | raise "Unable to find a good temp pathname: #{path.inspect}" if attempts.zero? |
| 24 | end |
| 25 | |
| 26 | File.expand_path(path) |
| 27 | end |
| 14 | 28 | |
| 15 | | logger.debug {"Removing #{@repos_dir.inspect}"} |
| 16 | | FileUtils.rm_rf(@repos_dir) |
| 29 | before do |
| 30 | @repos_dir = self.tmppath(:repos) |
| 31 | logger.debug {@repos_dir.inspect} |
| 17 | 32 | |
| 18 | 33 | @repos = Piston::Repository.new("file://" + @repos_dir) |
| 19 | 34 | @repos.logger = self.logger |
| 20 | 35 | end |
| 21 | 36 | |
| 22 | 37 | after do |
| 23 | | logger.debug {"Removing #{@repos_dir.inspect}"} |
| 24 | | FileUtils.rm_rf(@repos_dir) |
| 38 | path = File.expand_path(File.join(File.dirname(__FILE__), "tmp")) |
| 39 | logger.debug {"Removing #{path.inspect}"} |
| 40 | FileUtils.rm_rf(path) |
| 41 | end |
| 42 | end |
| 43 | |
| 44 | describe "A working copy against a local repository", :shared => true do |
| 45 | it_should_behave_like "A local repository" |
| 46 | |
| 47 | before do |
| 48 | @repos.create! |
| 49 | |
| 50 | @wcdir = self.tmppath(:wc) |
| 51 | @wc = Piston::WorkingCopy.new(@wcdir) |
| 52 | @wc.logger = self.logger |
| 25 | 53 | end |
| 26 | 54 | end |
| toggle raw diff |
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -2,25 +2,53 @@ require "spec"
require "logger"
$logger = Logger.new($stderr)
-$logger.level = Logger::INFO
+$logger.level = Logger::INFO unless $DEBUG
describe "A local repository", :shared => true do
def logger
$logger
end
- before do
- @repos_dir = File.expand_path(File.join(File.dirname(__FILE__), "tmp", "repos"))
+ def tmppath(*paths)
+ parts = [File.dirname(__FILE__), "tmp"]
+ parts << (@root_time ||= Time.now.to_i.to_s)
+ parts += paths
+ parts << rand().to_s.split(".").last
+ parts.collect! {|path| path.to_s}
+ path = File.join(*parts)
+ attempts = 10
+ while File.exists?(path)
+ path.succ!
+ attempts -= 1
+ raise "Unable to find a good temp pathname: #{path.inspect}" if attempts.zero?
+ end
+
+ File.expand_path(path)
+ end
- logger.debug {"Removing #{@repos_dir.inspect}"}
- FileUtils.rm_rf(@repos_dir)
+ before do
+ @repos_dir = self.tmppath(:repos)
+ logger.debug {@repos_dir.inspect}
@repos = Piston::Repository.new("file://" + @repos_dir)
@repos.logger = self.logger
end
after do
- logger.debug {"Removing #{@repos_dir.inspect}"}
- FileUtils.rm_rf(@repos_dir)
+ path = File.expand_path(File.join(File.dirname(__FILE__), "tmp"))
+ logger.debug {"Removing #{path.inspect}"}
+ FileUtils.rm_rf(path)
+ end
+end
+
+describe "A working copy against a local repository", :shared => true do
+ it_should_behave_like "A local repository"
+
+ before do
+ @repos.create!
+
+ @wcdir = self.tmppath(:wc)
+ @wc = Piston::WorkingCopy.new(@wcdir)
+ @wc.logger = self.logger
end
end |
| |   |
| 3 | 3 | require "piston/repository" |
| 4 | 4 | require "fileutils" |
| 5 | 5 | |
| 6 | | describe "A working copy against a local repository", :shared => true do |
| 7 | | it_should_behave_like "A local repository" |
| 8 | | |
| 9 | | before do |
| 10 | | @repos.create! |
| 11 | | @wcdir = File.expand_path(File.join(File.dirname(__FILE__), "..", "tmp", "wc")) |
| 12 | | FileUtils.rm_rf(@wcdir) |
| 13 | | @wc = Piston::WorkingCopy.new(@wcdir) |
| 14 | | @wc.logger = self.logger |
| 15 | | end |
| 16 | | |
| 17 | | after do |
| 18 | | FileUtils.rm_rf(@wcdir) |
| 19 | | end |
| 20 | | end |
| 21 | | |
| 22 | 6 | describe Piston::WorkingCopy do |
| 23 | 7 | it_should_behave_like "A working copy against a local repository" |
| 24 | 8 | |
| toggle raw diff |
--- a/spec/working_copy_spec.rb
+++ b/spec/working_copy_spec.rb
@@ -3,22 +3,6 @@ require "piston/working_copy"
require "piston/repository"
require "fileutils"
-describe "A working copy against a local repository", :shared => true do
- it_should_behave_like "A local repository"
-
- before do
- @repos.create!
- @wcdir = File.expand_path(File.join(File.dirname(__FILE__), "..", "tmp", "wc"))
- FileUtils.rm_rf(@wcdir)
- @wc = Piston::WorkingCopy.new(@wcdir)
- @wc.logger = self.logger
- end
-
- after do
- FileUtils.rm_rf(@wcdir)
- end
-end
-
describe Piston::WorkingCopy do
it_should_behave_like "A working copy against a local repository"
|