spec/warbler/war_spec.rb in warbler-1.2.0 vs spec/warbler/war_spec.rb in warbler-1.2.1
- old
+ new
@@ -25,12 +25,12 @@
(ENV.keys.grep(/BUNDLE/) + ["RUBYOPT", "GEM_PATH"]).each {|k| @env_save[k] = ENV[k]; ENV[k] = nil}
end
after(:each) do
rm_rf FileList["log", ".bundle", "tmp/war"]
- rm_f FileList["*.war", "config.ru", "*web.xml*", "config/web.xml*",
- "config/warble.rb", "file.txt", 'manifest', 'Gemfile*', 'MANIFEST.MF*']
+ rm_f FileList["*.war", "config.ru", "*web.xml*", "config/web.xml*", "config/warble.rb",
+ "file.txt", 'manifest', 'Gemfile*', 'MANIFEST.MF*', 'init.rb*']
Dir.chdir(@pwd)
@env_save.keys.each {|k| ENV[k] = @env_save[k]}
end
def file_list(regex)
@@ -449,7 +449,55 @@
it "should exclude test files in gems according to config.gem_excludes" do
@config.gem_excludes += [/^(test|spec)\//]
@war.apply(@config)
file_list(%r{WEB-INF/gems/gems/rake([^/]+)/test/test_rake.rb}).should be_empty
+ end
+
+ it "should create a META-INF/init.rb file with startup config" do
+ @war.apply(@config)
+ file_list(%r{META-INF/init.rb}).should_not be_empty
+ end
+
+ it "should allow adjusting the init file location in the war" do
+ @config.init_filename = 'WEB-INF/init.rb'
+ @war.add_init_file(@config)
+ file_list(%r{WEB-INF/init.rb}).should_not be_empty
+ end
+
+ it "should add RAILS_ENV to init.rb for Rails apps" do
+ @config = Warbler::Config.new { |c| c.webxml.booter = :rails }
+ @war.add_init_file(@config)
+ contents = @war.files['META-INF/init.rb'].read
+ contents.should =~ /ENV\['RAILS_ENV'\]/
+ contents.should =~ /'production'/
+ end
+
+ it "should add RACK_ENV to init.rb for Rack apps" do
+ @config = Warbler::Config.new { |c| c.webxml.booter = :rack }
+ @war.add_init_file(@config)
+ contents = @war.files['META-INF/init.rb'].read
+ contents.should =~ /ENV\['RACK_ENV'\]/
+ contents.should =~ /'production'/
+ end
+
+ it "should add BUNDLE_WITHOUT to init.rb when Bundler is used" do
+ File.open("Gemfile", "w") {|f| f << "gem 'rake'"}
+ @war.add_init_file(Warbler::Config.new)
+ contents = @war.files['META-INF/init.rb'].read
+ contents.should =~ /ENV\['BUNDLE_WITHOUT'\]/
+ contents.should =~ /'development:test'/
+ end
+
+ it "should allow adding custom files' contents to init.rb" do
+ @config = Warbler::Config.new { |c| c.init_contents << "Rakefile" }
+ @war.add_init_file(@config)
+ contents = @war.files['META-INF/init.rb'].read
+ contents.should =~ /require 'rake'/
+ end
+
+ it "should not have escaped HTML in WARBLER_CONFIG" do
+ @config.webxml.dummy = '<dummy/>'
+ @war.apply(@config)
+ @war.files['META-INF/init.rb'].read.should =~ /<dummy\/>/
end
end