Permalink
Browse files

starting TDD approach

  • Loading branch information...
1 parent 3b65870 commit 4bc60a4520677193cdcd83b357a618c2b8e0f2fe @grosser grosser committed May 18, 2009
View
@@ -0,0 +1,6 @@
+desc "Run all specs in spec directory"
+task :default do |t|
+ options = "--colour --format progress --loadby --reverse"
+ files = FileList['spec/**/*_spec.rb']
+ system("spec #{options} #{files}")
+end
View
@@ -0,0 +1,11 @@
+module ParallelSpecs
+ extend self
+
+ def with_copied_envs(root, num_processes)
+ envs = []
+ 2.upto(num_processes){|i| envs << "#{root}/config/environments/test#{i}.rb"}
+ envs.each{|f| `cp #{root}/config/environments/test.rb #{f}`}
+ yield
+ envs.each{|f| `rm #{f}`}
+ end
+end
No changes.
@@ -0,0 +1,57 @@
+require File.dirname(__FILE__)+'/spec_helper'
+
+FAKE_RAILS_ROOT = File.dirname(__FILE__)+'/fixtures/'
+
+describe ParallelSpecs do
+ def fixture_exist? file
+ File.exist?(FAKE_RAILS_ROOT+file)
+ end
+
+ describe :with_copied_envs do
+ it "calls the given block" do
+ x = 'block not called'
+ ParallelSpecs.with_copied_envs(FAKE_RAILS_ROOT, 2) do
+ x = 'block called'
+ end
+ x.should == 'block called'
+ end
+
+ it "copies env files for each parallel process" do
+ ParallelSpecs.with_copied_envs(FAKE_RAILS_ROOT, 3) do
+ fixture_exist?('config/environments/test1.rb').should == false
+ fixture_exist?('config/environments/test2.rb').should == true
+ fixture_exist?('config/environments/test3.rb').should == true
+ fixture_exist?('config/environments/test4.rb').should == false
+ end
+ end
+
+ it "overwrites existing envs with new copies" do
+ env2 = FAKE_RAILS_ROOT+'config/environments/test2.rb'
+ File.open(env2,'w'){|f|f.print 'XXX'}
+
+ ParallelSpecs.with_copied_envs(FAKE_RAILS_ROOT, 3) do
+ File.read(env2).should_not == "XXX"
+ end
+ end
+
+ it "adds comments to the copied files" do
+ env2 = FAKE_RAILS_ROOT+'config/environments/test2.rb'
+ File.open(env2,'w'){|f|f.print 'XXX'}
+
+ ParallelSpecs.with_copied_envs(FAKE_RAILS_ROOT, 3) do
+ pending
+ File.readlines(env2)[0].should =~ /^#.*OVERWRITTEN/
+ end
+ end
+
+ it "removes all env files after processing the block" do
+ ParallelSpecs.with_copied_envs(FAKE_RAILS_ROOT, 3) do
+ end
+
+ fixture_exist?('config/environments/test1.rb').should == false
+ fixture_exist?('config/environments/test2.rb').should == false
+ fixture_exist?('config/environments/test3.rb').should == false
+ fixture_exist?('config/environments/test4.rb').should == false
+ end
+ end
+end
View
@@ -0,0 +1,3 @@
+# ---- requirements
+$LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
+require 'parallel_specs'

0 comments on commit 4bc60a4

Please sign in to comment.