Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added rspec test for InterfaceLift::Installer
- Loading branch information
Showing
8 changed files
with
166 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
module InterfaceLift | |||
class Installer | |||
attr_reader :path, :theme, :theme_path | |||
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) | |||
SHARED = "#{APP_ROOT}/lib/templates/shared" | |||
|
|||
|
|||
def initialize(path,theme) | |||
@path = path | |||
@theme = theme | |||
@theme_path = "#{APP_ROOT}/lib/templates/#{theme}" | |||
|
|||
raise "Given path does not contain a rails app." unless File.directory? "#{@path}/public" | |||
raise "Theme #{@theme} is not available." unless File.directory? @theme_path | |||
end | |||
|
|||
def install! | |||
install_images | |||
install_stylesheets | |||
install_layouts | |||
install_javascript | |||
install_shared | |||
end | |||
|
|||
private | |||
def install_images | |||
FileUtils.cp_r "#{@theme_path}/images","#{path}/public" if File.directory? "#{@theme_path}/images" | |||
end | |||
|
|||
def install_stylesheets | |||
FileUtils.cp_r "#{@theme_path}/stylesheets","#{path}/public" if File.directory? "#{@theme_path}/stylesheets" | |||
end | |||
|
|||
def install_layouts | |||
FileUtils.cp_r "#{@theme_path}/layouts","#{path}/app/views" if File.directory? "#{@theme_path}/layouts" | |||
end | |||
|
|||
def install_javascript | |||
FileUtils.cp_r "#{@theme_path}/javascripts","#{path}/public" if File.directory? "#{@theme_path}/javascripts" | |||
end | |||
|
|||
def install_shared | |||
FileUtils.cp_r "#{SHARED}/icons","#{path}/public/images/" if File.directory? "#{@theme_path}/icons" | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,52 +1,6 @@ | |||
module InterfaceLift | module InterfaceLift | ||
class Installer | VERSION = "0.0.1" | ||
attr_reader :path, :theme, :theme_path | end | ||
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) |
|
||
SHARED = "#{APP_ROOT}/lib/templates/shared" | require "installer" | ||
|
require "theme_manager" | ||
|
|||
def initialize(path,theme) | |||
@path = path | |||
@theme = theme | |||
raise "Not a rails app" unless File.directory? "#{path}/public" | |||
@theme_path = "#{APP_ROOT}/lib/templates/#{theme}" | |||
raise "Theme #{theme} not found" unless File.directory? theme_path | |||
end | |||
|
|||
|
|||
def self.list | |||
Dir.foreach("#{APP_ROOT}/lib/templates") do |t| | |||
puts t unless t == "shared" || t == ".." || t == "." || t == ".DS_Store" | |||
end | |||
end | |||
|
|||
def install! | |||
install_images | |||
install_stylesheets | |||
install_layouts | |||
install_javascript | |||
install_shared | |||
end | |||
|
|||
def install_images | |||
FileUtils.cp_r "#{@theme_path}/images","#{path}/public" if File.directory? "#{@theme_path}/images" | |||
end | |||
|
|||
def install_stylesheets | |||
FileUtils.cp_r "#{@theme_path}/stylesheets","#{path}/public" if File.directory? "#{@theme_path}/stylesheets" | |||
end | |||
|
|||
def install_layouts | |||
FileUtils.cp_r "#{@theme_path}/layouts","#{path}/app/views" if File.directory? "#{@theme_path}/layouts" | |||
end | |||
|
|||
def install_javascript | |||
FileUtils.cp_r "#{@theme_path}/javascripts","#{path}/public" if File.directory? "#{@theme_path}/javascripts" | |||
end | |||
|
|||
def install_shared | |||
FileUtils.cp_r "#{SHARED}/icons","#{path}/public/images/" if File.directory? "#{@theme_path}/icons" | |||
end | |||
|
|||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
module InterfaceLift | |||
class ThemeManager | |||
def available_themes | |||
Dir.foreach("#{APP_ROOT}/lib/templates") do |t| | |||
puts t unless t == "shared" || t == ".." || t == "." || t == ".DS_Store" | |||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,74 @@ | |||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') | |||
include InterfaceLift | |||
describe InterfaceLift::Installer do | |||
|
|||
before(:each) do | |||
@path = "/tmp" | |||
@theme = "test_theme" | |||
@theme_path = "#{GEM_ROOT}/lib/templates/#{@theme}" | |||
end | |||
|
|||
def valid_arguments | |||
File.should_receive(:directory?).with("#{@path}/public").and_return(true) | |||
File.should_receive(:directory?).with(@theme_path).and_return(true) | |||
end | |||
|
|||
describe "Initialization" do | |||
|
|||
it "Should initialize with a theme name and a path" do | |||
valid_arguments | |||
installer = Installer.new(@path,@theme) | |||
installer.theme.should == @theme | |||
installer.path.should == @path | |||
end | |||
|
|||
it "Should raise an error when there the theme is not available" do | |||
File.should_receive(:directory?).with("#{@path}/public").and_return(true) | |||
File.should_receive(:directory?).with(@theme_path).and_return(false) | |||
lambda { Installer.new(@path,@theme) }.should raise_error("Theme #{@theme} is not available.") | |||
end | |||
|
|||
|
|||
it "Should raise an error when the given path does not contain a rails app " do | |||
File.should_receive(:directory?).with("#{@path}/public").and_return(false) | |||
lambda { Installer.new(@path,@theme) }.should raise_error("Given path does not contain a rails app.") | |||
end | |||
end | |||
|
|||
describe "Installing a theme" do | |||
before(:each) do | |||
#don't copy files over! | |||
valid_arguments | |||
@installer = Installer.new(@path,@theme) | |||
File.stub!(:directory?).and_return(true) | |||
FileUtils.stub!(:cp_r) | |||
end | |||
|
|||
after(:each) do | |||
@installer.install! | |||
end | |||
|
|||
it "Should copy over existing images to the RAILS_ROOT/public folder" do | |||
FileUtils.should_receive(:cp_r).with("#{@theme_path}/images","#{@path}/public") | |||
end | |||
|
|||
it "Should copy over existing stylesheets to the RAILS_ROOT/public folder" do | |||
FileUtils.should_receive(:cp_r).with("#{@theme_path}/stylesheets","#{@path}/public") | |||
end | |||
|
|||
it "Should copy over templates to the RAILS_ROOT/app/views/layout folder" do | |||
FileUtils.should_receive(:cp_r).with("#{@theme_path}/layouts","#{@path}/app/views") | |||
end | |||
|
|||
it "Should copy over javascripts to the RAILS_ROOT/public folder" do | |||
FileUtils.should_receive(:cp_r).with("#{@theme_path}/javascripts","#{@path}/public") | |||
end | |||
|
|||
it "Should copy over shared resources to the RAILS_ROOT/public folder" do | |||
FileUtils.should_receive(:cp_r).with("#{GEM_ROOT}/lib/templates/shared/icons","#{@path}/public/images/") | |||
end | |||
|
|||
end | |||
|
|||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |||
|
|||
describe InterfaceLift do | |||
it "Should have a version" do | |||
InterfaceLift::VERSION.should_not be_nil | |||
end | |||
|
|||
it "Should have an Installer class" do | |||
InterfaceLift::Installer.should_not be_nil | |||
end | |||
|
|||
it "Should have an Theme_manager class" do | |||
InterfaceLift::ThemeManager.should_not be_nil | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
--colour | |||
--format | |||
profile | |||
--timeout | |||
20 | |||
--diff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
SPEC_ROOT = File.expand_path(File.dirname(__FILE__)) | |||
$LOAD_PATH << SPEC_ROOT | |||
GEM_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) | |||
|
|||
$LOAD_PATH << "#{GEM_ROOT}/lib" | |||
require "interfacelift" | |||
|
|||
#stubbing and mocking | |||
require 'mocha' |