Permalink
Browse files

handle the case where dont have any rails gem installed, and also fix…

… autotest for latest config style

git-svn-id: https://opensource.thinkrelevance.com/svn/multi_rails/trunk@112 fe6a39be-99a9-dc11-9a70-001c23e17821
  • Loading branch information...
1 parent b8c69d4 commit e361bafccb68eff23cb695ef2ae2350619d4b25f rob committed Jan 27, 2008
Showing with 41 additions and 8 deletions.
  1. +19 −2 .autotest
  2. +4 −0 History.txt
  3. +1 −1 lib/multi_rails.rb
  4. +6 −0 lib/multi_rails/loader.rb
  5. +0 −4 test/autotest/railsplugin.rb
  6. +11 −1 test/loader_test.rb
View
@@ -1,6 +1,23 @@
require 'autotest'
$LOAD_PATH.unshift "test", "test/autotest"
# Make sure autotest groks our directory structure to map tests to files
-Autotest.add_discovery do
- ["railsplugin"]
+p 'here!'
+
+Autotest.add_hook :initialize do |at|
+ at.add_mapping(/^lib\/(.*)\.rb$/) { |filename, m|
+ file = File.basename(filename).gsub("_", "_?").gsub(".rb", "")
+ foo = at.files_matching %r%^test/.*#{file}_test.rb$%
+ foo
+ }
+
+ at.add_mapping(/^test\/.*_test\.rb$/) { |filename, _|
+ filename
+ }
+
+ #
+ #
+ # at.add_mapping(%r%^plugins/acts_as_currency/lib/.*\.rb$%) {
+ # at.files_matching %r%^spec/models/product_spec\.rb$% +
+ # at.files_matching %r%^plugins/acts_as_currency/spec/.*_spec\.rb$%
+ # }
end
View
@@ -1,3 +1,7 @@
+== 0.0.5
+
+* Handle the case where we don't have any Rails gems installed at all by raising early to prevent weirdness later on (Evan Weaver)
+
== 0.0.4
* Change the all task so that the build will run through all rails versions, even if one of them fails, but at the end
View
@@ -6,7 +6,7 @@
end
module MultiRails
- VERSION = '0.0.4'
+ VERSION = '0.0.5'
BAR = "=" * 80 # BEST CONSTANT EVAH
def self.gem_and_require_rails
@@ -10,6 +10,7 @@ def self.logger
# Require and gem rails
# Will use a default version if none is supplied
def self.gem_and_require_rails(rails_version = nil)
+ verify_rails_installed
rails_version = MultiRails::Config.version_lookup(rails_version)
Loader.new(rails_version).gem_and_require_rails
end
@@ -31,6 +32,11 @@ def self.latest_version
all_rails_versions.sort.last
end
+ # Verify we have at least one Rails gem installed, otherwise fail early
+ def self.verify_rails_installed
+ raise MultiRailsError, "No Rails gems installed!" if Gem::cache.find_name("rails").empty?
+ end
+
# A version of the loader is created to gem and require one version of Rails
def initialize(version)
@version = version
@@ -5,12 +5,8 @@ def initialize
@exceptions = /\/\./
@test_mappings = {
/^lib\/(.*)\.rb$/ => proc { |filename, m|
- # p "match #{m[1]}"
file = File.basename(filename).gsub("_", "_?").gsub(".rb", "")
foo = files_matching %r%^test/.*#{file}_test.rb$%
- # p "the file: #{file}"
- # p "the regex: #{files_matching %r%^test/.*#{file}_test.rb$%}"
- # p "files_matching: #{foo}"
foo
},
/^test\/.*_test\.rb$/ => proc { |filename, _|
View
@@ -1,10 +1,19 @@
require File.expand_path(File.join(File.dirname(__FILE__), "multi_rails_test_helper"))
-describe "loader" do
+describe "Loader with no Rails gem installed" do
+
+ it "should fail fast if we don't have any rails gems installed" do
+ Gem::cache.expects(:find_name).with("rails").returns([])
+ lambda { MultiRails::Loader.gem_and_require_rails }.should.raise(MultiRailsError).message.should == "No Rails gems installed!"
+ end
+
+end
+describe "Loader with at least one Rails gem installed" do
setup do
never_really_require_rails
never_puts
+ MultiRails::Loader.stubs(:verify_rails_installed).returns(nil)
end
it "should fall back to a default version to try" do
@@ -20,6 +29,7 @@
it "should gem the specified version" do
MultiRails::Loader.any_instance.stubs(:display_rails_gem_used)
+ MultiRails::Config.stubs(:named_version_lookup).with("1.2.5").returns("1.2.5")
stub_rails_requires
MultiRails::Loader.any_instance.expects(:gem).with("rails", "1.2.5").returns(true)
MultiRails::Loader.gem_and_require_rails("1.2.5")

0 comments on commit e361baf

Please sign in to comment.