Skip to content

Instantly share code, notes, and snippets.

@elcontrastador
Created August 26, 2011 03:39
Show Gist options
  • Save elcontrastador/1172630 to your computer and use it in GitHub Desktop.
Save elcontrastador/1172630 to your computer and use it in GitHub Desktop.
module Company
class ClientDirs
attr_reader :template_path, :dest_base_path, :client_domain
#takes Pathname objects as initial params
def initialize(client_template_path, dest_base_path)
@template_path = client_template_path
@dest_base_path = dest_base_path
@client_domain = ""
end
def template_exists?
template_path.directory?
end
def dest_base_path_exists?
dest_base_path.directory?
end
def client_domain=(client_domain)
@client_domain = client_domain.downcase
end
def client_domain_valid?
case client_domain
when /[^-a-z0-9.]/ then false
when /[.](com|net|edu|gov|org|biz|tv)$/ then true
else false
end
end
def client_dir_path
dest_base_path + client_domain
end
def client_dir_exists?
client_dir_path.directory? # what's the best way to restructure this code to mock this?
end
end
end
### spec below ####
require 'spec_helper'
describe Company::ClientDirs do
context "the destination directory methods" do
let(:ocd) do
dest_base_path = double('dest_base_path')
dest_base_path.stub(:directory?).and_return(true)
dest_base_path.stub(:to_s).and_return(DEST_BASE_PATH)
dest_base_path.stub("+").and_return(DEST_BASE_PATH + "/#{CLIENT_DOMAIN}")
Company::ClientDirs.new(CLIENT_DIR_TEMPL,dest_base_path)
end
it "should return the client dir path" do
ocd.client_dir_path.should == DEST_BASE_PATH + "/#{CLIENT_DOMAIN}"
end
it "should determine whether the client destination dir exists" do
ocd.client_dir_exists?.should be_false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment