updated from master
This commit is contained in:
parent
fbcd509097
commit
449edf4a10
|
@ -10,3 +10,4 @@ log
|
||||||
.loadpath
|
.loadpath
|
||||||
*.swp
|
*.swp
|
||||||
results
|
results
|
||||||
|
test_apps
|
22
History.txt
22
History.txt
|
@ -6,9 +6,13 @@
|
||||||
* Removed auto-require of webrat/rails when requiring webrat when RAILS_ENV is
|
* Removed auto-require of webrat/rails when requiring webrat when RAILS_ENV is
|
||||||
defined
|
defined
|
||||||
|
|
||||||
In your env.rb file, ensure you have:
|
In your env.rb or test_helper.rb file, ensure you have something like:
|
||||||
|
|
||||||
require "webrat/rails"
|
require "webrat"
|
||||||
|
|
||||||
|
Webrat.configure do |config|
|
||||||
|
config.mode = :rails
|
||||||
|
end
|
||||||
|
|
||||||
* Major enhancements
|
* Major enhancements
|
||||||
|
|
||||||
|
@ -16,7 +20,10 @@
|
||||||
* Use Hpricot and REXML when not parsing with Nokogiri (on JRuby, for example)
|
* Use Hpricot and REXML when not parsing with Nokogiri (on JRuby, for example)
|
||||||
|
|
||||||
* Minor enhancements
|
* Minor enhancements
|
||||||
* Now sets the mode with configuration.mode in the block (Mike Gaffney, Ticket #85)
|
* Added assert_contain, assert_not_contain [#86] (Mike Gaffney)
|
||||||
|
* Maximize the browser window after initializing Selenium (Luke Melia)
|
||||||
|
* Better inspect output for Webrat elements
|
||||||
|
* Sets the Webrat mode with Configuration#mode= in the config block [#85] (Mike Gaffney)
|
||||||
* Detect if the document is XML or HTML using the Content-Type when in Rails mode
|
* Detect if the document is XML or HTML using the Content-Type when in Rails mode
|
||||||
* Expose #selenium method for direct access to Selenium client
|
* Expose #selenium method for direct access to Selenium client
|
||||||
* Check nokogiri gem version before requiring nokogiri
|
* Check nokogiri gem version before requiring nokogiri
|
||||||
|
@ -50,6 +57,8 @@
|
||||||
* Raise Webrat::PageLoadError when a failure occurs so that application exceptions
|
* Raise Webrat::PageLoadError when a failure occurs so that application exceptions
|
||||||
can be more accurately tested (Ryan Briones)
|
can be more accurately tested (Ryan Briones)
|
||||||
* Helpful error message for missing option in select box. [#40] (Ben Mabey)
|
* Helpful error message for missing option in select box. [#40] (Ben Mabey)
|
||||||
|
* Extracted save_and_open page to make it usable in Selenium mode (Luke Melia)
|
||||||
|
* Added save_and_open_screengrab for Selenium mode (Luke Melia)
|
||||||
|
|
||||||
* Bug fixes
|
* Bug fixes
|
||||||
|
|
||||||
|
@ -66,6 +75,13 @@
|
||||||
* Extend Rails' ActionController::IntegrationTest instead of
|
* Extend Rails' ActionController::IntegrationTest instead of
|
||||||
ActionController::Integration::Session (Fixes using Webrat's #select method and
|
ActionController::Integration::Session (Fixes using Webrat's #select method and
|
||||||
avoids usage of method_missing)
|
avoids usage of method_missing)
|
||||||
|
* Ensure that Webrat::MechanizeSession.request_page always uses an absolute
|
||||||
|
URL. (Graham Ashton)
|
||||||
|
* Strip anchor tags from URIs before passing to Rails integration session
|
||||||
|
(Noah Davis)
|
||||||
|
* Treat text and regexp when matching Selenium buttons (Ross Kaffenberger)
|
||||||
|
* Allow SeleniumSession's click_button to be called without an argument without
|
||||||
|
blowing up (Luke Melia)
|
||||||
|
|
||||||
== 0.3.2 / 2008-11-08
|
== 0.3.2 / 2008-11-08
|
||||||
|
|
||||||
|
|
|
@ -59,11 +59,12 @@ To install the latest code as a plugin: (_Note:_ This may be less stable than us
|
||||||
|
|
||||||
script/plugin install git://github.com/brynary/webrat.git
|
script/plugin install git://github.com/brynary/webrat.git
|
||||||
|
|
||||||
In your test_helper.rb, spec_helper.rb, or env.rb (for Cucumber) add:
|
In your test_helper.rb or env.rb (for Cucumber) add:
|
||||||
|
|
||||||
require "webrat"
|
require "webrat"
|
||||||
|
|
||||||
Webrat.configure do |config|
|
Webrat.configure do |config|
|
||||||
config.mode = Webrat::Configuration::RAILS_MODE
|
config.mode = :rails
|
||||||
end
|
end
|
||||||
|
|
||||||
== Install with Merb
|
== Install with Merb
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Webrat
|
||||||
class WebratError < StandardError
|
class WebratError < StandardError
|
||||||
end
|
end
|
||||||
|
|
||||||
VERSION = '0.3.2.1'
|
VERSION = '0.3.2.2'
|
||||||
|
|
||||||
def self.require_xml
|
def self.require_xml
|
||||||
gem "nokogiri", ">= 1.0.6"
|
gem "nokogiri", ">= 1.0.6"
|
||||||
|
|
|
@ -11,3 +11,4 @@ require "webrat/core/elements/select_option"
|
||||||
require "webrat/core/session"
|
require "webrat/core/session"
|
||||||
require "webrat/core/methods"
|
require "webrat/core/methods"
|
||||||
require "webrat/core/matchers"
|
require "webrat/core/matchers"
|
||||||
|
require "webrat/core/save_and_open_page"
|
||||||
|
|
|
@ -24,6 +24,10 @@ module Webrat
|
||||||
Webrat::XML.xpath_to(@element)
|
Webrat::XML.xpath_to(@element)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def inspect
|
||||||
|
"#<#{self.class} @element=#{element.inspect}>"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -0,0 +1,50 @@
|
||||||
|
module Webrat
|
||||||
|
module SaveAndOpenPage
|
||||||
|
# Saves the page out to RAILS_ROOT/tmp/ and opens it in the default
|
||||||
|
# web browser if on OS X. Useful for debugging.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# save_and_open_page
|
||||||
|
def save_and_open_page
|
||||||
|
return unless File.exist?(saved_page_dir)
|
||||||
|
|
||||||
|
filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.html"
|
||||||
|
|
||||||
|
File.open(filename, "w") do |f|
|
||||||
|
f.write rewrite_css_and_image_references(response_body)
|
||||||
|
end
|
||||||
|
|
||||||
|
open_in_browser(filename)
|
||||||
|
end
|
||||||
|
|
||||||
|
def open_in_browser(path) # :nodoc
|
||||||
|
platform = ruby_platform
|
||||||
|
if platform =~ /cygwin/ || platform =~ /win32/
|
||||||
|
`rundll32 url.dll,FileProtocolHandler #{path.gsub("/", "\\\\")}`
|
||||||
|
elsif platform =~ /darwin/
|
||||||
|
`open #{path}`
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def rewrite_css_and_image_references(response_html) # :nodoc:
|
||||||
|
return response_html unless doc_root
|
||||||
|
response_html.gsub(/"\/(stylesheets|images)/, doc_root + '/\1')
|
||||||
|
end
|
||||||
|
|
||||||
|
def saved_page_dir #:nodoc:
|
||||||
|
File.expand_path(".")
|
||||||
|
end
|
||||||
|
|
||||||
|
def doc_root #:nodoc:
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# accessor for testing
|
||||||
|
def ruby_platform
|
||||||
|
RUBY_PLATFORM
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,6 +2,7 @@ require "forwardable"
|
||||||
require "ostruct"
|
require "ostruct"
|
||||||
|
|
||||||
require "webrat/core/mime"
|
require "webrat/core/mime"
|
||||||
|
require "webrat/core/save_and_open_page"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
# A page load or form submission returned an unsuccessful response code (500-599)
|
# A page load or form submission returned an unsuccessful response code (500-599)
|
||||||
|
@ -30,6 +31,7 @@ module Webrat
|
||||||
class Session
|
class Session
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
include Logging
|
include Logging
|
||||||
|
include SaveAndOpenPage
|
||||||
|
|
||||||
attr_reader :current_url
|
attr_reader :current_url
|
||||||
attr_reader :elements
|
attr_reader :elements
|
||||||
|
@ -44,23 +46,6 @@ module Webrat
|
||||||
reset
|
reset
|
||||||
end
|
end
|
||||||
|
|
||||||
# Saves the page out to RAILS_ROOT/tmp/ and opens it in the default
|
|
||||||
# web browser if on OS X. Useful for debugging.
|
|
||||||
#
|
|
||||||
# Example:
|
|
||||||
# save_and_open_page
|
|
||||||
def save_and_open_page
|
|
||||||
return unless File.exist?(saved_page_dir)
|
|
||||||
|
|
||||||
filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.html"
|
|
||||||
|
|
||||||
File.open(filename, "w") do |f|
|
|
||||||
f.write rewrite_css_and_image_references(response_body)
|
|
||||||
end
|
|
||||||
|
|
||||||
open_in_browser(filename)
|
|
||||||
end
|
|
||||||
|
|
||||||
def current_dom #:nodoc:
|
def current_dom #:nodoc:
|
||||||
current_scope.dom
|
current_scope.dom
|
||||||
end
|
end
|
||||||
|
@ -78,10 +63,6 @@ module Webrat
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def saved_page_dir #:nodoc:
|
|
||||||
File.expand_path(".")
|
|
||||||
end
|
|
||||||
|
|
||||||
def header(key, value)
|
def header(key, value)
|
||||||
@custom_headers[key] = value
|
@custom_headers[key] = value
|
||||||
end
|
end
|
||||||
|
@ -173,20 +154,6 @@ module Webrat
|
||||||
|
|
||||||
webrat_deprecate :visits, :visit
|
webrat_deprecate :visits, :visit
|
||||||
|
|
||||||
def open_in_browser(path) # :nodoc
|
|
||||||
platform = ruby_platform
|
|
||||||
if platform =~ /cygwin/ || platform =~ /win32/
|
|
||||||
`rundll32 url.dll,FileProtocolHandler #{path.gsub("/", "\\\\")}`
|
|
||||||
elsif platform =~ /darwin/
|
|
||||||
`open #{path}`
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def rewrite_css_and_image_references(response_html) # :nodoc:
|
|
||||||
return response_html unless doc_root
|
|
||||||
response_html.gsub(/"\/(stylesheets|images)/, doc_root + '/\1')
|
|
||||||
end
|
|
||||||
|
|
||||||
# Subclasses can override this to show error messages without html
|
# Subclasses can override this to show error messages without html
|
||||||
def formatted_error #:nodoc:
|
def formatted_error #:nodoc:
|
||||||
response_body
|
response_body
|
||||||
|
@ -247,9 +214,5 @@ module Webrat
|
||||||
@_page_scope = nil
|
@_page_scope = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# accessor for testing
|
|
||||||
def ruby_platform
|
|
||||||
RUBY_PLATFORM
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,10 @@ module Webrat #:nodoc:
|
||||||
attr_accessor :response
|
attr_accessor :response
|
||||||
alias :page :response
|
alias :page :response
|
||||||
|
|
||||||
|
def request_page(url, http_method, data) #:nodoc:
|
||||||
|
super(absolute_url(url), http_method, data)
|
||||||
|
end
|
||||||
|
|
||||||
def get(url, data, headers_argument_not_used = nil)
|
def get(url, data, headers_argument_not_used = nil)
|
||||||
@response = mechanize.get(url, data)
|
@response = mechanize.get(url, data)
|
||||||
end
|
end
|
||||||
|
@ -37,5 +41,34 @@ module Webrat #:nodoc:
|
||||||
|
|
||||||
def_delegators :mechanize, :basic_auth
|
def_delegators :mechanize, :basic_auth
|
||||||
|
|
||||||
|
def absolute_url(url) #:nodoc:
|
||||||
|
current_host, current_path = split_current_url
|
||||||
|
if url =~ Regexp.new('^https?://')
|
||||||
|
url
|
||||||
|
elsif url =~ Regexp.new('^/')
|
||||||
|
current_host + url
|
||||||
|
elsif url =~ Regexp.new('^\.')
|
||||||
|
current_host + absolute_path(current_path, url)
|
||||||
|
else
|
||||||
|
url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def split_current_url
|
||||||
|
current_url =~ Regexp.new('^(https?://[^/]+)(/.*)?')
|
||||||
|
[Regexp.last_match(1), Regexp.last_match(2)]
|
||||||
|
end
|
||||||
|
|
||||||
|
def absolute_path(current_path, url)
|
||||||
|
levels_up = url.split('/').find_all { |x| x == '..' }.size
|
||||||
|
ancestor = if current_path.nil?
|
||||||
|
""
|
||||||
|
else
|
||||||
|
current_path.split("/")[0..(-1 - levels_up)].join("/")
|
||||||
|
end
|
||||||
|
descendent = url.split("/")[levels_up..-1]
|
||||||
|
"#{ancestor}/#{descendent}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
require "webrat"
|
require "webrat"
|
||||||
|
|
||||||
|
require "action_controller"
|
||||||
require "action_controller/integration"
|
require "action_controller/integration"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
|
@ -48,15 +50,18 @@ module Webrat
|
||||||
|
|
||||||
def do_request(http_method, url, data, headers) #:nodoc:
|
def do_request(http_method, url, data, headers) #:nodoc:
|
||||||
update_protocol(url)
|
update_protocol(url)
|
||||||
integration_session.request_via_redirect(http_method, remove_protocol(url), data, headers)
|
url = normalize_url(url)
|
||||||
|
integration_session.request_via_redirect(http_method, url, data, headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_protocol(href) #:nodoc:
|
# remove protocol, host and anchor
|
||||||
if href =~ %r{^https?://www.example.com(/.*)}
|
def normalize_url(href) #:nodoc:
|
||||||
$LAST_MATCH_INFO.captures.first
|
uri = URI.parse(href)
|
||||||
else
|
normalized_url = uri.path
|
||||||
href
|
if uri.query
|
||||||
|
normalized_url += "?" + uri.query
|
||||||
end
|
end
|
||||||
|
normalized_url
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_protocol(href) #:nodoc:
|
def update_protocol(href) #:nodoc:
|
||||||
|
|
|
@ -38,14 +38,10 @@ module Webrat
|
||||||
# To use Webrat's Selenium support, you'll need the selenium-client gem installed.
|
# To use Webrat's Selenium support, you'll need the selenium-client gem installed.
|
||||||
# Activate it with (for example, in your <tt>env.rb</tt>):
|
# Activate it with (for example, in your <tt>env.rb</tt>):
|
||||||
#
|
#
|
||||||
# require "webrat/selenium"
|
# require "webrat"
|
||||||
#
|
#
|
||||||
# Then, if you're using Cucumber, configure it to use a
|
# Webrat.configure do |config|
|
||||||
# <tt>Webrat::Selenium::Rails::World</tt> as the scenario context by adding
|
# config.mode = :selenium
|
||||||
# the following to <tt>env.rb</tt>:
|
|
||||||
#
|
|
||||||
# World do
|
|
||||||
# Webrat::Selenium::Rails::World.new
|
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# == Dropping down to the selenium-client API
|
# == Dropping down to the selenium-client API
|
||||||
|
@ -72,31 +68,26 @@ module Webrat
|
||||||
# your Webrat::Selenium tests ignoring the concurrency issues that can plague in-browser
|
# your Webrat::Selenium tests ignoring the concurrency issues that can plague in-browser
|
||||||
# testing, so long as you're using the Webrat API.
|
# testing, so long as you're using the Webrat API.
|
||||||
module Selenium
|
module Selenium
|
||||||
|
module Methods
|
||||||
|
def response
|
||||||
|
webrat_session.response
|
||||||
|
end
|
||||||
|
|
||||||
module Rails #:nodoc:
|
def wait_for(*args, &block)
|
||||||
class World < ::ActionController::IntegrationTest
|
webrat_session.wait_for(*args, &block)
|
||||||
include Webrat::Selenium::Matchers
|
end
|
||||||
|
|
||||||
def initialize #:nodoc:
|
|
||||||
@_result = Test::Unit::TestResult.new
|
|
||||||
end
|
|
||||||
|
|
||||||
def response
|
|
||||||
webrat_session.response
|
|
||||||
end
|
|
||||||
|
|
||||||
def wait_for(*args, &block)
|
|
||||||
webrat_session.wait_for(*args, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
def save_and_open_screengrab
|
||||||
|
webrat_session.save_and_open_screengrab
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module ActionController #:nodoc:
|
module ActionController #:nodoc:
|
||||||
IntegrationTest.class_eval do
|
IntegrationTest.class_eval do
|
||||||
include Webrat::Methods
|
include Webrat::Methods
|
||||||
|
include Webrat::Selenium::Methods
|
||||||
|
include Webrat::Selenium::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require "webrat/core/save_and_open_page"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
class TimeoutError < WebratError
|
class TimeoutError < WebratError
|
||||||
end
|
end
|
||||||
|
@ -17,6 +19,7 @@ module Webrat
|
||||||
end
|
end
|
||||||
|
|
||||||
class SeleniumSession
|
class SeleniumSession
|
||||||
|
include Webrat::SaveAndOpenPage
|
||||||
|
|
||||||
def initialize(*args) # :nodoc:
|
def initialize(*args) # :nodoc:
|
||||||
end
|
end
|
||||||
|
@ -53,7 +56,7 @@ module Webrat
|
||||||
def click_button(button_text_or_regexp = nil, options = {})
|
def click_button(button_text_or_regexp = nil, options = {})
|
||||||
if button_text_or_regexp.is_a?(Hash) && options == {}
|
if button_text_or_regexp.is_a?(Hash) && options == {}
|
||||||
pattern, options = nil, button_text_or_regexp
|
pattern, options = nil, button_text_or_regexp
|
||||||
else
|
elsif button_text_or_regexp
|
||||||
pattern = adjust_if_regexp(button_text_or_regexp)
|
pattern = adjust_if_regexp(button_text_or_regexp)
|
||||||
end
|
end
|
||||||
pattern ||= '*'
|
pattern ||= '*'
|
||||||
|
@ -160,6 +163,20 @@ module Webrat
|
||||||
|
|
||||||
webrat_deprecate :browser, :selenium
|
webrat_deprecate :browser, :selenium
|
||||||
|
|
||||||
|
|
||||||
|
def save_and_open_screengrab
|
||||||
|
return unless File.exist?(saved_page_dir)
|
||||||
|
|
||||||
|
filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.png"
|
||||||
|
|
||||||
|
if $browser.chrome_backend?
|
||||||
|
$browser.capture_entire_page_screenshot(filename, '')
|
||||||
|
else
|
||||||
|
$browser.capture_screenshot(filename)
|
||||||
|
end
|
||||||
|
open_in_browser(filename)
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def setup #:nodoc:
|
def setup #:nodoc:
|
||||||
|
@ -175,6 +192,7 @@ module Webrat
|
||||||
|
|
||||||
extend_selenium
|
extend_selenium
|
||||||
define_location_strategies
|
define_location_strategies
|
||||||
|
$browser.window_maximize
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown_at_exit #:nodoc:
|
def teardown_at_exit #:nodoc:
|
||||||
|
@ -191,7 +209,7 @@ module Webrat
|
||||||
if text_or_regexp.is_a?(Regexp)
|
if text_or_regexp.is_a?(Regexp)
|
||||||
"evalregex:#{text_or_regexp.inspect}"
|
"evalregex:#{text_or_regexp.inspect}"
|
||||||
else
|
else
|
||||||
text_or_regexp
|
"evalregex:/#{text_or_regexp}/"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -330,7 +330,7 @@ describe "click_button" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should properly handle HTML entities in textarea default values" do
|
it "should properly handle HTML entities in textarea default values" do
|
||||||
pending "needs bug fix" do
|
spec = lambda do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
<form method="post" action="/posts">
|
<form method="post" action="/posts">
|
||||||
|
@ -342,6 +342,12 @@ describe "click_button" do
|
||||||
webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Peanut butter & jelly"})
|
webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Peanut butter & jelly"})
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Webrat.on_java?
|
||||||
|
spec.call
|
||||||
|
else
|
||||||
|
pending("needs bug fix", &spec)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should send default selected option value from select" do
|
it "should send default selected option value from select" do
|
||||||
|
|
|
@ -201,7 +201,7 @@ describe "select" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should properly handle submitting HTML entities in select values" do
|
it "should properly handle submitting HTML entities in select values" do
|
||||||
pending "needs bug fix" do
|
spec = lambda do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
<form method="post" action="/login">
|
<form method="post" action="/login">
|
||||||
|
@ -213,10 +213,16 @@ describe "select" do
|
||||||
webrat_session.should_receive(:post).with("/login", "month" => "Peanut butter & jelly")
|
webrat_session.should_receive(:post).with("/login", "month" => "Peanut butter & jelly")
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Webrat.on_java?
|
||||||
|
spec.call
|
||||||
|
else
|
||||||
|
pending("needs bug fix", &spec)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should properly handle locating with HTML entities in select values" do
|
it "should properly handle locating with HTML entities in select values" do
|
||||||
pending "needs bug fix" do
|
spec = lambda do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
<form method="post" action="/login">
|
<form method="post" action="/login">
|
||||||
|
@ -230,5 +236,11 @@ describe "select" do
|
||||||
select "Peanut butter & jelly"
|
select "Peanut butter & jelly"
|
||||||
}.should_not raise_error(Webrat::NotFoundError)
|
}.should_not raise_error(Webrat::NotFoundError)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Webrat.on_java?
|
||||||
|
spec.call
|
||||||
|
else
|
||||||
|
pending("needs bug fix", &spec)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -58,6 +58,28 @@ describe "within" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should work when the scope is inside the form" do
|
||||||
|
pending "needs bug fix" do
|
||||||
|
with_html <<-HTML
|
||||||
|
<html>
|
||||||
|
<form id="form2" action="/form2">
|
||||||
|
<div class="important">
|
||||||
|
<label>Email: <input type="text" class="email2" name="email" /></label>
|
||||||
|
</div>
|
||||||
|
<input type="submit" value="Add" />
|
||||||
|
</form>
|
||||||
|
</html>
|
||||||
|
HTML
|
||||||
|
|
||||||
|
webrat_session.should_receive(:get).with("/form2", "email" => "test@example.com")
|
||||||
|
within ".important" do
|
||||||
|
fill_in "Email", :with => "test@example.com"
|
||||||
|
end
|
||||||
|
|
||||||
|
submit_form "form2"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "should not find buttons outside of the scope" do
|
it "should not find buttons outside of the scope" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
|
|
|
@ -7,12 +7,21 @@ begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end
|
||||||
webrat_path = File.expand_path(File.dirname(__FILE__) + "/../lib/")
|
webrat_path = File.expand_path(File.dirname(__FILE__) + "/../lib/")
|
||||||
$LOAD_PATH.unshift(webrat_path) unless $LOAD_PATH.include?(webrat_path)
|
$LOAD_PATH.unshift(webrat_path) unless $LOAD_PATH.include?(webrat_path)
|
||||||
|
|
||||||
require "merb-core"
|
|
||||||
require "webrat/merb"
|
|
||||||
|
|
||||||
require "webrat"
|
require "webrat"
|
||||||
require File.expand_path(File.dirname(__FILE__) + "/fakes/test_session")
|
require File.expand_path(File.dirname(__FILE__) + "/fakes/test_session")
|
||||||
|
|
||||||
|
module Webrat
|
||||||
|
@@previous_config = nil
|
||||||
|
|
||||||
|
def self.cache_config_for_test
|
||||||
|
@@previous_config = Webrat.configuration.clone
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.reset_for_test
|
||||||
|
@@configuration = @@previous_config if @@previous_config
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Spec::Runner.configure do |config|
|
Spec::Runner.configure do |config|
|
||||||
include Webrat::Methods
|
include Webrat::Methods
|
||||||
|
|
||||||
|
@ -26,22 +35,15 @@ Spec::Runner.configure do |config|
|
||||||
webrat_session.response_body = xml
|
webrat_session.response_body = xml
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
config.before :each do
|
||||||
|
Webrat.cache_config_for_test
|
||||||
module Webrat
|
|
||||||
@@previous_config = nil
|
|
||||||
|
|
||||||
def self.cache_config_for_test
|
|
||||||
@@previous_config = Webrat.configuration.clone
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.reset_for_test
|
config.after :each do
|
||||||
@@configuration = @@previous_config if @@previous_config
|
Webrat.reset_for_test
|
||||||
end
|
|
||||||
|
|
||||||
class Configuration
|
|
||||||
def mode_for_test= (mode)
|
|
||||||
@mode = mode
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Webrat.configure do |config|
|
||||||
|
config.mode = :merb
|
||||||
|
end
|
|
@ -4,14 +4,6 @@ describe Webrat::Configuration do
|
||||||
predicate_matchers[:parse_with_nokogiri] = :parse_with_nokogiri?
|
predicate_matchers[:parse_with_nokogiri] = :parse_with_nokogiri?
|
||||||
predicate_matchers[:open_error_files] = :open_error_files?
|
predicate_matchers[:open_error_files] = :open_error_files?
|
||||||
|
|
||||||
before do
|
|
||||||
Webrat.cache_config_for_test
|
|
||||||
end
|
|
||||||
|
|
||||||
after do
|
|
||||||
Webrat.reset_for_test
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should have a mode" do
|
it "should have a mode" do
|
||||||
Webrat.configuration.should respond_to(:mode)
|
Webrat.configuration.should respond_to(:mode)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,20 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
|
describe Field do
|
||||||
|
it "should have nice inspect output" do
|
||||||
|
html = <<-HTML
|
||||||
|
<html>
|
||||||
|
<input type='checkbox' checked='checked' />
|
||||||
|
</html>
|
||||||
|
HTML
|
||||||
|
|
||||||
|
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
|
||||||
|
checkbox = CheckboxField.new(nil, element)
|
||||||
|
checkbox.inspect.should =~ /#<Webrat::CheckboxField @element=<input type=['"]checkbox['"] checked(=['"]checked['"])?\/?>>/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe CheckboxField do
|
describe CheckboxField do
|
||||||
it "should say it is checked if it is" do
|
it "should say it is checked if it is" do
|
||||||
html = <<-HTML
|
html = <<-HTML
|
||||||
|
|
|
@ -87,12 +87,8 @@ describe Webrat::Session do
|
||||||
|
|
||||||
describe "#request_page" do
|
describe "#request_page" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
Webrat.cache_config_for_test
|
|
||||||
webrat_session = Webrat::Session.new
|
webrat_session = Webrat::Session.new
|
||||||
end
|
end
|
||||||
after(:each) do
|
|
||||||
Webrat.reset_for_test
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should raise an error if the request is not a success" do
|
it "should raise an error if the request is not a success" do
|
||||||
webrat_session.stub!(:get)
|
webrat_session.stub!(:get)
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||||
require "mechanize"
|
|
||||||
require "webrat/mechanize"
|
require "webrat/mechanize"
|
||||||
|
|
||||||
describe Webrat::MechanizeSession do
|
describe Webrat::MechanizeSession do
|
||||||
|
|
||||||
|
before :each do
|
||||||
|
Webrat.configuration.mode = :mechanize
|
||||||
|
end
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@mech = Webrat::MechanizeSession.new
|
@mech = Webrat::MechanizeSession.new
|
||||||
end
|
end
|
||||||
|
@ -34,4 +38,45 @@ describe Webrat::MechanizeSession do
|
||||||
Webrat::MechanizeSession.new.post(url, data)
|
Webrat::MechanizeSession.new.post(url, data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#absolute_url" do
|
||||||
|
before(:each) do
|
||||||
|
@session = Webrat::MechanizeSession.new
|
||||||
|
@session.stub!(:current_url).and_return(absolute_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
def absolute_url
|
||||||
|
'http://test.host/users/fred/cabbages'
|
||||||
|
end
|
||||||
|
|
||||||
|
def rooted_url
|
||||||
|
'/users/fred/cabbages'
|
||||||
|
end
|
||||||
|
|
||||||
|
def relative_url
|
||||||
|
'../../wilma'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return unmodified url if prefixed with scheme" do
|
||||||
|
@session.absolute_url(absolute_url).should == absolute_url
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should prefix scheme and hostname if url begins with /" do
|
||||||
|
@session.absolute_url(rooted_url).should == absolute_url
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should resolve sibling URLs relative to current path" do
|
||||||
|
@session.absolute_url(relative_url).should == 'http://test.host/users/wilma'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should cope with sibling URLs from root of site" do
|
||||||
|
@session.stub!(:current_url).and_return('http://test.host')
|
||||||
|
@session.absolute_url(relative_url).should == 'http://test.host/wilma'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should cope with https" do
|
||||||
|
@session.stub!(:current_url).and_return('https://test.host')
|
||||||
|
@session.absolute_url(relative_url).should == 'https://test.host/wilma'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,5 +1,4 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
||||||
require File.expand_path(File.dirname(__FILE__) + "/helper")
|
|
||||||
|
|
||||||
describe HashWithIndifferentAccess do
|
describe HashWithIndifferentAccess do
|
||||||
it "should not update constructor when not a hash" do
|
it "should not update constructor when not a hash" do
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
||||||
|
|
||||||
|
require "webrat/merb"
|
||||||
|
|
||||||
|
describe Webrat::MerbSession do
|
||||||
|
it "should not pass empty params if data is and empty hash" do
|
||||||
|
session = Webrat::MerbSession.new
|
||||||
|
response = OpenStruct.new
|
||||||
|
response.status = 200
|
||||||
|
session.should_receive(:request).with('url', {:params=> nil, :method=>"GET", :headers=>nil}).and_return(response)
|
||||||
|
session.get('url', {}, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
%w{post put delete}.each do |request_method|
|
||||||
|
it "should call do request with method #{request_method.upcase} for a #{request_method} call" do
|
||||||
|
session = Webrat::MerbSession.new
|
||||||
|
response = OpenStruct.new
|
||||||
|
response.status = 200
|
||||||
|
|
||||||
|
session.should_receive(:request).with('url', {:params=>nil, :method=>request_method.upcase, :headers=>nil}).and_return(response)
|
||||||
|
session.send(request_method, 'url', {}, nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "a session with a response" do
|
||||||
|
setup do
|
||||||
|
@session = Webrat::MerbSession.new
|
||||||
|
@response = OpenStruct.new
|
||||||
|
@response.status = 200
|
||||||
|
@response.body = 'test response'
|
||||||
|
@session.instance_variable_set(:@response, @response)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return body of a request as a response_body" do
|
||||||
|
@session.response_body.should == @response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return status of a request as a response_code" do
|
||||||
|
@session.response_code.should == @response.status
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,7 +1,8 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||||
|
|
||||||
describe "attach_file" do
|
describe "attach_file" do
|
||||||
before do
|
before do
|
||||||
|
Webrat.configuration.mode = :rails
|
||||||
@filename = __FILE__
|
@filename = __FILE__
|
||||||
@uploaded_file = mock("uploaded file")
|
@uploaded_file = mock("uploaded file")
|
||||||
ActionController::TestUploadedFile.stub!(:new => @uploaded_file)
|
ActionController::TestUploadedFile.stub!(:new => @uploaded_file)
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||||
|
|
||||||
|
require "webrat/rails"
|
||||||
|
|
||||||
describe Webrat::RailsSession do
|
describe Webrat::RailsSession do
|
||||||
|
before do
|
||||||
|
Webrat.configuration.mode = :rails
|
||||||
|
end
|
||||||
|
|
||||||
it "should delegate response_body to the session response body" do
|
it "should delegate response_body to the session response body" do
|
||||||
response = mock("response", :body => "<html>")
|
response = mock("response", :body => "<html>")
|
||||||
integration_session = mock("integration session", :response => response)
|
integration_session = mock("integration session", :response => response)
|
||||||
|
@ -69,6 +75,15 @@ describe Webrat::RailsSession do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "the URL include an anchor" do
|
||||||
|
it "should strip out the anchor" do
|
||||||
|
integration_session = mock("integration session", :https! => false)
|
||||||
|
rails_session = Webrat::RailsSession.new(integration_session)
|
||||||
|
integration_session.should_receive(:request_via_redirect).with(:get, "/url", "data", "headers")
|
||||||
|
rails_session.get("http://www.example.com/url#foo", "data", "headers")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "should provide a saved_page_dir" do
|
it "should provide a saved_page_dir" do
|
||||||
Webrat::RailsSession.new(mock("integration session")).should respond_to(:saved_page_dir)
|
Webrat::RailsSession.new(mock("integration session")).should respond_to(:saved_page_dir)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = %q{webrat}
|
s.name = %q{webrat}
|
||||||
s.version = "0.3.2.1"
|
s.version = "0.3.2.2"
|
||||||
|
|
||||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||||
s.authors = ["Bryan Helmkamp"]
|
s.authors = ["Bryan Helmkamp"]
|
||||||
s.date = %q{2008-11-30}
|
s.date = %q{2008-12-25}
|
||||||
s.description = %q{Webrat. Ruby Acceptance Testing for Web applications}
|
s.description = %q{Webrat. Ruby Acceptance Testing for Web applications}
|
||||||
s.email = %q{bryan@brynary.com}
|
s.email = %q{bryan@brynary.com}
|
||||||
s.extra_rdoc_files = ["README.rdoc", "MIT-LICENSE.txt"]
|
s.extra_rdoc_files = ["README.rdoc", "MIT-LICENSE.txt"]
|
||||||
s.files = ["History.txt", "install.rb", "MIT-LICENSE.txt", "README.rdoc", "Rakefile", "lib/webrat", "lib/webrat/core", "lib/webrat/core/configuration.rb", "lib/webrat/core/elements", "lib/webrat/core/elements/area.rb", "lib/webrat/core/elements/element.rb", "lib/webrat/core/elements/field.rb", "lib/webrat/core/elements/form.rb", "lib/webrat/core/elements/label.rb", "lib/webrat/core/elements/link.rb", "lib/webrat/core/elements/select_option.rb", "lib/webrat/core/locators", "lib/webrat/core/locators/area_locator.rb", "lib/webrat/core/locators/button_locator.rb", "lib/webrat/core/locators/field_by_id_locator.rb", "lib/webrat/core/locators/field_labeled_locator.rb", "lib/webrat/core/locators/field_locator.rb", "lib/webrat/core/locators/field_named_locator.rb", "lib/webrat/core/locators/form_locator.rb", "lib/webrat/core/locators/label_locator.rb", "lib/webrat/core/locators/link_locator.rb", "lib/webrat/core/locators/locator.rb", "lib/webrat/core/locators/select_option_locator.rb", "lib/webrat/core/locators.rb", "lib/webrat/core/logging.rb", "lib/webrat/core/matchers", "lib/webrat/core/matchers/have_content.rb", "lib/webrat/core/matchers/have_selector.rb", "lib/webrat/core/matchers/have_tag.rb", "lib/webrat/core/matchers/have_xpath.rb", "lib/webrat/core/matchers.rb", "lib/webrat/core/methods.rb", "lib/webrat/core/mime.rb", "lib/webrat/core/scope.rb", "lib/webrat/core/session.rb", "lib/webrat/core/xml", "lib/webrat/core/xml/hpricot.rb", "lib/webrat/core/xml/nokogiri.rb", "lib/webrat/core/xml/rexml.rb", "lib/webrat/core/xml.rb", "lib/webrat/core.rb", "lib/webrat/core_extensions", "lib/webrat/core_extensions/blank.rb", "lib/webrat/core_extensions/deprecate.rb", "lib/webrat/core_extensions/detect_mapped.rb", "lib/webrat/core_extensions/hash_with_indifferent_access.rb", "lib/webrat/core_extensions/meta_class.rb", "lib/webrat/core_extensions/nil_to_param.rb", "lib/webrat/mechanize.rb", "lib/webrat/merb.rb", "lib/webrat/rack.rb", "lib/webrat/rails", "lib/webrat/rails/redirect_actions.rb", "lib/webrat/rails.rb", "lib/webrat/rspec-rails.rb", "lib/webrat/selenium", "lib/webrat/selenium/location_strategy_javascript", "lib/webrat/selenium/location_strategy_javascript/button.js", "lib/webrat/selenium/location_strategy_javascript/label.js", "lib/webrat/selenium/location_strategy_javascript/webrat.js", "lib/webrat/selenium/location_strategy_javascript/webratlink.js", "lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js", "lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js", "lib/webrat/selenium/selenium_extensions.js", "lib/webrat/selenium/selenium_session.rb", "lib/webrat/selenium.rb", "lib/webrat/sinatra.rb", "lib/webrat.rb", "vendor/selenium-server.jar"]
|
s.files = ["History.txt", "install.rb", "MIT-LICENSE.txt", "README.rdoc", "Rakefile", "lib/webrat", "lib/webrat/core", "lib/webrat/core/configuration.rb", "lib/webrat/core/elements", "lib/webrat/core/elements/area.rb", "lib/webrat/core/elements/element.rb", "lib/webrat/core/elements/field.rb", "lib/webrat/core/elements/form.rb", "lib/webrat/core/elements/label.rb", "lib/webrat/core/elements/link.rb", "lib/webrat/core/elements/select_option.rb", "lib/webrat/core/locators", "lib/webrat/core/locators/area_locator.rb", "lib/webrat/core/locators/button_locator.rb", "lib/webrat/core/locators/field_by_id_locator.rb", "lib/webrat/core/locators/field_labeled_locator.rb", "lib/webrat/core/locators/field_locator.rb", "lib/webrat/core/locators/field_named_locator.rb", "lib/webrat/core/locators/form_locator.rb", "lib/webrat/core/locators/label_locator.rb", "lib/webrat/core/locators/link_locator.rb", "lib/webrat/core/locators/locator.rb", "lib/webrat/core/locators/select_option_locator.rb", "lib/webrat/core/locators.rb", "lib/webrat/core/logging.rb", "lib/webrat/core/matchers", "lib/webrat/core/matchers/have_content.rb", "lib/webrat/core/matchers/have_selector.rb", "lib/webrat/core/matchers/have_tag.rb", "lib/webrat/core/matchers/have_xpath.rb", "lib/webrat/core/matchers.rb", "lib/webrat/core/methods.rb", "lib/webrat/core/mime.rb", "lib/webrat/core/save_and_open_page.rb", "lib/webrat/core/scope.rb", "lib/webrat/core/session.rb", "lib/webrat/core/xml", "lib/webrat/core/xml/hpricot.rb", "lib/webrat/core/xml/nokogiri.rb", "lib/webrat/core/xml/rexml.rb", "lib/webrat/core/xml.rb", "lib/webrat/core.rb", "lib/webrat/core_extensions", "lib/webrat/core_extensions/blank.rb", "lib/webrat/core_extensions/deprecate.rb", "lib/webrat/core_extensions/detect_mapped.rb", "lib/webrat/core_extensions/hash_with_indifferent_access.rb", "lib/webrat/core_extensions/meta_class.rb", "lib/webrat/core_extensions/nil_to_param.rb", "lib/webrat/mechanize.rb", "lib/webrat/merb.rb", "lib/webrat/rack.rb", "lib/webrat/rails", "lib/webrat/rails/redirect_actions.rb", "lib/webrat/rails.rb", "lib/webrat/rspec-rails.rb", "lib/webrat/selenium", "lib/webrat/selenium/location_strategy_javascript", "lib/webrat/selenium/location_strategy_javascript/button.js", "lib/webrat/selenium/location_strategy_javascript/label.js", "lib/webrat/selenium/location_strategy_javascript/webrat.js", "lib/webrat/selenium/location_strategy_javascript/webratlink.js", "lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js", "lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js", "lib/webrat/selenium/matchers.rb", "lib/webrat/selenium/selenium_extensions.js", "lib/webrat/selenium/selenium_session.rb", "lib/webrat/selenium.rb", "lib/webrat/sinatra.rb", "lib/webrat.rb", "vendor/selenium-server.jar"]
|
||||||
s.has_rdoc = true
|
s.has_rdoc = true
|
||||||
s.homepage = %q{http://github.com/brynary/webrat}
|
s.homepage = %q{http://github.com/brynary/webrat}
|
||||||
s.require_paths = ["lib"]
|
s.require_paths = ["lib"]
|
||||||
|
|
Loading…
Reference in New Issue