Permalink
Browse files

made first crack at specs

  • Loading branch information...
latimes committed Aug 16, 2008
1 parent 4e78120 commit 7dab796e2587be92311bfedb1737c5d9d1635a05
Showing with 74 additions and 7 deletions.
  1. +74 −7 spec/craken_spec.rb
View
@@ -1,5 +1,6 @@
RAILS_ROOT = "foo/bar/baz"
RAILS_ENV = "test"
+ENV['app_name'] = "craken_test"
require File.dirname(__FILE__) + "/../lib/craken"
@@ -8,16 +9,82 @@
include Craken
describe "load_and_strip" do
- it "should load the user's installed crontab"
- it "should strip out preinstalled raketab commands associated with the project"
- it "should not strip out preinstalled raketab commands not associated with the project"
+
+ it "should load the user's installed crontab" do
+ # figured out how to do this from here:
+ # http://jakescruggs.blogspot.com/2007/11/mocking-backticks-and-other-kernel.html
+ self.should_receive(:`).with(/crontab -l/).and_return('')
+ load_and_strip
+ end
+
+ it "should strip out preinstalled raketab commands associated with the project" do
+
+crontab = <<EOS
+### craken_test raketab
+this is a test
+one more line
+### craken_test raketab end
+EOS
+
+ self.should_receive(:`).with(/crontab -l/).and_return(crontab)
+ load_and_strip.should be_empty
+ end
+
+ it "should not strip out preinstalled raketab commands not associated with the project" do
+
+crontab = <<EOS
+1 2 3 4 5 blah blah
+### craken_test raketab
+this is a test
+one more line
+### craken_test raketab end
+6 7 8 9 10 foo bar
+EOS
+
+ self.should_receive(:`).with(/crontab -l/).and_return(crontab)
+ load_and_strip.should == "1 2 3 4 5 blah blah\n6 7 8 9 10 foo bar\n"
+ end
end
describe "append_tasks" do
- it "should add comments to the beginning and end of the rake tasks it adds to crontab"
- it "should ignore comments in the raketab string"
- it "should not munge the crontab time configuration"
- it "should add a cd command"
+ before(:each) do
+ @crontab = "1 2 3 4 5 blah blah\n6 7 8 9 10 foo bar\n"
+ end
+
+ it "should add comments to the beginning and end of the rake tasks it adds to crontab" do
+ raketab = "0 1 0 0 0 foo:bar"
+ cron = append_tasks(@crontab, raketab)
+ cron.should match(/### craken_test raketab\n0 1 0 0 0 /)
+ cron.should match(/### craken_test raketab end\n$/)
+ end
+
+ it "should ignore comments in the raketab string" do
+raketab = <<EOS
+# comment to ignore
+0 1 0 0 0 foo:bar
+# another comment to ignore
+EOS
+ cron = append_tasks(@crontab, raketab)
+ cron.should_not match(/# comment to ignore/)
+ cron.should_not match(/# another comment to ignore/)
+ end
+
+ it "should not munge the crontab time configuration" do
+raketab = <<EOS
+0 1 0 0 0 foo:bar
+1,2,3,4,5,6 0 7,8 4 5 baz:blarg
+EOS
+ cron = append_tasks(@crontab, raketab)
+ cron.should match(/0 1 0 0 0 [^\d]/)
+ cron.should match(/1,2,3,4,5,6 0 7,8 4 5 [^\d]/)
+ end
+
+ it "should add a cd command" do
+ raketab = "0 1 0 0 0 foo:bar"
+ cron = append_tasks(@crontab, raketab)
+ cron.should match(/0 1 0 0 0 cd /)
+ end
+
it "should add the rake command"
it "should add the rails environment value"
it "should ignore additional data at the end of the configuration"

0 comments on commit 7dab796

Please sign in to comment.