|
20 | 20 | end |
21 | 21 |
|
22 | 22 | before do |
23 | | - @rack_env = ENV['RACK_ENV'] |
24 | | - @gem_path = Gem.path.to_a |
25 | | - @env_gem_path = ENV['GEM_PATH'] |
| 23 | + # start clean, in case another test was messing with paths |
| 24 | + Gem.clear_paths |
| 25 | + @original_rack_env = ENV['RACK_ENV'] |
| 26 | + @original_gem_path = Gem.path.to_a |
| 27 | + @original_env_gem_path = ENV['GEM_PATH'] |
26 | 28 | end |
27 | 29 |
|
28 | 30 | after do |
29 | | - @rack_env.nil? ? ENV.delete('RACK_ENV') : ENV['RACK_ENV'] = @rack_env |
30 | | - Gem.path.replace(@gem_path) |
31 | | - @env_gem_path.nil? ? ENV.delete('GEM_PATH') : ENV['GEM_PATH'] = @env_gem_path |
| 31 | + # Ensure everything is reset how it was |
| 32 | + @original_rack_env.nil? ? ENV.delete('RACK_ENV') : ENV['RACK_ENV'] = @original_rack_env |
| 33 | + @original_env_gem_path.nil? ? ENV.delete('GEM_PATH') : ENV['GEM_PATH'] = @original_env_gem_path |
| 34 | + Gem.clear_paths |
| 35 | + Gem.path.replace(@original_gem_path) |
| 36 | + |
| 37 | + aggregate_failures("expected Gem.path to be restored after test") do |
| 38 | + expect(ENV['GEM_PATH']).to eq @original_env_gem_path |
| 39 | + expect(Gem.path).to eql @original_gem_path |
| 40 | + end |
32 | 41 | end |
33 | 42 |
|
34 | 43 | it "should determine the public html root from the 'public.root' init parameter" do |
|
93 | 102 | end |
94 | 103 |
|
95 | 104 | it "prepends gem_path to Gem.path (when configured to not mangle with ENV)" do |
96 | | - expect(@rack_context).to receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return 'false' |
97 | 105 | Gem.path.replace ['/opt/gems'] |
| 106 | + expect(@rack_context).to receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return 'false' |
| 107 | + |
98 | 108 | booter.gem_path = "wsjar:file:/opt/deploy/sample.war!/WEB-INF/gems" |
99 | 109 | booter.boot! |
100 | 110 |
|
101 | 111 | expect(Gem.path).to eql ['wsjar:file:/opt/deploy/sample.war!/WEB-INF/gems', '/opt/gems'] |
102 | 112 | end |
103 | 113 |
|
104 | 114 | it "prepends gem_path to Gem.path if not already present" do |
105 | | - Gem.path.replace ["file:/home/gems", "/usr/local/gems"] |
| 115 | + ENV['GEM_PATH'] = "file:/home/gems#{File::PATH_SEPARATOR}/usr/local/gems" |
| 116 | + Gem.clear_paths |
| 117 | + |
106 | 118 | booter.gem_path = '/usr/local/gems' |
107 | 119 | booter.boot! |
108 | 120 |
|
109 | | - expect(Gem.path).to eql ["file:/home/gems", "/usr/local/gems"] |
| 121 | + expect(Gem.path).to start_with ["file:/home/gems", "/usr/local/gems"] |
| 122 | + expect(ENV['GEM_PATH']).to eq "file:/home/gems#{File::PATH_SEPARATOR}/usr/local/gems" |
110 | 123 | end |
111 | 124 |
|
112 | 125 | it "does not change Gem.path if gem_path empty" do |
113 | | - Gem.path.replace ['/opt/gems'] |
| 126 | + ENV['GEM_PATH'] = '/opt/gems' |
| 127 | + Gem.clear_paths |
| 128 | + |
114 | 129 | booter.gem_path = "" |
115 | 130 | booter.boot! |
116 | 131 |
|
117 | | - expect(Gem.path).to eql ['/opt/gems'] |
| 132 | + expect(Gem.path).to start_with ['/opt/gems'] |
| 133 | + expect(ENV['GEM_PATH']).to eq '/opt/gems' |
118 | 134 | end |
119 | 135 |
|
120 | 136 | it "prepends gem_path to ENV['GEM_PATH'] if jruby.rack.gem_path set to true" do |
121 | 137 | expect(@rack_context).to receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return 'true' |
122 | 138 | ENV['GEM_PATH'] = '/opt/gems' |
| 139 | + Gem.clear_paths |
123 | 140 | expect(@rack_context).to receive(:getRealPath).with("/WEB-INF").and_return "/opt/deploy/sample.war!/WEB-INF" |
124 | 141 | expect(@rack_context).to receive(:getRealPath).with("/WEB-INF/gems").and_return "/opt/deploy/sample.war!/WEB-INF/gems" |
125 | 142 |
|
126 | 143 | booter.boot! |
127 | 144 |
|
128 | 145 | expect(ENV['GEM_PATH']).to eq "/opt/deploy/sample.war!/WEB-INF/gems#{File::PATH_SEPARATOR}/opt/gems" |
| 146 | + expect(Gem.path).to start_with ["/opt/deploy/sample.war!/WEB-INF/gems", "/opt/gems"] |
129 | 147 | end |
130 | 148 |
|
131 | 149 | it "does not prepend gem_path to ENV['GEM_PATH'] if jruby.rack.gem_path set not set" do |
132 | 150 | expect(@rack_context).to receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return '' |
133 | 151 | ENV['GEM_PATH'] = '/opt/gems' |
| 152 | + Gem.clear_paths |
134 | 153 | expect(@rack_context).to receive(:getRealPath).with("/WEB-INF").and_return "/opt/deploy/sample.war!/WEB-INF" |
135 | 154 | expect(@rack_context).to receive(:getRealPath).with("/WEB-INF/gems").and_return "/opt/deploy/sample.war!/WEB-INF/gems" |
136 | 155 |
|
137 | 156 | booter.boot! |
138 | 157 |
|
139 | 158 | expect(ENV['GEM_PATH']).to eq "/opt/gems" |
| 159 | + expect(Gem.path).to start_with ["/opt/gems"] |
140 | 160 | end |
141 | 161 |
|
142 | 162 | it "prepends gem_path to ENV['GEM_PATH'] if not already present" do |
143 | 163 | ENV['GEM_PATH'] = "/home/gems#{File::PATH_SEPARATOR}/usr/local/gems" |
| 164 | + Gem.clear_paths |
144 | 165 | booter.gem_path = '/usr/local/gems' |
145 | 166 | booter.boot! |
146 | 167 |
|
147 | 168 | expect(ENV['GEM_PATH']).to eq "/home/gems#{File::PATH_SEPARATOR}/usr/local/gems" |
| 169 | + expect(Gem.path).to start_with ["/home/gems", "/usr/local/gems"] |
| 170 | + end |
| 171 | + |
| 172 | + it "keeps ENV['GEM_PATH'] when gem_path is nil" do |
| 173 | + ENV['GEM_PATH'] = '/usr/local/gems' |
| 174 | + Gem.clear_paths |
| 175 | + |
| 176 | + booter.layout = layout = double('layout') |
| 177 | + allow(layout).to receive(:app_path).and_return '.' |
| 178 | + allow(layout).to receive(:public_path).and_return nil |
| 179 | + expect(layout).to receive(:gem_path).and_return nil |
| 180 | + booter.boot! |
| 181 | + |
| 182 | + expect(ENV['GEM_PATH']).to eq "/usr/local/gems" |
| 183 | + expect(Gem.path).to start_with ["/usr/local/gems"] |
148 | 184 | end |
149 | 185 |
|
150 | 186 | it "sets ENV['GEM_PATH'] to the value of gem_path if ENV['GEM_PATH'] is not present" do |
|
156 | 192 | booter.boot! |
157 | 193 |
|
158 | 194 | expect(ENV['GEM_PATH']).to eq "/blah/gems" |
| 195 | + expect(Gem.path).to start_with ["/blah/gems"] |
159 | 196 | end |
160 | 197 |
|
161 | 198 | before { $loaded_init_rb = nil } |
|
209 | 246 | # at RUBY.boot!(classpath:/jruby/rack/booter.rb:105) |
210 | 247 | # at RUBY.(root)(classpath:/jruby/rack/boot/rack.rb:10) |
211 | 248 | app_dir = "#{File.absolute_path Dir.pwd}/sample.war!/WEB-INF" |
212 | | - allow(File).to receive(:directory?).with(app_dir).and_return true |
213 | 249 | allow(booter).to receive(:layout).and_return layout = double('layout') |
214 | 250 | allow(layout).to receive(:app_path).and_return app_dir |
215 | 251 | allow(layout).to receive(:gem_path) |
216 | 252 | allow(layout).to receive(:public_path) |
| 253 | + allow(File).to receive(:directory?).and_wrap_original { |m, *args| m.call(*args) } |
| 254 | + expect(File).to receive(:directory?).with(app_dir).and_return true |
217 | 255 |
|
218 | 256 | booter.boot! # expect to_not raise_error |
219 | 257 | end |
|
0 commit comments