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