Permalink
Browse files

fixed tests, changed mocking framework in rspec for mocha

  • Loading branch information...
1 parent d7794b7 commit 131f7f5df16e3950d5ee3dbb05e2941e217d471b @michel committed Nov 18, 2009
Showing with 41 additions and 37 deletions.
  1. +23 −12 spec/catalog_spec.rb
  2. +0 −8 spec/fetcher_spec.rb
  3. +13 −13 spec/installer_spec.rb
  4. +5 −4 spec/spec_helper.rb
View
@@ -3,7 +3,9 @@
include InterfaceLift
describe Catalog do
-
+ before(:all) do
+ FileUtils.stubs(:mkdir_p)
+ end
context "Initialize" do
it "should initialize with a path that contains the users current themes" do
@@ -39,25 +41,25 @@
context "Updating a theme from a git repo" do
before(:each) do
- @git_mock = mock(Git, :repo => mock("git", :path => "fakepath"))
- Git.stub!(:open).and_return(@git_mock)
+ @git_mock = mock('Git', :repo => mock("git", :path => "fakepath"))
+ Git.stubs(:open).returns(@git_mock)
end
it "should return true when its updated" do
- @git_mock.expects(:pull).returns("Updating 35d573d..546fee5")
+ @git_mock.stubs(:pull).returns("Updating 35d573d..546fee5")
@cat.update_theme("test_theme2").should == true
end
it "should return false when there are no updates" do
- @git_mock.expects(:pull).returns("Already up-to-date.")
+ @git_mock.stubs(:pull).returns("Already up-to-date.")
@cat.update_theme("test_theme2").should == false
end
end
it "should check if the directory contains a git repo" do
- @git_mock = mock(Git, :repo => mock("git", :path => "fakepath"))
- Git.stub!(:open).and_return(@git_mock)
+ @git_mock = mock('Git', :repo => mock("git", :path => "fakepath"))
+ Git.stubs(:open).returns(@git_mock)
@cat.git_repo?("test_theme2").should == true
end
@@ -67,27 +69,36 @@
end
it "should download theme from a remote repository" do
- @git_mock = mock(Git, :repo => mock("git", :path => "fakepath"))
- Git.stub!(:clone).and_return(@git_mock)
+ @git_mock = mock('Git', :repo => mock("git", :path => "fakepath"))
+ Git.stubs(:clone).returns(@git_mock)
@cat.add_theme("mysweettheme", "git://mysickgit.git").should == true
end
end
context "Removing a theme" do
it "should remove a theme and return true" do
- @cat.stub!(:theme_exists?).and_return(true)
+ @cat.stubs(:theme_exists?).returns(true)
theme_name = "non_existing_theme"
- FileUtils.stub!(:rm_rf).with("#{@cat.catalog_path}/#{theme_name}").and_return(true)
+ FileUtils.stubs(:rm_rf).with("#{@cat.catalog_path}/#{theme_name}").returns(true)
@cat.remove_theme(theme_name).should == true
end
it "should return false when a theme doesn't exist in catalog" do
- @cat.stub!(:theme_exists?).and_return(false)
+ @cat.stubs(:theme_exists?).returns(false)
theme_name = "non_existing_theme"
@cat.remove_theme(theme_name).should == false
end
end
+ end
+
+
+ it "should create the catalog folder when it does not exists" do
+ non_existing_path = "no_path"
+ File.expects(:exists?).with(non_existing_path)
+ FileUtils.expects(:mkdir_p).with(non_existing_path)
+ @new_cat = Catalog.new(non_existing_path)
+ #@new_cat.create_catalog_path!
end
@@ -2,12 +2,4 @@
include InterfaceLift
describe Fetcher do
- it "should work" do
- object = mock()
- object.expects(:expected_method).at_least(9001)
- 3.times { object.expected_method }
- object = mock()
- object.expects(:expected_method).at_least(2)
- object.expected_method
- end
end
@@ -9,8 +9,8 @@
end
def valid_arguments
- File.should_receive(:directory?).with("#{@path}/public").and_return(true)
- File.should_receive(:directory?).with(@theme_path).and_return(true)
+ File.expects(:directory?).with("#{@path}/public").returns(true)
+ File.expects(:directory?).with(@theme_path).returns(true)
end
describe "Initialization" do
@@ -23,14 +23,14 @@ def valid_arguments
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)
+ File.expects(:directory?).with("#{@path}/public").returns(true)
+ File.expects(:directory?).with(@theme_path).returns(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)
+ File.expects(:directory?).with("#{@path}/public").returns(false)
lambda { Installer.new(@path,@theme) }.should raise_error("Given path does not contain a rails app.")
end
end
@@ -40,9 +40,9 @@ def valid_arguments
#don't copy files over!
valid_arguments
@installer = Installer.new(@path,@theme)
- File.stub!(:directory?).and_return(true)
- Dir.stub!(:glob).and_return([])
- FileUtils.stub!(:cp_r)
+ File.stubs(:directory?).returns(true)
+ Dir.stubs(:glob).returns([])
+ FileUtils.stubs(:cp_r)
end
after(:each) do
@@ -51,23 +51,23 @@ def valid_arguments
end
it "Should copy over existing images to the RAILS_ROOT/public folder" do
- FileUtils.should_receive(:cp_r).with("#{@theme_path}/public/images","#{@path}/public")
+ FileUtils.expects(:cp_r).with("#{@theme_path}/public/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}/public/stylesheets","#{@path}/public")
+ FileUtils.expects(:cp_r).with("#{@theme_path}/public/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}/app/views/layouts","#{@path}/app/views")
+ FileUtils.expects(:cp_r).with("#{@theme_path}/app/views/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}/public/javascripts","#{@path}/public")
+ FileUtils.expects(:cp_r).with("#{@theme_path}/public/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/")
+ FileUtils.expects(:cp_r).with("#{GEM_ROOT}/lib/templates/shared/icons","#{@path}/public/images/")
end
end
View
@@ -4,7 +4,8 @@
$LOAD_PATH << "#{GEM_ROOT}/lib"
require "interfacelift"
-
-require 'rubygems'
-#stubbing and mocking
-require 'mocha'
+#gem "mocha"
+
+Spec::Runner.configure do |config|
+ config.mock_with :mocha
+end

0 comments on commit 131f7f5

Please sign in to comment.