Permalink
Browse files

added rspec test for InterfaceLift::Installer

  • Loading branch information...
1 parent 8e19c8f commit 3838cd5d0e17eee99a53e8165cdf44d825458fbc @michel committed Oct 21, 2009
Showing with 166 additions and 52 deletions.
  1. +2 −1 bin/interfacelift
  2. +46 −0 lib/installer.rb
  3. +5 −51 lib/interfacelift.rb
  4. +9 −0 lib/theme_manager.rb
  5. +74 −0 spec/installer_spec.rb
  6. +15 −0 spec/interfacelift_spec.rb
  7. +6 −0 spec/spec.opts
  8. +9 −0 spec/spec_helper.rb
View
@@ -32,7 +32,8 @@ command :list do |c|
c.description = 'shows a list of all available themes'
c.action do |args, options|
begin
- InterfaceLift::Installer.list
+ manager = InterfaceLift::ThemeManager.new
+ manager.available_themes
rescue Exception => e
puts e
end
View
@@ -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
View
@@ -1,52 +1,6 @@
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
- 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
+ VERSION = "0.0.1"
+end
+
+require "installer"
+require "theme_manager"
View
@@ -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
View
@@ -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
View
@@ -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
View
@@ -0,0 +1,6 @@
+--colour
+--format
+profile
+--timeout
+20
+--diff
View
@@ -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'

0 comments on commit 3838cd5

Please sign in to comment.