|
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 |
|
90 | 99 | end |
91 | 100 |
|
92 | 101 | 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 | 102 | Gem.path.replace ['/opt/gems'] |
| 103 | + expect(@rack_context).to receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return 'false' |
| 104 | + |
95 | 105 | booter.gem_path = "wsjar:file:/opt/deploy/sample.war!/WEB-INF/gems" |
96 | 106 | booter.boot! |
97 | 107 |
|
98 | 108 | expect(Gem.path).to eql ['wsjar:file:/opt/deploy/sample.war!/WEB-INF/gems', '/opt/gems'] |
99 | 109 | end |
100 | 110 |
|
101 | 111 | it "prepends gem_path to Gem.path if not already present" do |
102 | | - Gem.path.replace ["file:/home/gems", "/usr/local/gems"] |
| 112 | + ENV['GEM_PATH'] = "file:/home/gems#{File::PATH_SEPARATOR}/usr/local/gems" |
| 113 | + Gem.clear_paths |
| 114 | + |
103 | 115 | booter.gem_path = '/usr/local/gems' |
104 | 116 | booter.boot! |
105 | 117 |
|
106 | | - expect(Gem.path).to eql ["file:/home/gems", "/usr/local/gems"] |
| 118 | + expect(Gem.path).to start_with ["file:/home/gems", "/usr/local/gems"] |
| 119 | + expect(ENV['GEM_PATH']).to eq "file:/home/gems#{File::PATH_SEPARATOR}/usr/local/gems" |
107 | 120 | end |
108 | 121 |
|
109 | 122 | it "does not change Gem.path if gem_path empty" do |
110 | | - Gem.path.replace ['/opt/gems'] |
| 123 | + ENV['GEM_PATH'] = '/opt/gems' |
| 124 | + Gem.clear_paths |
| 125 | + |
111 | 126 | booter.gem_path = "" |
112 | 127 | booter.boot! |
113 | 128 |
|
114 | | - expect(Gem.path).to eql ['/opt/gems'] |
| 129 | + expect(Gem.path).to start_with ['/opt/gems'] |
| 130 | + expect(ENV['GEM_PATH']).to eq '/opt/gems' |
115 | 131 | end |
116 | 132 |
|
117 | 133 | it "prepends gem_path to ENV['GEM_PATH'] if jruby.rack.gem_path set to true" do |
118 | 134 | expect(@rack_context).to receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return 'true' |
119 | 135 | ENV['GEM_PATH'] = '/opt/gems' |
| 136 | + Gem.clear_paths |
120 | 137 | expect(@rack_context).to receive(:getRealPath).with("/WEB-INF").and_return "/opt/deploy/sample.war!/WEB-INF" |
121 | 138 | expect(@rack_context).to receive(:getRealPath).with("/WEB-INF/gems").and_return "/opt/deploy/sample.war!/WEB-INF/gems" |
122 | 139 |
|
123 | 140 | booter.boot! |
124 | 141 |
|
125 | 142 | expect(ENV['GEM_PATH']).to eq "/opt/deploy/sample.war!/WEB-INF/gems#{File::PATH_SEPARATOR}/opt/gems" |
| 143 | + expect(Gem.path).to start_with ["/opt/deploy/sample.war!/WEB-INF/gems", "/opt/gems"] |
126 | 144 | end |
127 | 145 |
|
128 | 146 | it "does not prepend gem_path to ENV['GEM_PATH'] if jruby.rack.gem_path set not set" do |
129 | 147 | expect(@rack_context).to receive(:getInitParameter).with("jruby.rack.env.gem_path").and_return '' |
130 | 148 | ENV['GEM_PATH'] = '/opt/gems' |
| 149 | + Gem.clear_paths |
131 | 150 | expect(@rack_context).to receive(:getRealPath).with("/WEB-INF").and_return "/opt/deploy/sample.war!/WEB-INF" |
132 | 151 | expect(@rack_context).to receive(:getRealPath).with("/WEB-INF/gems").and_return "/opt/deploy/sample.war!/WEB-INF/gems" |
133 | 152 |
|
134 | 153 | booter.boot! |
135 | 154 |
|
136 | 155 | expect(ENV['GEM_PATH']).to eq "/opt/gems" |
| 156 | + expect(Gem.path).to start_with ["/opt/gems"] |
137 | 157 | end |
138 | 158 |
|
139 | 159 | it "prepends gem_path to ENV['GEM_PATH'] if not already present" do |
140 | 160 | ENV['GEM_PATH'] = "/home/gems#{File::PATH_SEPARATOR}/usr/local/gems" |
| 161 | + Gem.clear_paths |
141 | 162 | booter.gem_path = '/usr/local/gems' |
142 | 163 | booter.boot! |
143 | 164 |
|
144 | 165 | expect(ENV['GEM_PATH']).to eq "/home/gems#{File::PATH_SEPARATOR}/usr/local/gems" |
| 166 | + expect(Gem.path).to start_with ["/home/gems", "/usr/local/gems"] |
| 167 | + end |
| 168 | + |
| 169 | + it "keeps ENV['GEM_PATH'] when gem_path is nil" do |
| 170 | + ENV['GEM_PATH'] = '/usr/local/gems' |
| 171 | + Gem.clear_paths |
| 172 | + |
| 173 | + booter.layout = layout = double('layout') |
| 174 | + allow(layout).to receive(:app_path).and_return '.' |
| 175 | + allow(layout).to receive(:public_path).and_return nil |
| 176 | + expect(layout).to receive(:gem_path).and_return nil |
| 177 | + booter.boot! |
| 178 | + |
| 179 | + expect(ENV['GEM_PATH']).to eq "/usr/local/gems" |
| 180 | + expect(Gem.path).to start_with ["/usr/local/gems"] |
145 | 181 | end |
146 | 182 |
|
147 | 183 | it "sets ENV['GEM_PATH'] to the value of gem_path if ENV['GEM_PATH'] is not present" do |
|
153 | 189 | booter.boot! |
154 | 190 |
|
155 | 191 | expect(ENV['GEM_PATH']).to eq "/blah/gems" |
| 192 | + expect(Gem.path).to start_with ["/blah/gems"] |
156 | 193 | end |
157 | 194 |
|
158 | 195 | it "creates a logger that writes messages to the servlet context (by default)" do |
|
214 | 251 | # at RUBY.boot!(classpath:/jruby/rack/booter.rb:105) |
215 | 252 | # at RUBY.(root)(classpath:/jruby/rack/boot/rack.rb:10) |
216 | 253 | app_dir = "#{File.absolute_path Dir.pwd}/sample.war!/WEB-INF" |
217 | | - allow(File).to receive(:directory?).with(app_dir).and_return true |
218 | 254 | allow(booter).to receive(:layout).and_return layout = double('layout') |
219 | 255 | allow(layout).to receive(:app_path).and_return app_dir |
220 | 256 | allow(layout).to receive(:gem_path) |
221 | 257 | allow(layout).to receive(:public_path) |
| 258 | + allow(File).to receive(:directory?).and_wrap_original { |m, *args| m.call(*args) } |
| 259 | + expect(File).to receive(:directory?).with(app_dir).and_return true |
222 | 260 |
|
223 | 261 | booter.boot! # expect to_not raise_error |
224 | 262 | end |
|
0 commit comments