Added tests for the install generator.

This commit is contained in:
nathanvda 2011-07-24 00:54:15 +02:00
parent 6d261ef37c
commit e410388bd6
4 changed files with 58 additions and 9 deletions

View File

@ -10,6 +10,8 @@ group :development, :test do
gem "rspec", ">= 2.6.0"
gem "actionpack", ">=3.0.0"
gem "simplecov", :require => false
gem "generator_spec"
end
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)

View File

@ -33,6 +33,9 @@ GEM
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
generator_spec (0.8.3)
rails (~> 3.0)
rspec-rails
git (1.2.5)
i18n (0.5.0)
jeweler (1.6.2)
@ -95,6 +98,7 @@ PLATFORMS
DEPENDENCIES
actionpack (>= 3.0.0)
generator_spec
jeweler
json_pure
rails (>= 3.0.0)

View File

@ -3,16 +3,12 @@ module Cocoon
class InstallGenerator < ::Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1
# for Rails 3.1 no installing is needed anymore, because of the asset pipeline
desc "Installing is only needed for rails 3.0.x"
def do_nothing
desc "This generator installs the javascript needed for cocoon"
def copy_the_javascript
if ::Rails.version[0..2].to_f >= 3.1
puts "Installing is no longer required since Rails 3.1"
end
else
desc "This generator installs the javascript needed for cocoon"
def copy_the_javascript
copy_file "../../../app/assets/javascripts/cocoon.js", "public/javascripts/cocoon.js"
else
copy_file "../../../../../app/assets/javascripts/cocoon.js", "public/javascripts/cocoon.js"
end
end

View File

@ -0,0 +1,47 @@
require 'spec_helper'
require 'generator_spec/test_case'
require 'generators/cocoon/install/install_generator'
describe Cocoon::Generators::InstallGenerator do
include GeneratorSpec::TestCase
destination File.expand_path("../../tmp", __FILE__)
context "in rails 3.0" do
context "with no arguments" do
before(:all) do
::Rails.stub(:version) { '3.0.8' }
prepare_destination
run_generator
end
it "stubs the version correctly" do
Rails.version[0..2].should == "3.0"
end
it "stubs the version correctly" do
test_version = (Rails.version[0..2].to_f >= 3.1)
test_version.should be_false
end
it "copies cocoon.js to the correct folder" do
assert_file "public/javascripts/cocoon.js"
end
end
end
context "in rails 3.1" do
context "with no arguments" do
before(:all) do
::Rails.stub(:version) { '3.1.0' }
prepare_destination
run_generator
end
it "does not copy cocoon.js" do
assert_no_file "public/javascripts/cocoon.js"
end
end
end
end