Permalink
Browse files

Increase test coverage and extract install command into Brewdler::Com…

…mands::Install
  • Loading branch information...
1 parent c10038d commit 8994d8b2fddcbe77f0772e132a166bd2a8474b53 @jamesaanderson jamesaanderson committed with jamesaanderson Jun 26, 2013
View
@@ -11,17 +11,6 @@ default_command :install
command :install do |c|
c.description = 'Install all homebrew based dependecies'
c.action do |args, options|
- begin
- file = File.read(File.join(Dir.pwd, "Brewfile"))
- Brewdler::Dsl.new(file).process
- rescue Errno::ENOENT => e
- raise "No Brewfile found\n#{e.message}"
- rescue NameError
- file = File.open(File.join(Dir.pwd, "Brewfile"))
- file.find_all do |name|
- name.chomp!
- Brewdler::BrewInstaller.install(name) if name.length > 0 && name !~ /^ *#/
- end
- end
+ Brewdler::Commands::Install.run
end
end
View
@@ -2,3 +2,4 @@
require "brewdler/dsl"
require "brewdler/brew_installer"
require "brewdler/cask_installer"
+require "brewdler/commands/install"
@@ -1,7 +1,11 @@
module Brewdler
class BrewInstaller
def self.install(name)
- `brew install #{name}`
+ if system 'brew info'
@josh
josh Jan 28, 2015

After this change, brew info garbage will print out to the screen instead of being captured.

+ `brew install #{name}`
+ else
+ raise "Unable to install #{name}. Homebrew is not currently installed on your system."
+ end
end
end
end
@@ -1,7 +1,11 @@
module Brewdler
class CaskInstaller
def self.install(name)
- `brew cask install #{name}`
+ if system 'brew cask info'
+ `brew cask install #{name}`
+ else
+ raise "Unable to install #{name}. Homebrew-cask is not currently installed on your system"
+ end
end
end
end
@@ -0,0 +1,18 @@
+module Brewdler::Commands
+ class Install
+ def self.run
+ begin
+ file = File.read(File.join(Dir.pwd, "Brewfile"))
+ Brewdler::Dsl.new(file).process
+ rescue Errno::ENOENT => e
+ raise "No Brewfile found."
+ rescue NameError
+ file = File.open(File.join(Dir.pwd, "Brewfile"))
+ file.find_all do |name|
+ name.chomp!
+ Brewdler::BrewInstaller.install(name) if name.length > 0 && name !~ /^ *#/
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe Brewdler::Commands::Install do
+ context "when a Brewfile is not found" do
+ it "raises an error" do
+ expect { Brewdler::Commands::Install.run }.to raise_error
+ end
+ end
+
+ context "when a Brewfile is found" do
+ it "does not raise an error" do
+ File.stub(:read).and_return("brew 'git'")
+ expect { Brewdler::Commands::Install.run }.to_not raise_error('No Brewfile found.')
+
+ File.stub(:read).and_return('git')
+ File.stub(:open).and_return(['git'])
+ expect { Brewdler::Commands::Install.run }.to_not raise_error('No Brewfile found.')
+ end
+ end
+end

0 comments on commit 8994d8b

Please sign in to comment.