spec/trinidad/web_app_spec.rb in trinidad-0.8.3 vs spec/trinidad/web_app_spec.rb in trinidad-0.9.0

- old
+ new

@@ -1,11 +1,13 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Trinidad::WebApp do before do @tomcat = Trinidad::Tomcat::Tomcat.new + @tomcat.host.app_base = Dir.pwd @tomcat_web_app = @tomcat.addWebapp('/', File.dirname(__FILE__) + '/../../') + @app = { :web_app_dir => MOCK_WEB_APP_DIR, :context_path => '/' } @config = { @@ -20,33 +22,35 @@ } @web_app = Trinidad::RailsWebApp.new(@tomcat_web_app, @config, @app) end it "creates a RailsWebApp if rackup option is not present" do - Trinidad::WebApp.create(@tomcat_web_app, @config, @app).is_a?(Trinidad::RailsWebApp).should be_true + app = Trinidad::WebApp.create(@tomcat_web_app, @config, @app) + app.should be_an_instance_of(Trinidad::RailsWebApp) end it "creates a RackupWebApp if rackup option is present" do rackup_app = {:rackup => 'config.ru'} @config.deep_merge({:web_apps => {:default => rackup_app}}) - Trinidad::WebApp.create(@tomcat_web_app, @config, rackup_app).is_a?(Trinidad::RackupWebApp).should be_true + app = Trinidad::WebApp.create(@tomcat_web_app, @config, rackup_app) + app.should be_an_instance_of(Trinidad::RackupWebApp) end it "should load custom jars" do class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader) @web_app.add_application_libs(class_loader) resource = class_loader.find_class('org.ho.yaml.Yaml') - resource.should_not == nil + resource.should_not be_nil end it "should load custom classes" do class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader) @web_app.add_application_classes(class_loader) resource = class_loader.find_class('HelloTomcat') - resource.should_not == nil + resource.should_not be_nil end it "should start application context without errors" do start_context end @@ -78,36 +82,53 @@ web_app.context.findParameter('jruby.min.runtimes').should == '4' web_app.context.findParameter('jruby.max.runtimes').should == '8' end - it "should configure rack filter" do - @web_app.add_rack_filter - @web_app.context.findFilterDefs().should have(1).filters + it "configures rack handler" do + @web_app.configure_rack + @web_app.context.findChild('RackServlet').should_not be_nil end - it "should configure rack listener" do + it "configures rack listener" do @web_app.add_rack_context_listener @web_app.context.findApplicationListeners().should have(1).listeners end - it "should have rack filter already configured" do + it "has rack handler already configured when web.xml includes it" do @web_app.load_default_web_xml - @web_app.rack_filter_configured?().should == true + @web_app.rack_configured?().should be_true - @web_app.add_rack_filter - @web_app.context.findFilterDefs().should have(0).filters + @web_app.configure_rack + @web_app.context.findChild('RackServlet').should be_nil end - it "should have rack listener already configured" do + it "has rack listener already configured when web.xml includes it" do @web_app.load_default_web_xml - @web_app.rack_listener_configured?().should == true + @web_app.rack_listener_configured?().should be_true @web_app.add_rack_context_listener @web_app.context.findApplicationListeners().should have(0).listeners end + it "loads the provided web.xml for rails applications" do + @config[:default_web_xml] = 'config/foo.xml' + app = Trinidad::WebApp.create(@tomcat_web_app, @config, @app) + + app.load_default_web_xml + app.context.default_web_xml.should =~ /rails_web.xml$/ + end + + it "loads the provided web.xml for rack applications" do + @config[:default_web_xml] = 'config/foo.xml' + @app[:rackup] = 'config.ru' + + app = Trinidad::WebApp.create(@tomcat_web_app, @config, @app) + app.load_default_web_xml + app.context.default_web_xml.should =~ /rackup_web.xml$/ + end + def start_context_with_web_xml @web_app.load_default_web_xml start_context end @@ -118,7 +139,6 @@ def load_tomcat_libs @web_app.config[:libs_dir] = File.join(File.dirname(__FILE__), '..', '..', 'tomcat-libs') @web_app.add_context_loader end - end