Permalink
Browse files

Added tests for the install generator.

  • Loading branch information...
1 parent 6d261ef commit e410388bd63dc19bbc7e7ef85eeaa64eb42bf538 @nathanvda committed Jul 23, 2011
Showing with 58 additions and 9 deletions.
  1. +2 −0 Gemfile
  2. +4 −0 Gemfile.lock
  3. +5 −9 lib/generators/cocoon/install/install_generator.rb
  4. +47 −0 spec/generators/install_generator_spec.rb
View
2 Gemfile
@@ -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
4 Gemfile.lock
@@ -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
14 lib/generators/cocoon/install/install_generator.rb
@@ -3,16 +3,12 @@ module Generators
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
47 spec/generators/install_generator_spec.rb
@@ -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

0 comments on commit e410388

Please sign in to comment.