Skip to content

Commit

Permalink
Fix homebrew specs, refactor a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
wasnotrice committed Jan 30, 2012
1 parent df89689 commit 90d3315
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
36 changes: 30 additions & 6 deletions make/darwin/homebrew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def install package, args=""
end

def installed? package
`#{@brew_command} list`.split.include?(package)
@shell.brew_installed? package
end

def add_custom_formulas
Expand All @@ -77,17 +77,17 @@ def checkout_formula branch, formula

def add_custom_remote remote=@remote, remote_url=@remote_url
cd @brew_home do
unless `#{@git_command} remote`.split.include?(remote)
sh "#{@git_command} remote add #{remote} #{remote_url}"
unless @shell.git_repo_has_remote?(@remote)
@shell.git_remote_add(remote, remote_url)
end
sh "#{@git_command} fetch #{remote}"
@shell.git_fetch(@remote)
end
end

def remove_custom_remote
cd @brew_home do
if `#{@git_command} remote`.split.include?(@remote)
sh "#{@git_command} remote rm #{@remote}"
if @shell.git_repo_has_remote?(@remote)
@shell.git_remote_rm(@remote)
end
end
end
Expand All @@ -98,7 +98,31 @@ def sh command
end

class ShellCommandRunner
def initialize
@git_command = ENV['GIT'] || "git"
end

def run command
system command
end

def brew_installed? package
`#{@brew_command} list`.split.include?(package)
end

def git_fetch remote
run "#{@git_command} fetch #{remote}"
end

def git_remote_add remote, remote_url
sh "#{@git_command} remote add #{remote} #{remote_url}"
end

def git_remote_rm remote
`#{@git_command} remote rm #{remote}`
end

def git_repo_has_remote? remote
`#{@git_command} remote`.split.include?(remote)
end
end
13 changes: 9 additions & 4 deletions spec/homebrew_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
end

it "should install a new package" do
brew.stub(:installed?) {false}
shell.stub(:brew_installed?) {false}
shell.should_receive(:run).with "brew install cairo"
brew.install "cairo"
end
Expand All @@ -25,17 +25,22 @@
end

it "should add a custom remote" do
shell.should_receive(:run).with "git fetch shoes"
remote = "shoes"
remote_url = "https://github.com/wasnotrice/homebrew.git"
shell.stub(:git_repo_has_remote?) { false }
shell.should_receive(:git_remote_add).with(remote, remote_url)
shell.should_receive(:git_fetch).with(remote)
brew.add_custom_remote
end

it "should remove custom remote" do
shell.should_receive(:run).with "git remote rm shoes"
shell.stub(:git_repo_has_remote?) { true }
shell.should_receive(:git_remote_rm).with 'shoes'
brew.remove_custom_remote
end

it "should checkout custom formulas" do
branch = "quartz"
branch = "shoes"
brew.custom_formulas.each do |f|
shell.should_receive(:run).with "git checkout shoes/#{branch} Library/Formula/#{f}.rb"
end
Expand Down

0 comments on commit 90d3315

Please sign in to comment.