relevance-multi_rails 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ v0.0.7 update echoe to work with github and rubyforge
2
+
3
+ v0.0.6 Readme fixes
4
+
5
+ v0.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); Update to follow Relevance OSS standards
6
+
7
+ v0.0.4
8
+
9
+ * Change the all task so that the build will run through all rails versions, even if one of them fails, but at the end
10
+ the failing versions are printed and we abort. Thanks to Evan Weaver for initial patch and idea.
11
+ * display the rails gem from the load path as a sanity check right after we gem/require
12
+ * add autotest railsplugin discovery, so I can use autotest to test multi_rails
13
+ * various rake tweaks to make release easier and more automated
14
+
15
+ v0.0.3
16
+
17
+ * add support for using multi_rails with regular Rails apps, which was way more work then it should have been.
18
+ * add the bootstrap task to add our multi_rails require line at the top of environment.rb in a rails app
19
+ * renames vendor/rails to vendor/rails.off in a Rails app, in order to fall back to rubygems
20
+ * added multi_rails_runner to allow multi_rails to set the RAILS_GEM_VERSION before the Rails Rakefile ever gets loaded
21
+ * improve rdoc
22
+ * move svn hosting to google code, to make it publicly accessible
23
+
24
+ v0.0.2 / Tuesday; October 23, 2007
25
+
26
+ * first public release!
27
+ * add link to email group
28
+ * improve docs
29
+ * add hook file to load rake tasks when used as a gem
30
+ * change the env var for specifying the rails version under test to avoid name conflicts
31
+
32
+ v0.0.1 / Sunday; October 21, 2007
33
+
34
+ * initial release, no public announcement
@@ -0,0 +1,11 @@
1
+ Copyright (c) 2007-08 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.
@@ -0,0 +1,26 @@
1
+ autotest.rb
2
+ bin/multi_rails_runner.rb
3
+ CHANGELOG
4
+ credits.txt
5
+ install.rb
6
+ lib/multi_rails/config.rb
7
+ lib/multi_rails/core_extensions.rb
8
+ lib/multi_rails/loader.rb
9
+ lib/multi_rails/multi_rails_error.rb
10
+ lib/multi_rails/rails_app_helper.rb
11
+ lib/multi_rails.rb
12
+ lib/multi_rails_init.rb
13
+ Manifest
14
+ MIT-LICENSE
15
+ Rakefile
16
+ README.rdoc
17
+ tasks/load_multi_rails_rake_tasks.rb
18
+ tasks/multi_rails.rake
19
+ test/autotest/railsplugin.rb
20
+ test/config_test.rb
21
+ test/core_extensions_test.rb
22
+ test/install_test.rb
23
+ test/loader_test.rb
24
+ test/multi_rails_init_test.rb
25
+ test/multi_rails_test_helper.rb
26
+ test/rails_app_helper_test.rb
@@ -0,0 +1,116 @@
1
+ = MultiRails
2
+ by Relevance, http://thinkrelevance.com
3
+ Rob Sanheim - MultiRails lead
4
+ MultiRails lets you test your Rails plugin or app against many versions of Rails in one sweep.
5
+
6
+ == DESCRIPTION
7
+
8
+ 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.
9
+
10
+ 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 latest and greatest versions of Rails.
11
+
12
+ 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.
13
+
14
+ == FEATURES:
15
+
16
+ * easily test plugins/extensions using a require from your test_helper.rb and a require in your RakeFile
17
+ * rake tasks to test against a specified version of Rails, the latest version, or all versions
18
+ * tentative support for testing plain Rails apps against multiple versions of Rails
19
+ * Uses rubygems for version management of Rails
20
+
21
+ == TODOs:
22
+
23
+ * improve docs on how to override what files are required by multi_rails
24
+ * maybe add ability to load plain Rails versions -- ie checked out copies not in RubyGems
25
+
26
+ == NOTES:
27
+
28
+ * (__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.
29
+ * (__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
30
+
31
+ == REQUIREMENTS:
32
+
33
+ * Ruby 1.8.5 or higher
34
+ * Rubygems
35
+ * Rails 1.2.1 or higher
36
+ * Rails 2.0.0+ is not yet officially supported
37
+ * at least one copy of Rails installed via rubygems.
38
+
39
+ == INSTALLING FOR RAILS APPS
40
+
41
+ * install the plugin, which will copy the multi_rails_runner into your script folder on install.
42
+ grab the tar here: http://github.com/relevance/multi_rails/tarball/master
43
+ extract it inside vendor/plugins
44
+
45
+ * 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.
46
+ script/multi_rails_runner bootstrap
47
+
48
+ * Run your tests against all versions of Rails installed (the default):
49
+ script/multi_rails_runner
50
+ or run our tests against the most recent version of Rails you have installed:
51
+ script/multi_rails_runner latest
52
+ or just a specific version:
53
+ MULTIRAILS_RAILS_VERSION=1.2.5 script/multi_rails_runner one
54
+
55
+ == INSTALLING FOR PLUGINS
56
+
57
+ * Install multi_rails
58
+ sudo gem install multi_rails
59
+
60
+ * In your projects Rakefile, require the multi_rails Rake tasks.
61
+
62
+ require "load_multi_rails_rake_tasks"
63
+
64
+ * Run rake -T to verify you see the multi_rails tasks.
65
+ rake -T multi_rails
66
+ # should see "rake test:multi_rails:all, rake test:multi_rails:latest...etc"
67
+
68
+ * In your test_helper, require multi_rails_init *before* any rails specific requires (activerecord, actioncontroller, activesupport, etc).
69
+
70
+ require 'multi_rails_init'
71
+
72
+ * 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.
73
+
74
+ * 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.
75
+
76
+ == HELP
77
+
78
+ * Join the mailing list! - http://groups.google.com/group/multi_rails
79
+
80
+ * Rails plugin testing is pretty solid, but rails *app* testing is still new. Post issues to the mailing list.
81
+ * Getting gem activation errors? Post to the list with how you are using multi_rails, and I'll try to help.
82
+
83
+ == URLs
84
+
85
+ * Log bugs, issues, and suggestions on Trac: http://opensource.thinkrelevance.com/wiki/cap_gun
86
+
87
+ * rdocs http://thinkrelevance.rubyforge.org/multi_rails/
88
+ * mailing list http://groups.google.com/group/multi_rails
89
+
90
+ * view source http://github.com/relevance/multi_rails/tree/master
91
+ * get source git clone git://github.com/relevance/multi_rails.git
92
+
93
+ == LICENSE:
94
+
95
+ (The MIT License)
96
+
97
+ Copyright (c) 2007-8 Relevance, http://thinkrelevance.com
98
+
99
+ Permission is hereby granted, free of charge, to any person obtaining
100
+ a copy of this software and associated documentation files (the
101
+ 'Software'), to deal in the Software without restriction, including
102
+ without limitation the rights to use, copy, modify, merge, publish,
103
+ distribute, sublicense, and/or sell copies of the Software, and to
104
+ permit persons to whom the Software is furnished to do so, subject to
105
+ the following conditions:
106
+
107
+ The above copyright notice and this permission notice shall be
108
+ included in all copies or substantial portions of the Software.
109
+
110
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
111
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
112
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
113
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
114
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
115
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
116
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ begin
2
+ gem 'technicalpickles-echoe'
3
+ rescue LoadError => e
4
+ puts "couldn't find the correct version of echoe - please install from forked version on github: http://github.com/technicalpickles/echoe/"
5
+ puts "gem sources -a http://gems.github.com"
6
+ puts "sudo gem install technicalpickles-echoe"
7
+ end
8
+
9
+ require 'rubygems'
10
+ require 'echoe'
11
+ require File.expand_path(File.join(File.dirname(__FILE__), "/lib/multi_rails"))
12
+ load File.expand_path(File.join(File.dirname(__FILE__), "/tasks/multi_rails.rake"))
13
+
14
+ Echoe.new('multi_rails') do |p|
15
+ p.version = MultiRails::VERSION
16
+ p.rubyforge_name = 'thinkrelevance'
17
+ p.author = ['Rob Sanheim', 'Relevance']
18
+ p.email = 'multi_rails@googlegroups.com'
19
+ p.summary = 'Testing tool to easily test agaist multiple versions of Rails.'
20
+ p.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."
21
+ p.url = 'http://multi-rails.rubyforge.org/'
22
+ p.rdoc_pattern = /^(lib|bin|ext)|txt|rdoc|CHANGELOG|MIT-LICENSE$/
23
+ p.test_pattern = 'test/**/*_test.rb'
24
+ p.eval = lambda { self.require_paths = ['lib', 'tasks'] }
25
+ # p.manifest_name = 'manifest.txt'
26
+ rdoc_template = `allison --path`.strip << ".rb"
27
+ p.rdoc_template = rdoc_template
28
+ end
29
+
30
+ desc "Convert the readme from markdown to html to prep for posting on blog/email/whatever."
31
+ task :email_to_html => :email do
32
+ require 'redcloth'
33
+ RedCloth::DEFAULT_RULES.replace [:markdown, :textile]
34
+
35
+ email = File.read("email.txt")
36
+ html = RedCloth.new(email).to_html
37
+ html = text_helper.auto_link(html)
38
+ File.open("email.html", "w") do |f|
39
+ f << html
40
+ end
41
+ end
42
+
43
+ desc "Do a full release of the multi_rails, including copying to stable tag, pushing docs and prepping for blog/announcement."
44
+ task :full_release => [:require_version, :publish_docs, :email_to_html, :release]
45
+
46
+ desc "Must supply the VERSION env var"
47
+ task :require_version do
48
+ raise "You must supply a VERSION=x.x.x environment var to release!" unless ENV["VERSION"]
49
+ end
50
+
51
+ # it should be easier then this to do some g'd autolinking
52
+ def text_helper
53
+ gem 'actionpack'
54
+ require 'action_controller' # bringing this in for autolinks
55
+ helper = Object.new
56
+ helper.extend ActionView::Helpers::TextHelper
57
+ helper.extend ActionView::Helpers::TagHelper
58
+ helper
59
+ end
@@ -0,0 +1 @@
1
+ .autotest
@@ -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,3 @@
1
+ Thanks to:
2
+
3
+ Evan Weaver
@@ -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
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'logger'
3
+ files = %w(core_extensions config loader multi_rails_error rails_app_helper)
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.7'
10
+ BAR = "=" * 80 # BEST CONSTANT EVAH
11
+
12
+ def self.gem_and_require_rails
13
+ Loader.gem_and_require_rails
14
+ end
15
+ end
@@ -0,0 +1,38 @@
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_support
7
+ active_record
8
+ action_controller
9
+ action_controller/test_process]
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["MULTIRAILS_RAILS_VERSION"]) if ENV['MULTIRAILS_RAILS_VERSION']
16
+ Loader.latest_stable_version
17
+ end
18
+
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
+ version
23
+ end
24
+
25
+ # Output rails from the load path as a sanity check, to make sure we are really using the version of Rails we think we are
26
+ def rails_load_path
27
+ gem_rails_regex = %r[gems/(rails-[\d\.]+)/]
28
+ load_path.grep(gem_rails_regex).first.match(gem_rails_regex)[1] rescue nil
29
+ end
30
+
31
+ def load_path
32
+ $LOAD_PATH
33
+ end
34
+
35
+ end
36
+ end
37
+
38
+ 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,69 @@
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
+ # Require and gem rails
11
+ # Will use a default version if none is supplied
12
+ def self.gem_and_require_rails(rails_version = nil)
13
+ verify_rails_installed
14
+ rails_version = MultiRails::Config.version_lookup(rails_version)
15
+ Loader.new(rails_version).gem_and_require_rails
16
+ end
17
+
18
+ # Returns a list of all Rails versions available, oldest first
19
+ def self.all_rails_versions
20
+ specs = Gem::cache.find_name("rails")
21
+ specs.map {|spec| spec.version.to_s }.sort
22
+ end
23
+
24
+ # Try to detech the latest stable by finding the most recent version with less then 4 version parts
25
+ # -- not sure if there is a better way?
26
+ def self.latest_stable_version
27
+ all_rails_versions.sort.reverse.detect {|version| version.count(".") < 3 }
28
+ end
29
+
30
+ # Find the most recent version
31
+ def self.latest_version
32
+ all_rails_versions.sort.last
33
+ end
34
+
35
+ # Verify we have at least one Rails gem installed, otherwise fail early
36
+ def self.verify_rails_installed
37
+ raise MultiRailsError, "No Rails gems installed!" if Gem::cache.find_name("rails").empty?
38
+ end
39
+
40
+ # A version of the loader is created to gem and require one version of Rails
41
+ def initialize(version)
42
+ @version = version
43
+ end
44
+
45
+ # Gem a version of Rails, and require appropriate files
46
+ def gem_and_require_rails
47
+ gem_rails
48
+ require_rails
49
+ display_rails_gem_used
50
+ end
51
+
52
+ # Display the rails gem from the laod path, as a sanity check to make sure we are getting the rails version we expect
53
+ def display_rails_gem_used
54
+ puts %[#{MultiRails::BAR}\nUsing rails gem: #{Config.rails_load_path}\n]
55
+ end
56
+
57
+ def gem_rails
58
+ gem 'rails', version
59
+ rescue LoadError => e
60
+ msg = %Q[Cannot find gem for Rails version: '#{version}'!\nInstall the missing gem with:\nsudo gem install -v=#{version} rails]
61
+ raise MultiRailsError, msg
62
+ end
63
+
64
+ def require_rails
65
+ Config.rails_requires.each {|lib| require lib }
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,2 @@
1
+ class MultiRailsError < RuntimeError
2
+ end
@@ -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
@@ -0,0 +1,3 @@
1
+ # We include an init file here to be easily required using a gemmed version of MultiRails
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "multi_rails"))
3
+ MultiRails::gem_and_require_rails
@@ -0,0 +1,35 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{multi_rails}
3
+ s.version = "0.0.7"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new("= 1.2") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Rob Sanheim, Relevance"]
7
+ s.date = %q{2008-07-04}
8
+ s.default_executable = %q{multi_rails_runner.rb}
9
+ s.description = %q{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.}
10
+ s.email = %q{multi_rails@googlegroups.com}
11
+ s.executables = ["multi_rails_runner.rb"]
12
+ s.extra_rdoc_files = ["bin/multi_rails_runner.rb", "CHANGELOG", "credits.txt", "lib/multi_rails/config.rb", "lib/multi_rails/core_extensions.rb", "lib/multi_rails/loader.rb", "lib/multi_rails/multi_rails_error.rb", "lib/multi_rails/rails_app_helper.rb", "lib/multi_rails.rb", "lib/multi_rails_init.rb", "MIT-LICENSE", "README.rdoc"]
13
+ s.files = ["autotest.rb", "bin/multi_rails_runner.rb", "CHANGELOG", "credits.txt", "install.rb", "lib/multi_rails/config.rb", "lib/multi_rails/core_extensions.rb", "lib/multi_rails/loader.rb", "lib/multi_rails/multi_rails_error.rb", "lib/multi_rails/rails_app_helper.rb", "lib/multi_rails.rb", "lib/multi_rails_init.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README.rdoc", "tasks/load_multi_rails_rake_tasks.rb", "tasks/multi_rails.rake", "test/autotest/railsplugin.rb", "test/config_test.rb", "test/core_extensions_test.rb", "test/install_test.rb", "test/loader_test.rb", "test/multi_rails_init_test.rb", "test/multi_rails_test_helper.rb", "test/rails_app_helper_test.rb", "multi_rails.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://multi-rails.rubyforge.org/}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Multi_rails", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib", "tasks"]
18
+ s.rubyforge_project = %q{thinkrelevance}
19
+ s.rubygems_version = %q{1.2.0}
20
+ s.summary = %q{Testing tool to easily test agaist multiple versions of Rails.}
21
+ s.test_files = ["test/config_test.rb", "test/core_extensions_test.rb", "test/install_test.rb", "test/loader_test.rb", "test/multi_rails_init_test.rb", "test/rails_app_helper_test.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 2
26
+
27
+ if current_version >= 3 then
28
+ s.add_development_dependency(%q<echoe>, [">= 0"])
29
+ else
30
+ s.add_dependency(%q<echoe>, [">= 0"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<echoe>, [">= 0"])
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path(File.join(File.dirname(__FILE__), "multi_rails.rake"))
@@ -0,0 +1,91 @@
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
+ # Enable overriding the already invoked flag of a Rake task
7
+ class Rake::Task
8
+ attr_accessor :already_invoked
9
+ end
10
+
11
+ namespace :test do
12
+ namespace :multi_rails do
13
+
14
+ desc "Run against all installed versions of Rails. Local versions found: [#{MultiRails::Loader.all_rails_versions.to_sentence}]."
15
+ task :all do
16
+ begin
17
+ failed_versions = []
18
+ MultiRails::Loader.all_rails_versions.each_with_index do |version, index|
19
+ silence_warnings { ENV["MULTIRAILS_RAILS_VERSION"] = version }
20
+ init_for_rails_app(version) if within_rails_app?
21
+ print_rails_version
22
+ reset_test_tasks unless index == 0
23
+ begin
24
+ Rake::Task[:test].invoke
25
+ rescue RuntimeError => e
26
+ puts e.message
27
+ failed_versions << version
28
+ end
29
+ end
30
+ abort("Build failed with Rails versions: [#{failed_versions.to_sentence}].") if failed_versions.any?
31
+ ensure
32
+ clean_up
33
+ end
34
+ end
35
+
36
+ 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'"
37
+ task :one do
38
+ begin
39
+ version = ENV["MULTIRAILS_RAILS_VERSION"]
40
+ raise "Must give a version number" unless version
41
+ init_for_rails_app(version) if within_rails_app?
42
+ print_rails_version
43
+ Rake::Task[:test].invoke
44
+ ensure
45
+ clean_up
46
+ end
47
+ end
48
+
49
+ desc "Run against the most recent version of Rails installed. Most recent found: [#{MultiRails::Loader.latest_version}]."
50
+ task :latest do
51
+ begin
52
+ version = MultiRails::Loader.latest_version
53
+ ENV["MULTIRAILS_RAILS_VERSION"] = version
54
+ init_for_rails_app(version) if within_rails_app?
55
+ print_rails_version
56
+ Rake::Task[:test].invoke
57
+ ensure
58
+ clean_up
59
+ end
60
+ end
61
+
62
+ def init_for_rails_app(version)
63
+ MultiRails::RailsAppHelper.init_for_rails_app(version)
64
+ load "Rakefile"
65
+ end
66
+
67
+ def within_rails_app?
68
+ ENV["MULTIRAILS_FOR_RAILS_APP"] == "true"
69
+ end
70
+
71
+ # clean up after ourselves, reverting to clean state if needed
72
+ def clean_up
73
+ MultiRails::RailsAppHelper.clean_up if within_rails_app?
74
+ end
75
+
76
+ def print_rails_version
77
+ puts "\n#{MultiRails::BAR}\nTesting with Rails #{MultiRails::Config.version_lookup}\n#{MultiRails::BAR}"
78
+ end
79
+
80
+ # Need to hack the Rake test task a bit, otherwise it will only run once and never repeat.
81
+ def reset_test_tasks
82
+ ["test", "test:units", "test:functionals", "test:integration"].each do |name|
83
+ if Rake::Task.task_defined?(name)
84
+ Rake::Task[name].already_invoked = false
85
+ Rake::Task[name].prerequisites.each {|p| Rake::Task[p].already_invoked = false}
86
+ end
87
+ end
88
+ end
89
+
90
+ end
91
+ end
@@ -0,0 +1,31 @@
1
+ # Discover our lib and tests for autotest'ing Rails Plugins
2
+ class Autotest::Railsplugin < Autotest
3
+ def initialize
4
+ super
5
+ @exceptions = /\/\./
6
+ @test_mappings = {
7
+ /^lib\/(.*)\.rb$/ => proc { |filename, m|
8
+ file = File.basename(filename).gsub("_", "_?").gsub(".rb", "")
9
+ foo = files_matching %r%^test/.*#{file}_test.rb$%
10
+ foo
11
+ },
12
+ /^test\/.*_test\.rb$/ => proc { |filename, _|
13
+ filename
14
+ }
15
+ }
16
+ end
17
+
18
+ def files_matching regexp
19
+ # puts @files.sort.inspect
20
+ @files.keys.select { |k|
21
+ k =~ regexp
22
+ }
23
+ end
24
+
25
+ # def files_matching regexp
26
+ # @files.keys.select { |k|
27
+ # k =~ regexp
28
+ # }
29
+ # end
30
+
31
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "multi_rails_test_helper"))
2
+
3
+ describe "Version Lookup in config" do
4
+
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
+ 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["MULTIRAILS_RAILS_VERSION"] = "1.2.99"
14
+ MultiRails::Config.version_lookup.should == "1.2.99"
15
+ ensure
16
+ silence_warnings { ENV["MULTIRAILS_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["MULTIRAILS_RAILS_VERSION"] = "X.X.99"
23
+ lambda { MultiRails::Config.version_lookup }.should.raise(MultiRailsError)
24
+ ensure
25
+ silence_warnings { ENV["MULTIRAILS_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
33
+
34
+ describe "getting the rails load path " do
35
+ it "should grab only the real rails paths, and ignore false rails directories in the load path" do
36
+ load_path = ["/Users/rsanheim/src/relevance/essi/trunk/essi/vendor/plugins/test_spec_on_rails/lib",
37
+ "/Users/rsanheim/src/relevance/essi/trunk/essi/vendor/plugins/rails_env/lib",
38
+ "/opt/local/lib/ruby/gems/1.8/gems/rails-2.0.1/lib/../builtin/rails_info/", "/opt/local/lib/ruby/gems/1.8/gems/rails-2.0.1/lib",
39
+ "/opt/local/lib/ruby/gems/1.8/gems/rails-2.0.1/bin", "/Users/rsanheim/src/project/trunk/foo/vendor/gems/rails_env-0.4.0/lib"]
40
+ MultiRails::Config.stubs(:load_path).returns(load_path)
41
+ MultiRails::Config.rails_load_path.should == "rails-2.0.1"
42
+ end
43
+
44
+ it "should use the real load path" do
45
+ MultiRails::Config.load_path.should == $LOAD_PATH
46
+ end
47
+
48
+ it "should return nil if we can't figure out the rails version" do
49
+ load_path = ["/Users/rsanheim/src/relevance/essi/trunk/essi/vendor/plugins/test_spec_on_rails/lib",
50
+ "/Users/rsanheim/src/relevance/essi/trunk/essi/vendor/plugins/rails_env/lib"]
51
+ MultiRails::Config.stubs(:load_path).returns(load_path)
52
+ MultiRails::Config.rails_load_path.should == nil
53
+ end
54
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "multi_rails_test_helper"))
2
+
3
+ describe "core extensions" do
4
+ it "should extend Kernel" do
5
+ Kernel.should.respond_to? :silence_warnings
6
+ 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
@@ -0,0 +1,104 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "multi_rails_test_helper"))
2
+
3
+ describe "Loader with no Rails gem installed" do
4
+
5
+ it "should fail fast if we don't have any rails gems installed" do
6
+ Gem::cache.expects(:find_name).with("rails").returns([])
7
+ lambda { MultiRails::Loader.gem_and_require_rails }.should.raise(MultiRailsError).message.should == "No Rails gems installed!"
8
+ end
9
+
10
+ end
11
+ describe "Loader with at least one Rails gem installed" do
12
+
13
+ setup do
14
+ never_really_require_rails
15
+ never_puts
16
+ MultiRails::Loader.stubs(:verify_rails_installed).returns(nil)
17
+ end
18
+
19
+ it "should fall back to a default version to try" do
20
+ MultiRails::Loader.any_instance.stubs(:display_rails_gem_used)
21
+ stub_rails_requires
22
+ MultiRails::Loader.any_instance.expects(:gem).with("rails", MultiRails::Loader.latest_stable_version)
23
+ MultiRails::Loader.gem_and_require_rails
24
+ end
25
+
26
+ it "should fail fast if we are missing a requested gem version" do
27
+ lambda { MultiRails::Loader.gem_and_require_rails("9.9.9") }.should.raise(MultiRailsError)
28
+ end
29
+
30
+ it "should gem the specified version" do
31
+ MultiRails::Loader.any_instance.stubs(:display_rails_gem_used)
32
+ MultiRails::Config.stubs(:named_version_lookup).with("1.2.5").returns("1.2.5")
33
+ stub_rails_requires
34
+ MultiRails::Loader.any_instance.expects(:gem).with("rails", "1.2.5").returns(true)
35
+ MultiRails::Loader.gem_and_require_rails("1.2.5")
36
+ end
37
+
38
+ it "should allow using a better name for weird gem version numbers, like 2.0.0 PR => 1.2.4.7794" do
39
+ MultiRails::Loader.any_instance.stubs(:display_rails_gem_used)
40
+ MultiRails::Loader.stubs(:all_rails_versions).returns(["1.2.3", "1.2.4", "1.2.4.7794"])
41
+ stub_rails_requires
42
+ MultiRails::Loader.any_instance.expects(:gem).with("rails", MultiRails::Config.weird_versions["2.0.0.PR"]).returns(true)
43
+ MultiRails::Loader.gem_and_require_rails("2.0.0.PR")
44
+ end
45
+
46
+ it "should require the needed dependancies" do
47
+ MultiRails::Loader.any_instance.stubs(:display_rails_gem_used)
48
+ MultiRails::Loader.any_instance.stubs(:gem)
49
+ MultiRails::Config.rails_requires.each do |file|
50
+ MultiRails::Loader.any_instance.expects(:require).with(file)
51
+ end
52
+ MultiRails::Loader.gem_and_require_rails
53
+ end
54
+
55
+ def stub_rails_requires
56
+ MultiRails::Loader.any_instance.stubs(:require).returns(true)
57
+ end
58
+
59
+ def never_really_require_rails
60
+ MultiRails::Loader.any_instance.expects(:require).never
61
+ end
62
+
63
+ end
64
+
65
+ describe "finding all gems of rails available" do
66
+
67
+ it "should find rails by name when retrieving all rails versions, in order to avoid false positives with other gems with rails in the name" do
68
+ Gem::cache.expects(:find_name).with("rails").returns([])
69
+ MultiRails::Loader.all_rails_versions
70
+ end
71
+
72
+ it "should return all Rails versions it finds sorted with the earliest versions first" do
73
+ specs = [stub(:version => stub(:to_s => "1.2.4")), stub(:version => stub(:to_s => "1.2.3"))]
74
+ Gem::cache.expects(:find_name).with("rails").returns(specs)
75
+ MultiRails::Loader.all_rails_versions.should == ["1.2.3", "1.2.4"]
76
+ end
77
+
78
+ end
79
+
80
+ describe "finding latest stable version" do
81
+ it "should find the latest stable rails gem" do
82
+ MultiRails::Loader.stubs(:all_rails_versions).returns(["1.2.3", "1.2.5", "1.2.5.1343"])
83
+ MultiRails::Loader.latest_stable_version.should == "1.2.5"
84
+ end
85
+
86
+ it "should find 2.0.0 when its released" do
87
+ MultiRails::Loader.stubs(:all_rails_versions).returns(["1.2.3", "1.2.5", "1.2.5.1343", "2.0.0", "1.2.7"])
88
+ MultiRails::Loader.latest_stable_version.should == "2.0.0"
89
+ end
90
+
91
+ end
92
+
93
+ describe "finding latest version" do
94
+ it "should find the most recent version, regardless of edge or non edge versions" do
95
+ MultiRails::Loader.stubs(:all_rails_versions).returns(["1.2.3", "1.2.5", "1.2.5.1343"])
96
+ MultiRails::Loader.latest_version.should == "1.2.5.1343"
97
+ end
98
+
99
+ it "should return the only version you have if there is only one installed" do
100
+ MultiRails::Loader.stubs(:all_rails_versions).returns(["1.2.3"])
101
+ MultiRails::Loader.latest_version.should == "1.2.3"
102
+ end
103
+
104
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "multi_rails_test_helper"))
2
+
3
+ describe "Rubygem test helper init" do
4
+ setup { never_puts }
5
+
6
+ it "should call gem and require rails" do
7
+ MultiRails.expects(:gem_and_require_rails).once
8
+ load File.expand_path(File.join(File.dirname(__FILE__), "../lib/multi_rails_init.rb"))
9
+ end
10
+
11
+ it "should actually do the gem and require" do
12
+ MultiRails::Loader.stubs(:verify_rails_installed).returns(nil)
13
+ MultiRails::Loader.any_instance.expects(:require).never
14
+ MultiRails::Loader.any_instance.expects(:gem_rails)
15
+ MultiRails::Loader.any_instance.expects(:require_rails)
16
+ load File.expand_path(File.join(File.dirname(__FILE__), "../lib/multi_rails_init.rb"))
17
+ end
18
+
19
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ gem 'test-spec'
4
+ require 'test/spec'
5
+ require 'mocha'
6
+ require 'redgreen' unless Object.const_defined?("TextMate")
7
+
8
+ require File.expand_path(File.join(File.dirname(__FILE__), "../lib/multi_rails"))
9
+
10
+ class Test::Unit::TestCase
11
+ def never_puts
12
+ MultiRails::Loader.stubs(:puts)
13
+ MultiRails::Loader.any_instance.stubs(:puts)
14
+ end
15
+ end
@@ -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 ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: relevance-multi_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ platform: ruby
6
+ authors:
7
+ - Rob Sanheim, Relevance
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-04 00:00:00 -07:00
13
+ default_executable: multi_rails_runner.rb
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: echoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ 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.
25
+ email: multi_rails@googlegroups.com
26
+ executables:
27
+ - multi_rails_runner.rb
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - bin/multi_rails_runner.rb
32
+ - CHANGELOG
33
+ - credits.txt
34
+ - lib/multi_rails/config.rb
35
+ - lib/multi_rails/core_extensions.rb
36
+ - lib/multi_rails/loader.rb
37
+ - lib/multi_rails/multi_rails_error.rb
38
+ - lib/multi_rails/rails_app_helper.rb
39
+ - lib/multi_rails.rb
40
+ - lib/multi_rails_init.rb
41
+ - MIT-LICENSE
42
+ - README.rdoc
43
+ files:
44
+ - autotest.rb
45
+ - bin/multi_rails_runner.rb
46
+ - CHANGELOG
47
+ - credits.txt
48
+ - install.rb
49
+ - lib/multi_rails/config.rb
50
+ - lib/multi_rails/core_extensions.rb
51
+ - lib/multi_rails/loader.rb
52
+ - lib/multi_rails/multi_rails_error.rb
53
+ - lib/multi_rails/rails_app_helper.rb
54
+ - lib/multi_rails.rb
55
+ - lib/multi_rails_init.rb
56
+ - Manifest
57
+ - MIT-LICENSE
58
+ - Rakefile
59
+ - README.rdoc
60
+ - tasks/load_multi_rails_rake_tasks.rb
61
+ - tasks/multi_rails.rake
62
+ - test/autotest/railsplugin.rb
63
+ - test/config_test.rb
64
+ - test/core_extensions_test.rb
65
+ - test/install_test.rb
66
+ - test/loader_test.rb
67
+ - test/multi_rails_init_test.rb
68
+ - test/multi_rails_test_helper.rb
69
+ - test/rails_app_helper_test.rb
70
+ - multi_rails.gemspec
71
+ has_rdoc: true
72
+ homepage: http://multi-rails.rubyforge.org/
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --line-numbers
76
+ - --inline-source
77
+ - --title
78
+ - Multi_rails
79
+ - --main
80
+ - README.rdoc
81
+ require_paths:
82
+ - lib
83
+ - tasks
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "="
93
+ - !ruby/object:Gem::Version
94
+ version: "1.2"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project: thinkrelevance
99
+ rubygems_version: 1.2.0
100
+ signing_key:
101
+ specification_version: 2
102
+ summary: Testing tool to easily test agaist multiple versions of Rails.
103
+ test_files:
104
+ - test/config_test.rb
105
+ - test/core_extensions_test.rb
106
+ - test/install_test.rb
107
+ - test/loader_test.rb
108
+ - test/multi_rails_init_test.rb
109
+ - test/rails_app_helper_test.rb