@@ -59,13 +59,15 @@ def assert_output(match)
59
59
#
60
60
# Automatically changes back to the working directory
61
61
# and removes the temp directory when done.
62
- def within_rails_app ( name , without_gems = [ ] , gem_locations = $gem_locations )
62
+ def within_rails_app ( name , without_gems = [ ] , gem_options = $gem_options )
63
63
sourcedir = File . expand_path ( "../../fixtures/#{ name } " , __FILE__ )
64
64
Dir . mktmpdir do |tmpdir |
65
65
FileUtils . cp_r "#{ sourcedir } /." , tmpdir
66
66
Dir . chdir ( tmpdir ) do
67
- gem_locations . each { |name , path | modify_gem_location name , path }
67
+ gem_options . each { |name , options | modify_gem_entry name , options }
68
68
without_gems . each { |name | remove_gem name }
69
+ puts File . read ( "Gemfile" )
70
+ FileUtils . rm ( "Gemfile.lock" )
69
71
runcmd "bundle install --verbose"
70
72
yield
71
73
end
@@ -81,23 +83,29 @@ def process_gemfile(gemfile = "Gemfile", &blk)
81
83
end
82
84
end
83
85
84
- def modify_gem_location ( gemname , path , gemfile = "Gemfile" )
86
+ def modify_gem_entry ( gemname , options , gemfile = "Gemfile" )
85
87
found = false
86
88
process_gemfile ( gemfile ) do |line |
87
89
if line =~ /gem *(["'])#{ Regexp . escape ( gemname ) } \1 /
88
90
found = true
89
- %Q{gem " #{ gemname } ", :path => #{ path . inspect } \n }
91
+ gem_entry ( gemname , options ) + " \n "
90
92
else
91
93
line
92
94
end
93
95
end
94
96
unless found
95
97
File . open ( gemfile , "a" ) do |f |
96
- f . print ( %Q{ \n gem " #{ gemname } ", :path => #{ path . inspect } \n } )
98
+ f . print ( " \n #{ gem_entry ( gemname , options ) } \n " )
97
99
end
98
100
end
99
101
end
100
102
103
+ def gem_entry ( gemname , options )
104
+ entry = %Q{gem "#{ gemname } ", "~> #{ options [ :version ] } "}
105
+ entry += ", :path => #{ options [ :path ] . inspect } " if options [ :path ]
106
+ entry
107
+ end
108
+
101
109
def remove_gem ( gemname )
102
110
process_gemfile ( gemfile ) do |line |
103
111
line unless line =~ /gem *(["'])#{ Regexp . escape ( gemname ) } \1 /
0 commit comments