multi_rails 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,12 @@
1
+ == 0.0.3
2
+
3
+ * add support for using multi_rails with regular Rails apps, which was way more work then it should have been.
4
+ * add the bootstrap task to add our multi_rails require line at the top of environment.rb in a rails app
5
+ * renames vendor/rails to vendor/rails.off in a Rails app, in order to fall back to rubygems
6
+ * added multi_rails_runner to allow multi_rails to set the RAILS_GEM_VERSION before the Rails Rakefile ever gets loaded
7
+ * improve rdoc
8
+ * move svn hosting to google code, to make it publicly accessible
9
+
1
10
  == 0.0.2 / Tuesday; October 23, 2007
2
11
 
3
12
  * first public release!
@@ -0,0 +1,11 @@
1
+ Copyright (c) 2007 Relevance, Inc. (http://thinkrelevance.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction,
4
+ including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished
5
+ to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
10
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
11
+ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,19 +1,23 @@
1
1
  History.txt
2
+ MIT-LICENSE
2
3
  Manifest.txt
3
4
  README.txt
4
5
  Rakefile
5
- init.rb
6
+ bin/multi_rails_runner.rb
7
+ install.rb
6
8
  lib/multi_rails.rb
7
9
  lib/multi_rails/config.rb
8
10
  lib/multi_rails/core_extensions.rb
9
11
  lib/multi_rails/loader.rb
10
12
  lib/multi_rails/multi_rails_error.rb
13
+ lib/multi_rails/rails_app_helper.rb
11
14
  lib/multi_rails_init.rb
12
15
  tasks/load_multi_rails_rake_tasks.rb
13
16
  tasks/multi_rails.rake
14
17
  test/config_test.rb
15
18
  test/core_extensions_test.rb
16
- test/init_test.rb
19
+ test/install_test.rb
17
20
  test/loader_test.rb
18
21
  test/multi_rails_init_test.rb
19
22
  test/multi_rails_test_helper.rb
23
+ test/rails_app_helper_test.rb
data/README.txt CHANGED
@@ -2,26 +2,38 @@ MultiRails
2
2
  by Relevance, http://thinkrelevance.com
3
3
  Rob Sanheim - MultiRails lead
4
4
 
5
+ == URLs:
6
+
7
+ rubyforge: http://rubyforge.org/projects/multi-rails/
8
+ svn stable: http://robsanheim.googlecode.com/svn/tags/stable/multi_rails
9
+ svn trunk: http://robsanheim.googlecode.com/svn/trunk/multi_rails
10
+ mailing list: http://groups.google.com/group/multi_rails
11
+
5
12
  == DESCRIPTION:
6
13
 
7
- MultiRails allows easy testing against multiple versions of Rails for your Rails specific gem or plugin.
14
+ MultiRails allows easy testing against multiple versions of Rails for your Rails specific gem or plugin. IT also has tentative support testing Rails applications against multiple versions of Rails.
8
15
 
9
- Use MultiRails to hook in Rails 2.0 testing in your continuous integration. Still working on Rails 2.0 support?
10
- Use MultiRails to see where your test suite falls down against the 2.0 preview releases of Rails.
16
+ Use MultiRails to hook in Rails 2.0 testing in your continuous integration. Still working on Rails 2.0 support? Use MultiRails to see where your test suite falls down against the 2.0 preview releases of Rails.
11
17
 
12
18
  MultiRails was initially developed by members of Relevance while developing Streamlined
13
19
  against edge Rails. To see how Streamlined uses MultiRails, go to http://trac.streamlinedframework.org.
14
20
 
15
- == FEATURES/PROBLEMS:
21
+ == FEATURES:
16
22
 
17
23
  * easily test plugins/extensions using a require from your test_helper.rb and a require in your RakeFile
18
- * rake tasks to test against a specific version of Rails, or all versions of Rails available locally as Gems
24
+ * rake tasks to test against a specified version of Rails, the latest version, or all versions
25
+ * tentative support for testing plain Rails apps against multiple versions of Rails
26
+ * Uses rubygems for version management of Rails
19
27
 
20
28
  == TODOs:
21
29
 
22
- * enable multi_rails testing in a plain ole' Rails app -- this is difficult right now because of the Rails boot process
23
30
  * improve docs on how to override what files are required by multi_rails
24
- * test against Rails versions that are just checked out, and not installed via Gems
31
+ * maybe add ability to load plain Rails versions -- ie checked out copies not in RubyGems
32
+
33
+ == NOTES:
34
+
35
+ * (__For Rails apps only__) multi_rails will rename your vendor/rails directory to vendor/rails.off if it finds one within your rails app. We have to do this to make Rails fall back to RubyGems rails. Multi_rails will rename back to the correct vendor/rails when done testing, so it will not interrupt your app in normal use.
36
+ * (__For Rails apps only__) multi_rails needs to add a line to top of your environment.rb to hook into -- see the instructions below for more details
25
37
 
26
38
  == REQUIREMENTS:
27
39
 
@@ -30,45 +42,50 @@ against edge Rails. To see how Streamlined uses MultiRails, go to http://trac.s
30
42
  * Rails 1.2.1 or higher
31
43
  * at least one copy of Rails installed via rubygems.
32
44
 
33
- == INSTALL:
45
+ == INSTALLING FOR RAILS APPS
34
46
 
35
- NOTE - for multi_rails to work at all, you *must* remove any of your own requires of the Rails
36
- framework in any sort of test_helper you have. MultiRails handles requiring Rails on its own,
37
- immediately after it uses gem to activate the correct version under test.
38
-
39
- * sudo gem install multi_rails
40
-
41
- * in your projects Rakefile, require a simple rb file which just loads the multi_rails rake tasks.
47
+ * install the plugin, which will copy the multi_rails_runner into your script folder on install.
48
+ script/plugin install http://robsanheim.googlecode.com/svn/tags/stable/multi_rails
42
49
 
43
- require 'load_multi_rails_rake_tasks'
44
-
45
- * run rake -T in your root, verify that you see two new rake tasks.
50
+ * Run the multi_rails bootstrap command to get your Rails app ready to go with multi_rails - this will add a require line to the top of your environment.rb needed for multi_rails to work right.
51
+ script/multi_rails_runner bootstrap
46
52
 
47
- rake test:multi_rails:all
48
- rake test:multi_rails:one
49
-
50
- * In your plugins test_helper, remove any rails specific requires (activerecord, actioncontroller, activesupport, etc),
51
- and require multi_rails_init instead.
53
+ * Run your tests against all versions of Rails installed (the default):
54
+ script/multi_rails_runner
55
+ or run our tests against the most recent version of Rails you have installed:
56
+ script/multi_rails_runner latest
57
+ or just a specific version:
58
+ MULTIRAILS_RAILS_VERSION=1.2.5 script/multi_rails_runner one
52
59
 
53
- require multi_rails_init
60
+ == INSTALLING FOR PLUGINS
54
61
 
55
- * Run the multi_rails:all rake task to run your test suite against all versions of Rails you have installed via gems. Install
56
- other versions of Rails using rubygems to add them to your test suite.
57
-
58
- * For changing the Rails version under test, set the environment variable MULTIRAILS_RAILS_VERSION to version you want, and run
59
- the multi_rails:one task or just run a test class directly.
62
+ * Install multi_rails
63
+ sudo gem install multi_rails
64
+
65
+ * In your projects Rakefile, require the multi_rails Rake tasks.
66
+
67
+ require "load_multi_rails_rake_tasks"
68
+
69
+ * Run rake -T to verify you see the multi_rails tasks.
70
+ rake -T multi_rails
71
+ # should see "rake test:multi_rails:all, rake test:multi_rails:latest...etc"
72
+
73
+ * In your test_helper, require multi_rails_init *before* any rails specific requires (activerecord, actioncontroller, activesupport, etc).
74
+
75
+ require 'multi_rails_init'
76
+
77
+ * Run the multi_rails:all rake task to run your test suite against all versions of Rails you have installed via gems. Install other versions of Rails using rubygems to add them to your test suite.
78
+
79
+ * For changing the Rails version under test, set the environment variable MULTIRAILS_RAILS_VERSION to version you want, and run the multi_rails:one task or just run a test class directly.
60
80
 
61
81
  == HELP
62
82
 
63
- * Are you trying to use MultiRails in a plain rails application? Right now there isn't a good way to do this, without hacking
64
- up your boot.rb. If you have any ideas please do contribute.
65
-
66
- * Getting gem activation errors? Are you sure you removed your rails requires and are just using multi rails?
67
-
68
83
  * Join the mailing list!
69
84
  http://groups.google.com/group/multi_rails
70
85
  multi_rails@googlegroups.com
71
-
86
+
87
+ * Rails plugin testing is pretty solid, but rails *app* testing is still new. Post issues to the mailing list.
88
+ * Getting gem activation errors? Post to the list with how you are using multi_rails, and I'll try to help.
72
89
 
73
90
  == LICENSE:
74
91
 
data/Rakefile CHANGED
@@ -14,4 +14,12 @@ Hoe.new('multi_rails', MultiRails::VERSION) do |p|
14
14
  p.remote_rdoc_dir = '' # Release to root
15
15
  p.test_globs = 'test/**/*_test.rb' # we use the foo_test convention
16
16
  p.spec_extras[:require_paths] = ['lib', 'tasks']
17
+ end
18
+
19
+ desc "Copy trunk to stable tag in SVN to make things easy for Rails plugin installation."
20
+ task :copy_stable do
21
+ trunk_dir = "~/src/opensource/robsanheim/trunk/multi_rails/"
22
+ stable_dir = "~/src/opensource/robsanheim/tags/stable/multi_rails/"
23
+ puts %x[rsync --exclude='.svn' -r #{trunk_dir} #{stable_dir}]
24
+ puts %x[svn ci #{stable_dir} -m 'Release to stable from trunk.']
17
25
  end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'pathname'
5
+
6
+ # Get the real path, to make sure if this file is symlinked we don't mess up
7
+ absolute_current_dir = File.dirname(Pathname.new(__FILE__).realpath)
8
+
9
+ require File.expand_path(File.join(absolute_current_dir, "../lib/multi_rails"))
10
+ require File.expand_path(File.join(absolute_current_dir, "../tasks/load_multi_rails_rake_tasks"))
11
+
12
+ # A script to allow multi_rails to work with Rails apps
13
+ # For testing Rails plugins or gems, you don't need to use this - you can just the rake tasks.
14
+ module MultiRails
15
+ module Runner
16
+ # Run multi_rails using the specified task, defaults to testing against all Rails versions intalled
17
+ def self.run(task = "all")
18
+ task = task ? task : "all"
19
+ puts %[Running MultiRails with task "#{task}"...]
20
+ MultiRails::RailsAppHelper.run(task)
21
+ end
22
+
23
+ end
24
+ end
25
+
26
+ HELP_MESSAGE = "Give this runner the name of the multi_rails rake task you want to run, or give it no args if you want the default behavior of testing against all versions of Rails."
27
+
28
+ if ARGV.size > 1
29
+ puts HELP_MESSAGE
30
+ else
31
+ MultiRails::Runner.run(ARGV.first)
32
+ end
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+
3
+ BAR = "=" * 80
4
+ RUNNER_PATH = "script/multi_rails_runner"
5
+ ACTUAL_PATH = File.expand_path(File.join(RAILS_ROOT, "/vendor/plugins/multi_rails/bin/multi_rails_runner.rb"))
6
+
7
+ puts BAR
8
+ puts "Installing multi_rails, and settig up /script/multi_rails_runner."
9
+
10
+ FileUtils.symlink(ACTUAL_PATH, RUNNER_PATH, :force => true)
11
+ `chmod +x #{RAILS_ROOT}/script/multi_rails_runner`
12
+ puts "Run '#{RUNNER_PATH} bootstrap' to add the necessary multi_rails require line to the top of your environment.rb file."
13
+ puts "Once that has been done, run '#{RUNNER_PATH}' from the root of our project to test your Rails app against all your versions of Rails."
14
+ puts "Happy Testing !"
15
+ puts BAR
@@ -1,12 +1,12 @@
1
1
  require 'rubygems'
2
2
  require 'logger'
3
- files = %w(core_extensions config loader multi_rails_error)
3
+ files = %w(core_extensions config loader multi_rails_error rails_app_helper)
4
4
  files.each do |file|
5
5
  require File.expand_path(File.join(File.dirname(__FILE__), "multi_rails/#{file}"))
6
6
  end
7
7
 
8
8
  module MultiRails
9
- VERSION = '0.0.2'
9
+ VERSION = '0.0.3'
10
10
 
11
11
  def self.gem_and_require_rails
12
12
  Loader.gem_and_require_rails
@@ -16,9 +16,9 @@ module MultiRails
16
16
  Loader.latest_stable_version
17
17
  end
18
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
19
+ def named_version_lookup(version)
20
+ version = @weird_versions[version] || version
21
+ raise MultiRailsError, "Can't find Rails gem version #{version} - available versions are: #{Loader.all_rails_versions.to_sentence})." if !Loader.all_rails_versions.include? version
22
22
  version
23
23
  end
24
24
 
@@ -24,6 +24,10 @@ module MultiRails
24
24
  all_rails_versions.sort.reverse.detect {|version| version.count(".") < 3 }
25
25
  end
26
26
 
27
+ def self.latest_version
28
+ all_rails_versions.sort.last
29
+ end
30
+
27
31
  # A version of the loader is created to gem and require one version of Rails
28
32
  def initialize(version)
29
33
  @version = version
@@ -0,0 +1,108 @@
1
+ require 'rake'
2
+ module MultiRails
3
+ module RailsAppHelper
4
+ RAILS_DIRECTORIES = %w(app config public test)
5
+ REQUIRE_LINE = %[require File.expand_path('config/rails_version') if File.exist?("config/rails_version.rb")].freeze
6
+
7
+ class << self
8
+
9
+ # Run the appropriate task or method for MultiRails
10
+ # This is called from the MultiRails command line runner
11
+ def run(task)
12
+ if task == "bootstrap"
13
+ self.bootstrap_for_rails
14
+ else
15
+ ENV["MULTIRAILS_FOR_RAILS_APP"] = "true"
16
+ Rake::Task["test:multi_rails:#{task}"].invoke
17
+ end
18
+ end
19
+
20
+ # Do a one time bootstrap to let MultiRails do its thing -- we aren't putting this
21
+ # in the general MultiRails rake file to keep it from showing up in contexts where
22
+ # it doesn't make sense (ie when testing a plugin).
23
+ def bootstrap_for_rails
24
+ set_rails_root
25
+ add_require_line_to_environment_file
26
+ end
27
+
28
+ # Make sure we have RAILS_ROOT set - will try to find it dynamically if its not set.
29
+ def set_rails_root
30
+ if Object.const_defined?("RAILS_ROOT")
31
+ RAILS_ROOT
32
+ else
33
+ Object.const_set("RAILS_ROOT", find_rails_root_dir)
34
+ end
35
+ raise("Must have a valid RAILS_ROOT.") unless Object.const_defined?("RAILS_ROOT") && RAILS_ROOT
36
+ RAILS_ROOT
37
+ end
38
+
39
+ def clean_up
40
+ FileUtils.rm(rails_gem_version_file) if within_rails_app? && File.exist?(rails_gem_version_file)
41
+ rename_vendor_rails_to_original
42
+ end
43
+
44
+ def init_for_rails_app(version)
45
+ set_rails_root
46
+ write_rails_gem_version_file(version)
47
+ rename_vendor_rails_if_necessary
48
+ end
49
+
50
+ def find_rails_root_dir
51
+ if current_dir_contains_rails_dirs? then Dir.pwd end
52
+ end
53
+
54
+ def current_dir_contains_rails_dirs?
55
+ if RAILS_DIRECTORIES.all? { |rails_dir| Dir.entries(Dir.pwd).include?(rails_dir) }
56
+ Dir.pwd
57
+ end
58
+ end
59
+
60
+ # Write out a file which is loaded later, so that the RAILS_GEM_VERSION gets set in the correct process
61
+ def write_rails_gem_version_file(version)
62
+ File.open(rails_gem_version_file, 'w') do |file|
63
+ file << %|RAILS_GEM_VERSION = '#{version}' unless Object.const_defined?("RAILS_GEM_VERSION")|
64
+ end
65
+ end
66
+
67
+ def rails_gem_version_file
68
+ File.expand_path("#{RAILS_ROOT}/config/rails_version.rb")
69
+ end
70
+
71
+ def rename_vendor_rails_if_necessary
72
+ File.rename(vendor_rails, vendor_rails_off) if File.directory?(vendor_rails)
73
+ end
74
+
75
+ def rename_vendor_rails_to_original
76
+ File.rename(vendor_rails_off, vendor_rails) if File.directory?(vendor_rails_off)
77
+ end
78
+
79
+ def add_require_line_to_environment_file
80
+ raise MultiRailsError, "Can't find environment.rb file was looking at path: #{environment_file}" unless File.exist?(environment_file)
81
+ unless first_environment_line == REQUIRE_LINE
82
+ original_content = File.read(environment_file)
83
+ File.open(environment_file, 'r+') do |f|
84
+ f.puts REQUIRE_LINE
85
+ f.print original_content
86
+ end
87
+ end
88
+ end
89
+
90
+ def first_environment_line
91
+ File.open(environment_file).readline.strip
92
+ end
93
+
94
+ def environment_file
95
+ File.expand_path(File.join(RAILS_ROOT, "config/environment.rb"))
96
+ end
97
+
98
+ def vendor_rails
99
+ "#{RAILS_ROOT}/vendor/rails"
100
+ end
101
+
102
+ def vendor_rails_off
103
+ "#{RAILS_ROOT}/vendor/rails.off"
104
+ end
105
+ end
106
+
107
+ end
108
+ end
@@ -11,31 +11,75 @@ end
11
11
  namespace :test do
12
12
  namespace :multi_rails do
13
13
 
14
- desc "Run against all versions of rubygem installed versions of Rails"
14
+ desc "Run against all installed versions of Rails. Local versions found: [#{MultiRails::Loader.all_rails_versions.to_sentence}]."
15
15
  task :all do
16
- MultiRails::Loader.all_rails_versions.each_with_index do |version, index|
17
- silence_warnings { ENV["MULTIRAILS_RAILS_VERSION"] = version }
18
- print_rails_version
19
- reset_rake_task unless index == 0
20
- Rake::Task[:test].invoke
16
+ begin
17
+ MultiRails::Loader.all_rails_versions.each_with_index do |version, index|
18
+ silence_warnings { ENV["MULTIRAILS_RAILS_VERSION"] = version }
19
+ init_for_rails_app(version) if within_rails_app?
20
+ print_rails_version
21
+ reset_test_tasks unless index == 0
22
+ Rake::Task[:test].invoke
23
+ end
24
+ ensure
25
+ clean_up
21
26
  end
22
27
  end
23
28
 
24
29
  desc "Run against one verison of Rails specified as 'MULTIRAILS_RAILS_VERSION' - for example 'rake test:multi_rails:one MULTIRAILS_RAILS_VERSION=1.2.3'"
25
30
  task :one do
26
- print_rails_version
27
- Rake::Task[:test].invoke
31
+ begin
32
+ version = ENV["MULTIRAILS_RAILS_VERSION"]
33
+ raise "Must give a version number" unless version
34
+ init_for_rails_app(version) if within_rails_app?
35
+ print_rails_version
36
+ Rake::Task[:test].invoke
37
+ ensure
38
+ clean_up
39
+ end
28
40
  end
29
-
41
+
42
+ desc "Run against the most recent version of Rails installed. Most recent found: [#{MultiRails::Loader.latest_version}]."
43
+ task :latest do
44
+ begin
45
+ version = MultiRails::Loader.latest_version
46
+ ENV["MULTIRAILS_RAILS_VERSION"] = version
47
+ init_for_rails_app(version) if within_rails_app?
48
+ print_rails_version
49
+ Rake::Task[:test].invoke
50
+ ensure
51
+ clean_up
52
+ end
53
+ end
54
+
55
+ def init_for_rails_app(version)
56
+ MultiRails::RailsAppHelper.init_for_rails_app(version)
57
+ load "Rakefile"
58
+ end
59
+
60
+ def within_rails_app?
61
+ ENV["MULTIRAILS_FOR_RAILS_APP"] == "true"
62
+ end
63
+
64
+ # clean up after ourselves, reverting to clean state if needed
65
+ def clean_up
66
+ MultiRails::RailsAppHelper.clean_up if within_rails_app?
67
+ end
68
+
30
69
  BAR = "=" * 80
31
70
  def print_rails_version
32
71
  puts "\n#{BAR}\nRequiring rails version: #{MultiRails::Config.version_lookup}\n#{BAR}"
33
72
  end
34
73
 
35
74
  # Need to hack the Rake test task a bit, otherwise it will only run once and never repeat.
36
- def reset_rake_task
37
- Rake::Task[:test].already_invoked = false
38
- Rake::Task[:test].prerequisites.each {|p| Rake::Task[p].already_invoked = false}
75
+ def reset_test_tasks
76
+ ["test", "test:units", "test:functionals", "test:integration"].each do |name|
77
+ if Rake::Task.task_defined?(name)
78
+ Rake::Task[name].already_invoked = false
79
+ Rake::Task[name].prerequisites.each {|p| Rake::Task[p].already_invoked = false}
80
+ end
81
+ end
39
82
  end
83
+
40
84
  end
41
85
  end
@@ -1,9 +1,9 @@
1
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
2
 
4
3
  describe "Version Lookup in config" do
5
4
 
6
5
  it "should use argument version if passed in " do
6
+ MultiRails::Loader.stubs(:all_rails_versions).returns(["1.2.3", "1.2.4"])
7
7
  MultiRails::Config.version_lookup("1.2.3").should == "1.2.3"
8
8
  end
9
9
 
@@ -1,8 +1,7 @@
1
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
2
 
4
3
  describe "core extensions" do
5
4
  it "should extend Kernel" do
6
5
  Kernel.should.respond_to? :silence_warnings
7
6
  end
8
- end
7
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "multi_rails_test_helper"))
2
+
3
+ describe "install hook" do
4
+ setup { Object.const_set("RAILS_ROOT", "/src/rails_app") }
5
+ teardown { Object.send(:remove_const, "RAILS_ROOT") if Object.const_defined?("RAILS_ROOT")}
6
+
7
+ def load_install
8
+ silence_warnings do
9
+ load File.expand_path(File.join(File.dirname(__FILE__), "../install.rb"))
10
+ end
11
+ end
12
+
13
+ it "should copy the multi_rails_runner to the script directory" do
14
+ Object.any_instance.stubs(:puts).returns(nil)
15
+ Object.any_instance.stubs(:`)
16
+
17
+ FileUtils.expects(:symlink).with("#{RAILS_ROOT}/vendor/plugins/multi_rails/bin/multi_rails_runner.rb",
18
+ "script/multi_rails_runner", :force => true)
19
+ load_install
20
+ end
21
+
22
+ it 'should make the file executable' do
23
+ Object.any_instance.stubs(:puts).returns(nil)
24
+ Object.any_instance.expects(:`).with("chmod +x #{RAILS_ROOT}/script/multi_rails_runner")
25
+ File.stubs(:symlink)
26
+ load_install
27
+ end
28
+
29
+ end
@@ -1,5 +1,4 @@
1
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
2
 
4
3
  describe "loader" do
5
4
 
@@ -25,6 +24,7 @@ describe "loader" do
25
24
  end
26
25
 
27
26
  it "should allow using a better name for weird gem version numbers, like 2.0.0 PR => 1.2.4.7794" do
27
+ MultiRails::Loader.stubs(:all_rails_versions).returns(["1.2.3", "1.2.4", "1.2.4.7794"])
28
28
  stub_rails_requires
29
29
  MultiRails::Loader.any_instance.expects(:gem).with("rails", MultiRails::Config.weird_versions["2.0.0.PR"]).returns(true)
30
30
  MultiRails::Loader.gem_and_require_rails("2.0.0.PR")
@@ -78,3 +78,16 @@ describe "finding latest stable version" do
78
78
  end
79
79
 
80
80
  end
81
+
82
+ describe "finding latest version" do
83
+ it "should find the most recent version, regardless of edge or non edge versions" do
84
+ MultiRails::Loader.stubs(:all_rails_versions).returns(["1.2.3", "1.2.5", "1.2.5.1343"])
85
+ MultiRails::Loader.latest_version.should == "1.2.5.1343"
86
+ end
87
+
88
+ it "should return the only version you have if there is only one installed" do
89
+ MultiRails::Loader.stubs(:all_rails_versions).returns(["1.2.3"])
90
+ MultiRails::Loader.latest_version.should == "1.2.3"
91
+ end
92
+
93
+ end
@@ -1,5 +1,4 @@
1
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
2
 
4
3
  describe "Rubygem test helper init" do
5
4
  it "should call gem and require rails" do
@@ -1,4 +1,6 @@
1
1
  require 'test/unit'
2
2
  require 'test/spec'
3
3
  require 'mocha'
4
- require 'redgreen' unless Object.const_defined?("TextMate")
4
+ require 'redgreen' unless Object.const_defined?("TextMate")
5
+
6
+ require File.expand_path(File.join(File.dirname(__FILE__), "../lib/multi_rails"))
@@ -0,0 +1,131 @@
1
+ require 'tempfile'
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "multi_rails_test_helper"))
3
+
4
+ describe "running a task" do
5
+ setup { Object.const_set("RAILS_ROOT", "/src/rails_app")}
6
+ teardown { Object.send(:remove_const, "RAILS_ROOT")}
7
+
8
+ it "should call the bootstrap method if thats the task" do
9
+ MultiRails::RailsAppHelper.expects(:bootstrap_for_rails)
10
+ MultiRails::RailsAppHelper.run('bootstrap')
11
+ end
12
+
13
+ it "should invoke the corresponding rake task for any other arg" do
14
+ task = mock().expects(:invoke)
15
+ Rake::Task.expects(:[]).with("test:multi_rails:all").returns(task)
16
+ MultiRails::RailsAppHelper.run('all')
17
+ end
18
+
19
+ end
20
+
21
+ describe "determing rails root" do
22
+ teardown { Object.send(:remove_const, "RAILS_ROOT") if Object.const_defined?("RAILS_ROOT")}
23
+
24
+ it "should try the RAILS_ROOT constant first" do
25
+ Object.const_set("RAILS_ROOT", "/src/rails_app")
26
+ MultiRails::RailsAppHelper.set_rails_root.should == "/src/rails_app"
27
+ end
28
+
29
+ it "should fallback to finding it dynamically" do
30
+ current_dir_stub = "/foo/bar/my_rails_app"
31
+ Dir.expects(:entries).returns(["app", "lib", "config", "public", "test", "vendor"]).at_least_once
32
+ Dir.expects(:pwd).returns(current_dir_stub).at_least_once
33
+ MultiRails::RailsAppHelper.set_rails_root.should == "/foo/bar/my_rails_app"
34
+ end
35
+
36
+ it "should fail fast if it can't determine RAILS ROOT" do
37
+ MultiRails::RailsAppHelper.expects(:find_rails_root_dir).returns(nil)
38
+ lambda { MultiRails::RailsAppHelper.set_rails_root }.should.raise
39
+ end
40
+
41
+ end
42
+
43
+ describe "writing rails gem version file" do
44
+ setup { Object.const_set("RAILS_ROOT", "/src/rails_app")}
45
+ teardown { Object.send(:remove_const, "RAILS_ROOT")}
46
+
47
+ it "should write to the correct file" do
48
+ File.expects(:open).with("#{RAILS_ROOT}/config/rails_version.rb", 'w')
49
+ MultiRails::RailsAppHelper.write_rails_gem_version_file('1.2.5')
50
+ end
51
+
52
+ end
53
+
54
+ describe "init for rails app" do
55
+ it "should set rails root, write rails gem version file, and rename vendor rails" do
56
+ version = "1.2.6"
57
+ MultiRails::RailsAppHelper.expects(:set_rails_root)
58
+ MultiRails::RailsAppHelper.expects(:write_rails_gem_version_file).with(version)
59
+ MultiRails::RailsAppHelper.expects(:rename_vendor_rails_if_necessary)
60
+ MultiRails::RailsAppHelper.init_for_rails_app(version)
61
+ end
62
+ end
63
+
64
+ describe "renaming vendor/rails if it exists" do
65
+ setup { Object.const_set("RAILS_ROOT", "/src/rails_app")}
66
+ teardown { Object.send(:remove_const, "RAILS_ROOT")}
67
+
68
+ it "should rename with .OFF extension so that gem version is picked up during test run" do
69
+ vendor_rails = "#{RAILS_ROOT}/vendor/rails"
70
+ File.stubs(:directory?).returns(true)
71
+ File.expects(:rename).with(vendor_rails, "#{vendor_rails}.off")
72
+ MultiRails::RailsAppHelper.rename_vendor_rails_if_necessary
73
+ end
74
+
75
+ it "should do nothing if there is no vendor/rails" do
76
+ File.expects(:directory?).returns(false)
77
+ File.expects(:rename).never
78
+ MultiRails::RailsAppHelper.rename_vendor_rails_if_necessary
79
+ end
80
+ end
81
+
82
+ describe "adding require hook to top of environment.rb using mocks" do
83
+ setup { Object.const_set("RAILS_ROOT", "/src/rails_app")}
84
+ teardown { Object.send(:remove_const, "RAILS_ROOT")}
85
+
86
+ it "should raise if it can't find environment.rb" do
87
+ e = lambda { MultiRails::RailsAppHelper.add_require_line_to_environment_file }.should.raise(MultiRailsError)
88
+ end
89
+
90
+ it "should not do anything if the line is already in the file" do
91
+ File.stubs(:exist?).returns(true)
92
+ File.expects(:open).never
93
+ MultiRails::RailsAppHelper.expects(:first_environment_line).returns(MultiRails::RailsAppHelper::REQUIRE_LINE)
94
+ MultiRails::RailsAppHelper.add_require_line_to_environment_file
95
+ end
96
+
97
+ end
98
+
99
+ describe "adding require hook to top of environment.rb (without using mocks)" do
100
+
101
+ setup do
102
+ Object.const_set("RAILS_ROOT", "/src/rails_app")
103
+ @env_content = <<-EOL
104
+ # Be sure to restart your web server when you modify this file.
105
+
106
+ # Uncomment below to force Rails into production mode when
107
+ # you don't control web/app server and can't set it the proper way
108
+ # ENV['RAILS_ENV'] ||= 'production'
109
+
110
+ # Specifies gem version of Rails to use when vendor/rails is not present
111
+ RAILS_GEM_VERSION = '1.2.5' unless defined? RAILS_GEM_VERSION
112
+ EOL
113
+ @file = Tempfile.new('sample_environment')
114
+ @file << @env_content
115
+ @file.close
116
+ end
117
+
118
+ teardown do
119
+ Object.send(:remove_const, "RAILS_ROOT")
120
+ end
121
+
122
+ it "should add the require line" do
123
+ MultiRails::RailsAppHelper.stubs(:environment_file).returns(@file.path)
124
+ MultiRails::RailsAppHelper.add_require_line_to_environment_file
125
+ @file.open.rewind
126
+ lines = @file.readlines
127
+ lines[0].to_s.should == (MultiRails::RailsAppHelper::REQUIRE_LINE + "\n")
128
+ lines[1..-1].to_s.should == @env_content
129
+ end
130
+
131
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: multi_rails
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.2
7
- date: 2007-10-23 00:00:00 -04:00
6
+ version: 0.0.3
7
+ date: 2007-12-06 00:00:00 -05:00
8
8
  summary: Testing tool to easily test agaist multiple versions of Rails.
9
9
  require_paths:
10
10
  - lib
@@ -12,7 +12,7 @@ require_paths:
12
12
  email: multi_rails@googlegroups.com
13
13
  homepage: http://multi-rails.rubyforge.org/
14
14
  rubyforge_project: multi-rails
15
- description: "MultiRails by Relevance, http://thinkrelevance.com Rob Sanheim - MultiRails lead == DESCRIPTION: MultiRails allows easy testing against multiple versions of Rails for your Rails specific gem or plugin. Use MultiRails to hook in Rails 2.0 testing in your continuous integration. Still working on Rails 2.0 support? Use MultiRails to see where your test suite falls down against the 2.0 preview releases of Rails. MultiRails was initially developed by members of Relevance while developing Streamlined against edge Rails. To see how Streamlined uses MultiRails, go to http://trac.streamlinedframework.org. == FEATURES/PROBLEMS: * easily test plugins/extensions using a require from your test_helper.rb and a require in your RakeFile * rake tasks to test against a specific version of Rails, or all versions of Rails available locally as Gems == TODOs: * enable multi_rails testing in a plain ole' Rails app -- this is difficult right now because of the Rails boot process * improve docs on how to override what files are required by multi_rails * test against Rails versions that are just checked out, and not installed via Gems == REQUIREMENTS: * Ruby 1.8.5 or higher * Rubygems * Rails 1.2.1 or higher * at least one copy of Rails installed via rubygems. == INSTALL:"
15
+ description: "MultiRails by Relevance, http://thinkrelevance.com Rob Sanheim - MultiRails lead == URLs: rubyforge: http://rubyforge.org/projects/multi-rails/ svn stable: http://robsanheim.googlecode.com/svn/tags/stable/multi_rails svn trunk: http://robsanheim.googlecode.com/svn/trunk/multi_rails mailing list: http://groups.google.com/group/multi_rails == DESCRIPTION: MultiRails allows easy testing against multiple versions of Rails for your Rails specific gem or plugin. IT also has tentative support testing Rails applications against multiple versions of Rails. Use MultiRails to hook in Rails 2.0 testing in your continuous integration. Still working on Rails 2.0 support? Use MultiRails to see where your test suite falls down against the 2.0 preview releases of Rails. MultiRails was initially developed by members of Relevance while developing Streamlined against edge Rails. To see how Streamlined uses MultiRails, go to http://trac.streamlinedframework.org. == FEATURES: * easily test plugins/extensions using a require from your test_helper.rb and a require in your RakeFile * rake tasks to test against a specified version of Rails, the latest version, or all versions * tentative support for testing plain Rails apps against multiple versions of Rails * Uses rubygems for version management of Rails == TODOs: * improve docs on how to override what files are required by multi_rails * maybe add ability to load plain Rails versions -- ie checked out copies not in RubyGems == NOTES: * (__For Rails apps only__) multi_rails will rename your vendor/rails directory to vendor/rails.off if it finds one within your rails app. We have to do this to make Rails fall back to RubyGems rails. Multi_rails will rename back to the correct vendor/rails when done testing, so it will not interrupt your app in normal use. * (__For Rails apps only__) multi_rails needs to add a line to top of your environment.rb to hook into -- see the instructions below for more details"
16
16
  autorequire:
17
17
  default_executable:
18
18
  bindir: bin
@@ -31,30 +31,35 @@ authors:
31
31
  - Relevance
32
32
  files:
33
33
  - History.txt
34
+ - MIT-LICENSE
34
35
  - Manifest.txt
35
36
  - README.txt
36
37
  - Rakefile
37
- - init.rb
38
+ - bin/multi_rails_runner.rb
39
+ - install.rb
38
40
  - lib/multi_rails.rb
39
41
  - lib/multi_rails/config.rb
40
42
  - lib/multi_rails/core_extensions.rb
41
43
  - lib/multi_rails/loader.rb
42
44
  - lib/multi_rails/multi_rails_error.rb
45
+ - lib/multi_rails/rails_app_helper.rb
43
46
  - lib/multi_rails_init.rb
44
47
  - tasks/load_multi_rails_rake_tasks.rb
45
48
  - tasks/multi_rails.rake
46
49
  - test/config_test.rb
47
50
  - test/core_extensions_test.rb
48
- - test/init_test.rb
51
+ - test/install_test.rb
49
52
  - test/loader_test.rb
50
53
  - test/multi_rails_init_test.rb
51
54
  - test/multi_rails_test_helper.rb
55
+ - test/rails_app_helper_test.rb
52
56
  test_files:
53
57
  - test/config_test.rb
54
58
  - test/core_extensions_test.rb
55
- - test/init_test.rb
59
+ - test/install_test.rb
56
60
  - test/loader_test.rb
57
61
  - test/multi_rails_init_test.rb
62
+ - test/rails_app_helper_test.rb
58
63
  rdoc_options:
59
64
  - --main
60
65
  - README.txt
@@ -62,8 +67,8 @@ extra_rdoc_files:
62
67
  - History.txt
63
68
  - Manifest.txt
64
69
  - README.txt
65
- executables: []
66
-
70
+ executables:
71
+ - multi_rails_runner.rb
67
72
  extensions: []
68
73
 
69
74
  requirements: []
data/init.rb DELETED
@@ -1,4 +0,0 @@
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::gem_and_require_rails
4
- end
@@ -1,28 +0,0 @@
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(:gem_and_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(:gem_and_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(:gem_and_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
- end