public
Rubygem
Description: Makes tests easy on the fingers and the eyes
Homepage: http://www.thoughtbot.com/projects/shoulda
Clone URL: git://github.com/thoughtbot/shoulda.git
Upped rails_root to depend on Rails 2.1.0
rmm5t (author)
Tue Jul 01 06:15:13 -0700 2008
commit  9f8c29edf3e632cdbc9756f6c5792bdc8cc9494c
tree    c7684ff03add9b697b7a1a88eecc2520c6c30f38
parent  5aed59248b6292be6dba3a928db5f73b24ae1213
...
1
 
 
2
3
4
 
5
6
7
8
9
 
 
 
 
 
 
 
 
10
11
12
 
 
 
 
 
 
 
 
 
 
 
13
14
15
16
17
18
 
 
 
19
20
21
22
 
 
 
 
23
24
25
26
 
 
 
 
 
 
27
28
29
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
32
33
34
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
37
38
39
40
 
 
 
 
 
 
 
 
 
41
42
43
44
45
 
 
 
...
 
1
2
3
 
 
4
5
 
 
 
 
6
7
8
9
10
11
12
13
14
 
 
15
16
17
18
19
20
21
22
23
24
25
26
 
 
 
 
 
27
28
29
30
 
 
 
31
32
33
34
35
 
 
 
36
37
38
39
40
41
42
 
 
 
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 
 
 
 
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 
 
 
95
96
97
98
99
100
101
102
103
104
105
 
 
106
107
108
109
0
@@ -1,45 +1,109 @@
0
-# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb
0
+# Don't change this file!
0
+# Configure your app in config/environment.rb and config/environments/*.rb
0
 
0
-unless defined?(RAILS_ROOT)
0
- root_path = File.join(File.dirname(__FILE__), '..')
0
+RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
0
 
0
- unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
0
- require 'pathname'
0
- root_path = Pathname.new(root_path).cleanpath(true).to_s
0
- end
0
+module Rails
0
+ class << self
0
+ def boot!
0
+ unless booted?
0
+ preinitialize
0
+ pick_boot.run
0
+ end
0
+ end
0
 
0
- RAILS_ROOT = root_path
0
-end
0
+ def booted?
0
+ defined? Rails::Initializer
0
+ end
0
+
0
+ def pick_boot
0
+ (vendor_rails? ? VendorBoot : GemBoot).new
0
+ end
0
+
0
+ def vendor_rails?
0
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
0
+ end
0
 
0
-unless defined?(Rails::Initializer)
0
- if File.directory?("#{RAILS_ROOT}/vendor/rails")
0
- require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
0
- else
0
- require 'rubygems'
0
+ def preinitialize
0
+ load(preinitializer_path) if File.exist?(preinitializer_path)
0
+ end
0
 
0
- environment_without_comments = IO.readlines(File.dirname(__FILE__) + '/environment.rb').reject { |l| l =~ /^#/ }.join
0
- environment_without_comments =~ /[^#]RAILS_GEM_VERSION = '([\d.]+)'/
0
- rails_gem_version = $1
0
+ def preinitializer_path
0
+ "#{RAILS_ROOT}/config/preinitializer.rb"
0
+ end
0
+ end
0
 
0
- if version = defined?(RAILS_GEM_VERSION) ? RAILS_GEM_VERSION : rails_gem_version
0
- # Asking for 1.1.6 will give you 1.1.6.5206, if available -- makes it easier to use beta gems
0
- rails_gem = Gem.cache.search('rails', "~>#{version}.0").sort_by { |g| g.version.version }.last
0
+ class Boot
0
+ def run
0
+ load_initializer
0
+ Rails::Initializer.run(:set_load_path)
0
+ end
0
+ end
0
 
0
- if rails_gem
0
- gem "rails", "=#{rails_gem.version.version}"
0
- require rails_gem.full_gem_path + '/lib/initializer'
0
+ class VendorBoot < Boot
0
+ def load_initializer
0
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
0
+ Rails::Initializer.run(:install_gem_spec_stubs)
0
+ end
0
+ end
0
+
0
+ class GemBoot < Boot
0
+ def load_initializer
0
+ self.class.load_rubygems
0
+ load_rails_gem
0
+ require 'initializer'
0
+ end
0
+
0
+ def load_rails_gem
0
+ if version = self.class.gem_version
0
+ gem 'rails', version
0
       else
0
- STDERR.puts %(Cannot find gem for Rails ~>#{version}.0:
0
- Install the missing gem with 'gem install -v=#{version} rails', or
0
- change environment.rb to define RAILS_GEM_VERSION with your desired version.
0
- )
0
+ gem 'rails'
0
+ end
0
+ rescue Gem::LoadError => load_error
0
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
0
+ exit 1
0
+ end
0
+
0
+ class << self
0
+ def rubygems_version
0
+ Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
0
+ end
0
+
0
+ def gem_version
0
+ if defined? RAILS_GEM_VERSION
0
+ RAILS_GEM_VERSION
0
+ elsif ENV.include?('RAILS_GEM_VERSION')
0
+ ENV['RAILS_GEM_VERSION']
0
+ else
0
+ parse_gem_version(read_environment_rb)
0
+ end
0
+ end
0
+
0
+ def load_rubygems
0
+ require 'rubygems'
0
+
0
+ unless rubygems_version >= '0.9.4'
0
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
0
+ exit 1
0
+ end
0
+
0
+ rescue LoadError
0
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
0
         exit 1
0
       end
0
- else
0
- gem "rails"
0
- require 'initializer'
0
+
0
+ def parse_gem_version(text)
0
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
0
+ end
0
+
0
+ private
0
+ def read_environment_rb
0
+ File.read("#{RAILS_ROOT}/config/environment.rb")
0
+ end
0
     end
0
   end
0
-
0
- Rails::Initializer.run(:set_load_path)
0
 end
0
+
0
+# All that for this:
0
+Rails.boot!
...
1
2
3
 
4
5
 
6
7
 
8
9
10
...
15
16
17
18
19
 
...
1
2
 
3
4
 
5
6
 
7
8
9
10
...
15
16
17
 
18
19
0
@@ -1,10 +1,10 @@
0
 # Specifies gem version of Rails to use when vendor/rails is not present
0
 old_verbose, $VERBOSE = $VERBOSE, nil
0
-RAILS_GEM_VERSION = '2.0.2'
0
+RAILS_GEM_VERSION = '2.1.0' unless defined? RAILS_GEM_VERSION
0
 $VERBOSE = old_verbose
0
-
0
+
0
 require File.join(File.dirname(__FILE__), 'boot')
0
-
0
+
0
 Rails::Initializer.run do |config|
0
   # Someday, I'm going to find a way of getting rid of that symlink...
0
   # config.plugin_paths = ['../../../']
0
@@ -15,4 +15,4 @@ Rails::Initializer.run do |config|
0
   # config.load_paths << File.join(File.dirname(__FILE__), *%w{.. .. .. lib})
0
 end
0
  
0
-# Dependencies.log_activity = true
0
\ No newline at end of file
0
+# Dependencies.log_activity = true
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@
0
 
0
 <head>
0
   <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
0
- <title>We're sorry, but something went wrong</title>
0
+ <title>We're sorry, but something went wrong (500)</title>
0
   <style type="text/css">
0
     body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
0
     div.dialog {
...
1
2
3
4
 
...
1
2
 
3
4
0
@@ -1,3 +1,3 @@
0
 #!/usr/bin/env ruby
0
 require File.dirname(__FILE__) + '/../config/boot'
0
-require 'commands/console'
0
\ No newline at end of file
0
+require 'commands/console'
...
1
2
3
4
 
...
1
2
 
3
4
0
@@ -1,3 +1,3 @@
0
 #!/usr/bin/env ruby
0
 require File.dirname(__FILE__) + '/../config/boot'
0
-require 'commands/generate'
0
\ No newline at end of file
0
+require 'commands/generate'

Comments