From 627913708c563f136f17d7da1b85b961f20f143b Mon Sep 17 00:00:00 2001 From: Larry Diehl Date: Thu, 28 May 2009 22:40:52 -0700 Subject: [PATCH] Made Selenium Rails integration tests at least runnable, although there are failures. --- lib/webrat/selenium.rb | 8 +------- lib/webrat/selenium/silence_stream.rb | 20 +++++++++++-------- .../rails/test/integration/webrat_test.rb | 18 +++++++++++------ 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/webrat/selenium.rb b/lib/webrat/selenium.rb index 2564645..d47c583 100644 --- a/lib/webrat/selenium.rb +++ b/lib/webrat/selenium.rb @@ -1,13 +1,7 @@ require "webrat" gem "selenium-client", ">=1.2.14" require "selenium/client" - -# active_support already defines silence_stream, no need to do that again if it's already present. -# http://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/kernel/reporting.rb -unless Kernel.respond_to?(:silence_stream) - require "webrat/selenium/silence_stream" -end - +require "webrat/selenium/silence_stream" require "webrat/selenium/selenium_session" require "webrat/selenium/matchers" require "webrat/core_extensions/tcp_socket" diff --git a/lib/webrat/selenium/silence_stream.rb b/lib/webrat/selenium/silence_stream.rb index a458306..e1e6c74 100644 --- a/lib/webrat/selenium/silence_stream.rb +++ b/lib/webrat/selenium/silence_stream.rb @@ -1,14 +1,18 @@ module Webrat module Selenium module SilenceStream - def silence_stream(stream) - old_stream = stream.dup - stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null') - stream.sync = true - yield - ensure - stream.reopen(old_stream) + # active_support already defines silence_stream, no need to do that again if it's already present. + # http://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/kernel/reporting.rb + unless Kernel.respond_to?(:silence_stream) + def silence_stream(stream) + old_stream = stream.dup + stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null') + stream.sync = true + yield + ensure + stream.reopen(old_stream) + end end end end -end \ No newline at end of file +end diff --git a/spec/integration/rails/test/integration/webrat_test.rb b/spec/integration/rails/test/integration/webrat_test.rb index b1449ca..f0d51a4 100644 --- a/spec/integration/rails/test/integration/webrat_test.rb +++ b/spec/integration/rails/test/integration/webrat_test.rb @@ -2,9 +2,12 @@ require 'test_helper' class WebratTest < ActionController::IntegrationTest - test "should visit fully qualified urls" do - visit root_url(:host => "chunkybacon.example.com") - assert_equal "chunkybacon", request.subdomains.first + # Firefox raises a security concern under Selenium + unless ENV['WEBRAT_INTEGRATION_MODE'] == 'selenium' + test "should visit fully qualified urls" do + visit root_url(:host => "chunkybacon.example.com") + assert_equal "chunkybacon", request.subdomains.first + end end test "should visit pages" do @@ -68,9 +71,12 @@ class WebratTest < ActionController::IntegrationTest assert_have_selector "h1" end - test "should detect infinite redirects" do - assert_raises Webrat::InfiniteRedirectError do - visit infinite_redirect_path + # Firefox detects and prevents infinite redirects under Selenium + unless ENV['WEBRAT_INTEGRATION_MODE'] == 'selenium' + test "should detect infinite redirects" do + assert_raises Webrat::InfiniteRedirectError do + visit infinite_redirect_path + end end end