From 926bcc6c66bc1e0fed384ed9896380987f7af7e7 Mon Sep 17 00:00:00 2001 From: snusnu Date: Wed, 13 May 2009 03:35:32 +0200 Subject: [PATCH] extracted silence_stream into its own file under webrat/selenium I don't think silence_stream.rb should be stored under core_extensions, because the way it's implemented, it simply is no core extension. Also, a grep through webrat source shows that silence_stream is only used inside the selenium support. This is why I added webrat/selenium/silence_stream.rb and require it *before* all other selenium related files in webrat/selenium.rb. It's necessary to include it this early, because if mode is set to :selenium, webrat/selenium.rb is required, which in turn requires webrat/selenium/selenium_session.rb and silence_stream must be available before selenium_session gets required because selenium_session already wants to silence the stream. --- lib/webrat/core/configuration.rb | 11 ----------- lib/webrat/selenium.rb | 1 + lib/webrat/selenium/application_server.rb | 2 +- lib/webrat/selenium/selenium_rc_server.rb | 2 +- lib/webrat/selenium/selenium_session.rb | 2 +- lib/webrat/selenium/silence_stream.rb | 14 ++++++++++++++ 6 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 lib/webrat/selenium/silence_stream.rb diff --git a/lib/webrat/core/configuration.rb b/lib/webrat/core/configuration.rb index 376cd36..33d274f 100755 --- a/lib/webrat/core/configuration.rb +++ b/lib/webrat/core/configuration.rb @@ -1,17 +1,6 @@ require "webrat/core_extensions/deprecate" module Webrat - - module SilentStream - 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 # Configures Webrat. If this is not done, Webrat will be created # with all of the default settings. diff --git a/lib/webrat/selenium.rb b/lib/webrat/selenium.rb index b7574fe..d47c583 100644 --- a/lib/webrat/selenium.rb +++ b/lib/webrat/selenium.rb @@ -1,6 +1,7 @@ require "webrat" gem "selenium-client", ">=1.2.14" require "selenium/client" +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/application_server.rb b/lib/webrat/selenium/application_server.rb index 65b2993..4f47332 100644 --- a/lib/webrat/selenium/application_server.rb +++ b/lib/webrat/selenium/application_server.rb @@ -3,7 +3,7 @@ module Webrat class ApplicationServer - include Webrat::SilentStream + include Webrat::Selenium::SilenceStream def self.boot case Webrat.configuration.application_framework diff --git a/lib/webrat/selenium/selenium_rc_server.rb b/lib/webrat/selenium/selenium_rc_server.rb index 2685af4..735adf6 100644 --- a/lib/webrat/selenium/selenium_rc_server.rb +++ b/lib/webrat/selenium/selenium_rc_server.rb @@ -3,7 +3,7 @@ module Webrat class SeleniumRCServer - include Webrat::SilentStream + include Webrat::Selenium::SilenceStream def self.boot new.boot diff --git a/lib/webrat/selenium/selenium_session.rb b/lib/webrat/selenium/selenium_session.rb index 5512f4e..c0d8f35 100644 --- a/lib/webrat/selenium/selenium_session.rb +++ b/lib/webrat/selenium/selenium_session.rb @@ -22,7 +22,7 @@ module Webrat class SeleniumSession include Webrat::SaveAndOpenPage - include Webrat::SilentStream + include Webrat::Selenium::SilenceStream def initialize(*args) # :nodoc: end diff --git a/lib/webrat/selenium/silence_stream.rb b/lib/webrat/selenium/silence_stream.rb new file mode 100644 index 0000000..a458306 --- /dev/null +++ b/lib/webrat/selenium/silence_stream.rb @@ -0,0 +1,14 @@ +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) + end + end + end +end \ No newline at end of file