diff --git a/lib/webrat/selenium/application_server.rb b/lib/webrat/selenium/application_server.rb index 8050b72..75ea0b3 100644 --- a/lib/webrat/selenium/application_server.rb +++ b/lib/webrat/selenium/application_server.rb @@ -5,34 +5,6 @@ module Webrat include Webrat::Selenium::SilenceStream - def self.boot - case Webrat.configuration.application_framework - when :sinatra - require "webrat/selenium/sinatra_application_server" - SinatraApplicationServer.new.boot - when :merb - require "webrat/selenium/merb_application_server" - MerbApplicationServer.new.boot - when :rails - require "webrat/selenium/rails_application_server" - RailsApplicationServer.new.boot - else - raise WebratError.new(<<-STR) -Unknown Webrat application_framework: #{Webrat.configuration.application_framework.inspect} - -Please ensure you have a Webrat configuration block that specifies an application_framework -in your test_helper.rb, spec_helper.rb, or env.rb (for Cucumber). - -For example: - - Webrat.configure do |config| - # ... - config.application_framework = :rails - end - STR - end - end - def boot start wait diff --git a/lib/webrat/selenium/application_server_factory.rb b/lib/webrat/selenium/application_server_factory.rb new file mode 100644 index 0000000..d56565b --- /dev/null +++ b/lib/webrat/selenium/application_server_factory.rb @@ -0,0 +1,37 @@ +module Webrat + module Selenium + + class ApplicationServerFactory + + def self.app_server_instance + case Webrat.configuration.application_framework + when :sinatra + require "webrat/selenium/sinatra_application_server" + return SinatraApplicationServer.new + when :merb + require "webrat/selenium/merb_application_server" + return MerbApplicationServer.new + when :rails + require "webrat/selenium/rails_application_server" + return RailsApplicationServer.new + else + raise WebratError.new(<<-STR) +Unknown Webrat application_framework: #{Webrat.configuration.application_framework.inspect} + +Please ensure you have a Webrat configuration block that specifies an application_framework +in your test_helper.rb, spec_helper.rb, or env.rb (for Cucumber). + +For example: + + Webrat.configure do |config| + # ... + config.application_framework = :rails + end + STR + end + end + + end + + end +end diff --git a/lib/webrat/selenium/selenium_session.rb b/lib/webrat/selenium/selenium_session.rb index 56de115..6a0324e 100644 --- a/lib/webrat/selenium/selenium_session.rb +++ b/lib/webrat/selenium/selenium_session.rb @@ -1,5 +1,6 @@ require "webrat/core/save_and_open_page" require "webrat/selenium/selenium_rc_server" +require "webrat/selenium/application_server_factory" require "webrat/selenium/application_server" module Webrat @@ -198,7 +199,7 @@ module Webrat def setup #:nodoc: Webrat::Selenium::SeleniumRCServer.boot - Webrat::Selenium::ApplicationServer.boot + Webrat::Selenium::ApplicationServerFactory.app_server_instance.boot create_browser $browser.start diff --git a/spec/integration/rails/test/integration/webrat_test.rb b/spec/integration/rails/test/integration/webrat_test.rb index 7df1d9c..ea22869 100644 --- a/spec/integration/rails/test/integration/webrat_test.rb +++ b/spec/integration/rails/test/integration/webrat_test.rb @@ -34,6 +34,9 @@ class WebratTest < ActionController::IntegrationTest fill_in "Text field", :with => "value" click_button + automate do + selenium.wait_for_page_to_load + end assert response.body !~ /value/ assert response.body =~ /custom_param/ end diff --git a/spec/public/selenium/application_server_factory_spec.rb b/spec/public/selenium/application_server_factory_spec.rb new file mode 100644 index 0000000..a709863 --- /dev/null +++ b/spec/public/selenium/application_server_factory_spec.rb @@ -0,0 +1,44 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +require "webrat/selenium/silence_stream" +require "webrat/selenium/application_server_factory" +require "webrat/selenium/application_server" + +require "webrat/selenium/sinatra_application_server" +require "webrat/selenium/merb_application_server" +require "webrat/selenium/rails_application_server" + +describe Webrat::Selenium::ApplicationServerFactory do + + it "should require and create a sinatra server in sinatra mode" do + server = mock(Webrat::Selenium::SinatraApplicationServer) + Webrat.configuration.application_framework = :sinatra + Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/sinatra_application_server") + Webrat::Selenium::SinatraApplicationServer.should_receive(:new).and_return(server) + Webrat::Selenium::ApplicationServerFactory.app_server_instance.should == server + end + + it "should require and create a merb server in merb mode" do + server = mock(Webrat::Selenium::MerbApplicationServer) + Webrat.configuration.application_framework = :merb + Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/merb_application_server") + Webrat::Selenium::MerbApplicationServer.should_receive(:new).and_return(server) + Webrat::Selenium::ApplicationServerFactory.app_server_instance + end + + it "should require and create a rails server in rails mode" do + server = mock(Webrat::Selenium::RailsApplicationServer) + Webrat.configuration.application_framework = :rails + Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/rails_application_server") + Webrat::Selenium::RailsApplicationServer.should_receive(:new).and_return(server) + Webrat::Selenium::ApplicationServerFactory.app_server_instance + end + + it "should handle unknown servers with an exception in unknown modes" do + Webrat.configuration.application_framework = :unknown + lambda { + Webrat::Selenium::ApplicationServerFactory.app_server_instance + }.should raise_error(Webrat::WebratError) + end + +end