MultiRails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ == 0.0.1 / Sunday; October 21, 2007
2
+
3
+ * initial public release
@@ -0,0 +1,16 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ init.rb
6
+ lib/multi_rails.rb
7
+ lib/multi_rails/config.rb
8
+ lib/multi_rails/core_extensions.rb
9
+ lib/multi_rails/loader.rb
10
+ lib/multi_rails/multi_rails_error.rb
11
+ tasks/multi_rails.rake
12
+ test/config_test.rb
13
+ test/core_extensions_test.rb
14
+ test/init_test.rb
15
+ test/loader_test.rb
16
+ test/multi_rails_test_helper.rb
@@ -0,0 +1,58 @@
1
+ MultiRails
2
+ by Relevance, http://thinkrelevance.com
3
+
4
+ == DESCRIPTION:
5
+
6
+ MultiRails easily allows testing against multiple versions of Rails.
7
+
8
+ MultiRails was initially developed by members of Relevance while developing Streamlined
9
+ against edge Rails. To see how Streamlined uses MultiRails, go to http://streamlinedframework.org.
10
+
11
+ == FEATURES/PROBLEMS:
12
+
13
+ * easily test plugins/extensions to Rails using a one line require from your test_helper.rb
14
+ * rake tasks to test against a specific version of Rails, or all versions of Rails available locally as Gems
15
+
16
+ == TODOs:
17
+
18
+ * enable multi_rails testing in a plain ole' Rails app -- this is difficult right now because of the Rails boot process
19
+
20
+ == REQUIREMENTS:
21
+
22
+ * Ruby 1.8.5 or higher
23
+ * Rubygems
24
+ * Rails 1.2.1 or higher
25
+ * at least one copy of Rails installed via rubygems.
26
+
27
+ == INSTALL:
28
+
29
+ * sudo gem install multi_rails
30
+ * in your test_helper.rb, require the multi_rails init file -- your specific path may differ
31
+ require File.expand_path(File.join(File.dirname(__FILE__), "/multi_rails/init"))
32
+ * IMPORTANT: you _must_ require multi_rails before you require any Rails files
33
+
34
+
35
+ == LICENSE:
36
+
37
+ (The MIT License)
38
+
39
+ Copyright (c) 2007 Relevance, http://thinkrelevance.com
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining
42
+ a copy of this software and associated documentation files (the
43
+ 'Software'), to deal in the Software without restriction, including
44
+ without limitation the rights to use, copy, modify, merge, publish,
45
+ distribute, sublicense, and/or sell copies of the Software, and to
46
+ permit persons to whom the Software is furnished to do so, subject to
47
+ the following conditions:
48
+
49
+ The above copyright notice and this permission notice shall be
50
+ included in all copies or substantial portions of the Software.
51
+
52
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
53
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
54
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
55
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
56
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
57
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
58
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+ require File.expand_path(File.join(File.dirname(__FILE__), "/lib/multi_rails"))
4
+ load File.expand_path(File.join(File.dirname(__FILE__), "/tasks/multi_rails.rake"))
5
+
6
+ Hoe.new('MultiRails', MultiRails::VERSION) do |p|
7
+ p.rubyforge_name = 'multi-rails'
8
+ p.author = 'Relevance'
9
+ p.email = ''
10
+ p.summary = 'Testing tool to easily test agaist multiple versions of Rails.'
11
+ p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
12
+ p.url = 'http://multi-rails.rubyforge.org/'
13
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
14
+ p.remote_rdoc_dir = '' # Release to root
15
+ p.test_globs = 'test/**/*_test.rb' # we use the foo_test convention
16
+ end
data/init.rb ADDED
@@ -0,0 +1,4 @@
1
+ if Object.const_defined?("RAILS_ENV") && RAILS_ENV == "test"
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "lib/multi_rails"))
3
+ MultiRails::require_rails
4
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'logger'
3
+ files = %w(core_extensions config loader multi_rails_error)
4
+ files.each do |file|
5
+ require File.expand_path(File.join(File.dirname(__FILE__), "multi_rails/#{file}"))
6
+ end
7
+
8
+ module MultiRails
9
+ VERSION = '0.0.1'
10
+
11
+ def self.require_rails
12
+ Loader.require_rails
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ module MultiRails
2
+
3
+ # Simple config object
4
+ class Config
5
+ @weird_versions = { "2.0.0.PR" => "1.2.4.7794" }
6
+ @rails_requires = %w[active_record
7
+ action_controller
8
+ action_controller/test_process
9
+ active_support]
10
+
11
+ class << self
12
+ attr_accessor :weird_versions, :rails_requires
13
+ def version_lookup(version = nil)
14
+ return named_version_lookup(version) if version
15
+ return named_version_lookup(ENV["RAILS_VERSION"]) if ENV['RAILS_VERSION']
16
+ Loader.latest_stable_version
17
+ end
18
+
19
+ def named_version_lookup(pretty_version)
20
+ version = @weird_versions[pretty_version] || pretty_version
21
+ raise MultiRailsError, "Can't find Rails gem version #{pretty_version} - available versions are: #{Loader.all_rails_versions.to_sentence})." if !Loader.all_rails_versions.include? version
22
+ version
23
+ end
24
+
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,44 @@
1
+ # Add some nice to haves from ActiveSupport
2
+
3
+ module Kernel
4
+ def silence_warnings
5
+ old_verbose, $VERBOSE = $VERBOSE, nil
6
+ yield
7
+ ensure
8
+ $VERBOSE = old_verbose
9
+ end
10
+ end
11
+
12
+ module HashExtensions
13
+ def reverse_merge(other_hash)
14
+ other_hash.merge(self)
15
+ end
16
+
17
+ def reverse_merge!(other_hash)
18
+ replace(reverse_merge(other_hash))
19
+ end
20
+ end
21
+
22
+ module ArrayExtensions
23
+ # Converts the array to comma-seperated sentence where the last element is joined by the connector word. Options:
24
+ # * <tt>:connector</tt>: The word used to join the last element in arrays with two or more elements (default: "and")
25
+ # * <tt>:skip_last_comma</tt>: Set to true to return "a, b and c" instead of "a, b, and c".
26
+ def to_sentence(options = {})
27
+ options.reverse_merge! :connector => 'and', :skip_last_comma => false
28
+
29
+ case length
30
+ when 0
31
+ ""
32
+ when 1
33
+ self[0]
34
+ when 2
35
+ "#{self[0]} #{options[:connector]} #{self[1]}"
36
+ else
37
+ "#{self[0...-1].join(', ')}#{options[:skip_last_comma] ? '' : ','} #{options[:connector]} #{self[-1]}"
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ Array.send(:include, ArrayExtensions) unless Array.respond_to?(:to_sentence)
44
+ Hash.send(:include, HashExtensions) unless Hash.respond_to?(:reverse_merge) && Hash.respond_to?(:reverse_merge!)
@@ -0,0 +1,49 @@
1
+ module MultiRails
2
+
3
+ class Loader
4
+ attr_reader :version
5
+
6
+ def self.logger
7
+ @logger ||= Logger.new(STDOUT)
8
+ end
9
+
10
+ # Create a loader for a specified version
11
+ # Will use a default version if none is supplied
12
+ def self.require_rails(rails_version = nil)
13
+ rails_version = MultiRails::Config.version_lookup(rails_version)
14
+ Loader.new(rails_version).load_rails
15
+ end
16
+
17
+ # Returns a list of all Rails versions available, oldest first
18
+ def self.all_rails_versions
19
+ specs = Gem::cache.search("rails")
20
+ specs.map {|spec| spec.version.to_s }.sort
21
+ end
22
+
23
+ def self.latest_stable_version
24
+ all_rails_versions.sort.reverse.detect {|version| version.count(".") < 3 }
25
+ end
26
+
27
+ # A version of the loader is created to gem and require one version of Rails
28
+ def initialize(version)
29
+ @version = version
30
+ end
31
+
32
+ def load_rails
33
+ gem_rails
34
+ require_rails
35
+ end
36
+
37
+ def gem_rails
38
+ gem 'rails', version
39
+ rescue LoadError => e
40
+ msg = %Q[Cannot find gem for Rails version: '#{version}'!\nInstall the missing gem with:\ngem install -v=#{version} rails]
41
+ raise MultiRailsError, msg
42
+ end
43
+
44
+ def require_rails
45
+ Config.rails_requires.each {|lib| require lib }
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,2 @@
1
+ class MultiRailsError < RuntimeError
2
+ end
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require File.expand_path(File.join(File.dirname(__FILE__), "/../lib/multi_rails"))
5
+
6
+ class Rake::Task
7
+ attr_accessor :already_invoked
8
+ end
9
+
10
+ namespace :test do
11
+ namespace :multi_rails do
12
+
13
+ desc "Run against all versions of Rails"
14
+ task :all do
15
+ MultiRails::Loader.all_rails_versions.each_with_index do |version, index|
16
+ silence_warnings { ENV["RAILS_VERSION"] = version }
17
+ print_rails_version
18
+ reset_rake_task unless index == 0
19
+ Rake::Task[:test].invoke
20
+ end
21
+ end
22
+
23
+ desc "Run against one verison of Rails specified as 'RAILS_VERSION' - for example 'rake test:multi_rails:one RAILS_VERSION=1.2.3'"
24
+ task :one do
25
+ print_rails_version
26
+ Rake::Task[:test].invoke
27
+ end
28
+
29
+ BAR = "=" * 80
30
+ def print_rails_version
31
+ puts "\n#{BAR}\nRequiring rails version: #{MultiRails::Config.version_lookup}\n#{BAR}"
32
+ end
33
+
34
+ def reset_rake_task
35
+ Rake::Task[:test].already_invoked = false
36
+ Rake::Task[:test].prerequisites.each {|p| Rake::Task[p].already_invoked = false}
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "multi_rails_test_helper"))
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../lib/multi_rails"))
3
+
4
+ describe "Version Lookup in config" do
5
+
6
+ it "should use argument version if passed in " do
7
+ MultiRails::Config.version_lookup("1.2.3").should == "1.2.3"
8
+ end
9
+
10
+ it "should use env var if set" do
11
+ begin
12
+ MultiRails::Loader.stubs(:all_rails_versions).returns(["1.2.99"])
13
+ ENV["RAILS_VERSION"] = "1.2.99"
14
+ MultiRails::Config.version_lookup.should == "1.2.99"
15
+ ensure
16
+ silence_warnings { ENV["RAILS_VERSION"] = nil }
17
+ end
18
+ end
19
+
20
+ it "should raise if providing env var and we dont find a corresponding version" do
21
+ begin
22
+ ENV["RAILS_VERSION"] = "X.X.99"
23
+ lambda { MultiRails::Config.version_lookup }.should.raise(MultiRailsError)
24
+ ensure
25
+ silence_warnings { ENV["RAILS_VERSION"] = nil }
26
+ end
27
+ end
28
+
29
+ it "should use latest stable version if there is no argumnt or env var" do
30
+ MultiRails::Config.version_lookup.should == MultiRails::Loader.latest_stable_version
31
+ end
32
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "multi_rails_test_helper"))
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../lib/multi_rails"))
3
+
4
+ describe "core extensions" do
5
+ it "should extend Kernel" do
6
+ Kernel.should.respond_to? :silence_warnings
7
+ end
8
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "multi_rails_test_helper"))
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../lib/multi_rails"))
3
+
4
+ describe "Rails plugin init" do
5
+ it "should do nothing if RAILS_ENV isn't set" do
6
+ MultiRails.expects(:require_rails).never
7
+ load File.expand_path(File.join(File.dirname(__FILE__), "../init.rb"))
8
+ end
9
+
10
+ it "should only do anything in Test environment" do
11
+ MultiRails.expects(:require_rails).never
12
+ load File.expand_path(File.join(File.dirname(__FILE__), "../init.rb"))
13
+ end
14
+
15
+ it "should require rails in Test environment" do
16
+ silence_warnings do
17
+ begin
18
+ orig_rails_env = Object.const_defined?("RAILS_ENV") ? Object.const_get("RAILS_ENV") : nil
19
+ Object.const_set("RAILS_ENV", "test")
20
+ MultiRails.expects(:require_rails).once
21
+ load File.expand_path(File.join(File.dirname(__FILE__), "../init.rb"))
22
+ ensure
23
+ Object.const_set("RAILS_ENV", orig_rails_env)
24
+ end
25
+ end
26
+ end
27
+
28
+
29
+ end
@@ -0,0 +1,80 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "multi_rails_test_helper"))
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../lib/multi_rails"))
3
+
4
+ describe "loader" do
5
+
6
+ setup do
7
+ never_really_require_rails
8
+ never_puts
9
+ end
10
+
11
+ it "should fall back to a default verison to try" do
12
+ stub_rails_requires
13
+ MultiRails::Loader.any_instance.expects(:gem).with("rails", MultiRails::Loader.latest_stable_version)
14
+ MultiRails::Loader.require_rails
15
+ end
16
+
17
+ it "should fail fast if we are missing a requested gem version" do
18
+ lambda { MultiRails::Loader.require_rails("9.9.9") }.should.raise(MultiRailsError)
19
+ end
20
+
21
+ it "should gem the specified version" do
22
+ stub_rails_requires
23
+ MultiRails::Loader.any_instance.expects(:gem).with("rails", "1.2.5").returns(true)
24
+ MultiRails::Loader.require_rails("1.2.5")
25
+ end
26
+
27
+ it "should allow using a better name for weird gem version numbers, like 2.0.0 PR => 1.2.4.7794" do
28
+ stub_rails_requires
29
+ MultiRails::Loader.any_instance.expects(:gem).with("rails", MultiRails::Config.weird_versions["2.0.0.PR"]).returns(true)
30
+ MultiRails::Loader.require_rails("2.0.0.PR")
31
+ end
32
+
33
+ it "should require the needed dependancies" do
34
+ MultiRails::Loader.any_instance.stubs(:gem)
35
+ MultiRails::Config.rails_requires.each do |file|
36
+ MultiRails::Loader.any_instance.expects(:require).with(file)
37
+ end
38
+ MultiRails::Loader.require_rails
39
+ end
40
+
41
+ def stub_rails_requires
42
+ MultiRails::Loader.any_instance.stubs(:require).returns(true)
43
+ end
44
+
45
+ def never_really_require_rails
46
+ MultiRails::Loader.any_instance.expects(:require).never
47
+ end
48
+
49
+ def never_puts
50
+ MultiRails::Loader.stubs(:puts)
51
+ end
52
+ end
53
+
54
+ describe "finding all gems of rails available" do
55
+
56
+ it "should search the gem cache for rails" do
57
+ Gem::cache.expects(:search).with("rails").returns([])
58
+ MultiRails::Loader.all_rails_versions
59
+ end
60
+
61
+ it "should return all Rails versions it finds sorted with the earliest versions first" do
62
+ specs = [stub(:version => stub(:to_s => "1.2.4")), stub(:version => stub(:to_s => "1.2.3"))]
63
+ Gem::cache.expects(:search).with("rails").returns(specs)
64
+ MultiRails::Loader.all_rails_versions.should == ["1.2.3", "1.2.4"]
65
+ end
66
+
67
+ end
68
+
69
+ describe "finding latest stable version" do
70
+ it "should find the latest stable rails gem" do
71
+ MultiRails::Loader.stubs(:all_rails_versions).returns(["1.2.3", "1.2.5", "1.2.5.1343"])
72
+ MultiRails::Loader.latest_stable_version.should == "1.2.5"
73
+ end
74
+
75
+ it "should find 2.0.0 when its released" do
76
+ MultiRails::Loader.stubs(:all_rails_versions).returns(["1.2.3", "1.2.5", "1.2.5.1343", "2.0.0", "1.2.7"])
77
+ MultiRails::Loader.latest_stable_version.should == "2.0.0"
78
+ end
79
+
80
+ end
@@ -0,0 +1,4 @@
1
+ require 'test/unit'
2
+ require 'test/spec'
3
+ require 'mocha'
4
+ require 'redgreen' unless Object.const_defined?("TextMate")
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: MultiRails
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-10-21 00:00:00 -04:00
8
+ summary: Testing tool to easily test agaist multiple versions of Rails.
9
+ require_paths:
10
+ - lib
11
+ email: ""
12
+ homepage: http://multi-rails.rubyforge.org/
13
+ rubyforge_project: multi-rails
14
+ description: "MultiRails was initially developed by members of Relevance while developing Streamlined against edge Rails. To see how Streamlined uses MultiRails, go to http://streamlinedframework.org. == FEATURES/PROBLEMS: * easily test plugins/extensions to Rails using a one line require from your test_helper.rb * rake tasks to test against a specific version of Rails, or all versions of Rails available locally as Gems == TODOs:"
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Relevance
31
+ files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - init.rb
37
+ - lib/multi_rails.rb
38
+ - lib/multi_rails/config.rb
39
+ - lib/multi_rails/core_extensions.rb
40
+ - lib/multi_rails/loader.rb
41
+ - lib/multi_rails/multi_rails_error.rb
42
+ - tasks/multi_rails.rake
43
+ - test/config_test.rb
44
+ - test/core_extensions_test.rb
45
+ - test/init_test.rb
46
+ - test/loader_test.rb
47
+ - test/multi_rails_test_helper.rb
48
+ test_files:
49
+ - test/config_test.rb
50
+ - test/core_extensions_test.rb
51
+ - test/init_test.rb
52
+ - test/loader_test.rb
53
+ rdoc_options:
54
+ - --main
55
+ - README.txt
56
+ extra_rdoc_files:
57
+ - History.txt
58
+ - Manifest.txt
59
+ - README.txt
60
+ executables: []
61
+
62
+ extensions: []
63
+
64
+ requirements: []
65
+
66
+ dependencies:
67
+ - !ruby/object:Gem::Dependency
68
+ name: hoe
69
+ version_requirement:
70
+ version_requirements: !ruby/object:Gem::Version::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.3.0
75
+ version: