From b4e79b5daa16c1a25ea111b167487a0ba2001f14 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 31 Aug 2011 14:11:05 -0400 Subject: [PATCH] rake support --- lib/penchant/dot_penchant.rb | 12 ++++++++++++ spec/lib/penchant/dot_penchant_spec.rb | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/penchant/dot_penchant.rb b/lib/penchant/dot_penchant.rb index 7bfbfbe..7174201 100644 --- a/lib/penchant/dot_penchant.rb +++ b/lib/penchant/dot_penchant.rb @@ -11,6 +11,18 @@ module Penchant def run(env = nil) instance_eval(File.read('.penchant')) end + + def rake(*tasks) + command = [ "rake", *tasks ] + command.unshift("bundle exec") if gemfile? + Kernel.system command.join(' ') + end + + private + def gemfile? + File.file?('Gemfile') + end + end end diff --git a/spec/lib/penchant/dot_penchant_spec.rb b/spec/lib/penchant/dot_penchant_spec.rb index 73bf0cc..8be4d9e 100644 --- a/spec/lib/penchant/dot_penchant_spec.rb +++ b/spec/lib/penchant/dot_penchant_spec.rb @@ -16,5 +16,30 @@ describe Penchant::DotPenchant do dot_file.instance_variable_get(:@did_run).should == :this end end + + let(:dot_file) { described_class.new } + + describe '#rake' do + context 'without Gemfile' do + before do + Kernel.expects(:system).with('rake task1 task2') + end + + it 'should run the rake task via system' do + dot_file.rake("task1", "task2") + end + end + + context 'with Gemfile' do + before do + File.open('Gemfile', 'wb') + Kernel.expects(:system).with('bundle exec rake task1 task2') + end + + it 'should run the rake task via system' do + dot_file.rake("task1", "task2") + end + end + end end