moving app server lookup out into a factory
This commit is contained in:
parent
6816c46d47
commit
a6a4a7cfd9
@ -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
|
||||
|
37
lib/webrat/selenium/application_server_factory.rb
Normal file
37
lib/webrat/selenium/application_server_factory.rb
Normal file
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
44
spec/public/selenium/application_server_factory_spec.rb
Normal file
44
spec/public/selenium/application_server_factory_spec.rb
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user