Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moving app server lookup out into a factory
- Loading branch information
Mike Gaffney
committed
Jun 4, 2009
1 parent
6816c46
commit a6a4a7c
Showing
5 changed files
with
86 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |