Whitespace
This commit is contained in:
parent
f3f81dabdc
commit
03914fd293
@ -11,7 +11,7 @@ module Webrat
|
|||||||
|
|
||||||
def self.require_xml
|
def self.require_xml
|
||||||
gem "nokogiri", ">= 1.0.6"
|
gem "nokogiri", ">= 1.0.6"
|
||||||
|
|
||||||
if on_java?
|
if on_java?
|
||||||
# We need Nokogiri's CSS to XPath support, even if using REXML and Hpricot for parsing and searching
|
# We need Nokogiri's CSS to XPath support, even if using REXML and Hpricot for parsing and searching
|
||||||
require "nokogiri/css"
|
require "nokogiri/css"
|
||||||
@ -22,11 +22,11 @@ module Webrat
|
|||||||
require "webrat/core/xml/nokogiri"
|
require "webrat/core/xml/nokogiri"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.on_java?
|
def self.on_java?
|
||||||
RUBY_PLATFORM =~ /java/
|
RUBY_PLATFORM =~ /java/
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Webrat.require_xml
|
Webrat.require_xml
|
||||||
|
@ -57,7 +57,7 @@ module Webrat
|
|||||||
# How many redirects to the same URL should be halted as an infinite redirect
|
# How many redirects to the same URL should be halted as an infinite redirect
|
||||||
# loop? Defaults to 10
|
# loop? Defaults to 10
|
||||||
attr_accessor :infinite_redirect_limit
|
attr_accessor :infinite_redirect_limit
|
||||||
|
|
||||||
def initialize # :nodoc:
|
def initialize # :nodoc:
|
||||||
self.open_error_files = true
|
self.open_error_files = true
|
||||||
self.parse_with_nokogiri = !Webrat.on_java?
|
self.parse_with_nokogiri = !Webrat.on_java?
|
||||||
@ -82,7 +82,7 @@ module Webrat
|
|||||||
# :rails, :selenium, :rack, :sinatra, :mechanize, :merb
|
# :rails, :selenium, :rack, :sinatra, :mechanize, :merb
|
||||||
def mode=(mode)
|
def mode=(mode)
|
||||||
@mode = mode.to_sym
|
@mode = mode.to_sym
|
||||||
|
|
||||||
# This is a temporary hack to support backwards compatibility
|
# This is a temporary hack to support backwards compatibility
|
||||||
# with Merb 1.0.8 until it's updated to use the new Webrat.configure
|
# with Merb 1.0.8 until it's updated to use the new Webrat.configure
|
||||||
# syntax
|
# syntax
|
||||||
|
@ -2,21 +2,21 @@ require "webrat/core/elements/element"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
class Area < Element #:nodoc:
|
class Area < Element #:nodoc:
|
||||||
|
|
||||||
def self.xpath_search
|
def self.xpath_search
|
||||||
".//area"
|
".//area"
|
||||||
end
|
end
|
||||||
|
|
||||||
def click(method = nil, options = {})
|
def click(method = nil, options = {})
|
||||||
@session.request_page(absolute_href, :get, {})
|
@session.request_page(absolute_href, :get, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def href
|
def href
|
||||||
Webrat::XML.attribute(@element, "href")
|
Webrat::XML.attribute(@element, "href")
|
||||||
end
|
end
|
||||||
|
|
||||||
def absolute_href
|
def absolute_href
|
||||||
if href =~ /^\?/
|
if href =~ /^\?/
|
||||||
"#{@session.current_url}#{href}"
|
"#{@session.current_url}#{href}"
|
||||||
@ -26,6 +26,6 @@ module Webrat
|
|||||||
href
|
href
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,33 +1,33 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
|
|
||||||
class Element # :nodoc:
|
class Element # :nodoc:
|
||||||
|
|
||||||
def self.load_all(session, dom)
|
def self.load_all(session, dom)
|
||||||
Webrat::XML.xpath_search(dom, xpath_search).map do |element|
|
Webrat::XML.xpath_search(dom, xpath_search).map do |element|
|
||||||
load(session, element)
|
load(session, element)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.load(session, element)
|
def self.load(session, element)
|
||||||
return nil if element.nil?
|
return nil if element.nil?
|
||||||
session.elements[Webrat::XML.xpath_to(element)] ||= self.new(session, element)
|
session.elements[Webrat::XML.xpath_to(element)] ||= self.new(session, element)
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :element
|
attr_reader :element
|
||||||
|
|
||||||
def initialize(session, element)
|
def initialize(session, element)
|
||||||
@session = session
|
@session = session
|
||||||
@element = element
|
@element = element
|
||||||
end
|
end
|
||||||
|
|
||||||
def path
|
def path
|
||||||
Webrat::XML.xpath_to(@element)
|
Webrat::XML.xpath_to(@element)
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
"#<#{self.class} @element=#{element.inspect}>"
|
"#<#{self.class} @element=#{element.inspect}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -8,10 +8,10 @@ module Webrat
|
|||||||
# Raised when Webrat is asked to manipulate a disabled form field
|
# Raised when Webrat is asked to manipulate a disabled form field
|
||||||
class DisabledFieldError < WebratError
|
class DisabledFieldError < WebratError
|
||||||
end
|
end
|
||||||
|
|
||||||
class Field < Element #:nodoc:
|
class Field < Element #:nodoc:
|
||||||
attr_reader :value
|
attr_reader :value
|
||||||
|
|
||||||
def self.xpath_search
|
def self.xpath_search
|
||||||
[".//button", ".//input", ".//textarea", ".//select"]
|
[".//button", ".//input", ".//textarea", ".//select"]
|
||||||
end
|
end
|
||||||
@ -19,22 +19,22 @@ module Webrat
|
|||||||
def self.xpath_search_excluding_hidden
|
def self.xpath_search_excluding_hidden
|
||||||
[".//button", ".//input[ @type != 'hidden']", ".//textarea", ".//select"]
|
[".//button", ".//input[ @type != 'hidden']", ".//textarea", ".//select"]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.field_classes
|
def self.field_classes
|
||||||
@field_classes || []
|
@field_classes || []
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.inherited(klass)
|
def self.inherited(klass)
|
||||||
@field_classes ||= []
|
@field_classes ||= []
|
||||||
@field_classes << klass
|
@field_classes << klass
|
||||||
# raise args.inspect
|
# raise args.inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.load(session, element)
|
def self.load(session, element)
|
||||||
return nil if element.nil?
|
return nil if element.nil?
|
||||||
session.elements[Webrat::XML.xpath_to(element)] ||= field_class(element).new(session, element)
|
session.elements[Webrat::XML.xpath_to(element)] ||= field_class(element).new(session, element)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.field_class(element)
|
def self.field_class(element)
|
||||||
case element.name
|
case element.name
|
||||||
when "button" then ButtonField
|
when "button" then ButtonField
|
||||||
@ -55,7 +55,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
super
|
super
|
||||||
@value = default_value
|
@value = default_value
|
||||||
@ -65,7 +65,7 @@ module Webrat
|
|||||||
return nil if labels.empty?
|
return nil if labels.empty?
|
||||||
labels.first.text
|
labels.first.text
|
||||||
end
|
end
|
||||||
|
|
||||||
def id
|
def id
|
||||||
Webrat::XML.attribute(@element, "id")
|
Webrat::XML.attribute(@element, "id")
|
||||||
end
|
end
|
||||||
@ -73,15 +73,15 @@ module Webrat
|
|||||||
def disabled?
|
def disabled?
|
||||||
@element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false'
|
@element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false'
|
||||||
end
|
end
|
||||||
|
|
||||||
def raise_error_if_disabled
|
def raise_error_if_disabled
|
||||||
return unless disabled?
|
return unless disabled?
|
||||||
raise DisabledFieldError.new("Cannot interact with disabled form element (#{self})")
|
raise DisabledFieldError.new("Cannot interact with disabled form element (#{self})")
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
return nil if disabled?
|
return nil if disabled?
|
||||||
|
|
||||||
case Webrat.configuration.mode
|
case Webrat.configuration.mode
|
||||||
when :rails
|
when :rails
|
||||||
parse_rails_request_params("#{name}=#{escaped_value}")
|
parse_rails_request_params("#{name}=#{escaped_value}")
|
||||||
@ -91,17 +91,17 @@ module Webrat
|
|||||||
{ name => escaped_value }
|
{ name => escaped_value }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set(value)
|
def set(value)
|
||||||
@value = value
|
@value = value
|
||||||
end
|
end
|
||||||
|
|
||||||
def unset
|
def unset
|
||||||
@value = default_value
|
@value = default_value
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def parse_rails_request_params(params)
|
def parse_rails_request_params(params)
|
||||||
if defined?(ActionController::AbstractRequest)
|
if defined?(ActionController::AbstractRequest)
|
||||||
ActionController::AbstractRequest.parse_query_parameters(params)
|
ActionController::AbstractRequest.parse_query_parameters(params)
|
||||||
@ -113,38 +113,38 @@ module Webrat
|
|||||||
Rack::Utils.parse_nested_query(params)
|
Rack::Utils.parse_nested_query(params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def form
|
def form
|
||||||
Form.load(@session, form_element)
|
Form.load(@session, form_element)
|
||||||
end
|
end
|
||||||
|
|
||||||
def form_element
|
def form_element
|
||||||
parent = @element.parent
|
parent = @element.parent
|
||||||
|
|
||||||
while parent.respond_to?(:parent)
|
while parent.respond_to?(:parent)
|
||||||
return parent if parent.name == 'form'
|
return parent if parent.name == 'form'
|
||||||
parent = parent.parent
|
parent = parent.parent
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def name
|
def name
|
||||||
Webrat::XML.attribute(@element, "name")
|
Webrat::XML.attribute(@element, "name")
|
||||||
end
|
end
|
||||||
|
|
||||||
def escaped_value
|
def escaped_value
|
||||||
CGI.escape(@value.to_s)
|
CGI.escape(@value.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def labels
|
def labels
|
||||||
@labels ||= label_elements.map do |element|
|
@labels ||= label_elements.map do |element|
|
||||||
Label.load(@session, element)
|
Label.load(@session, element)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def label_elements
|
def label_elements
|
||||||
return @label_elements unless @label_elements.nil?
|
return @label_elements unless @label_elements.nil?
|
||||||
@label_elements = []
|
@label_elements = []
|
||||||
|
|
||||||
parent = @element.parent
|
parent = @element.parent
|
||||||
while parent.respond_to?(:parent)
|
while parent.respond_to?(:parent)
|
||||||
if parent.name == 'label'
|
if parent.name == 'label'
|
||||||
@ -153,18 +153,18 @@ module Webrat
|
|||||||
end
|
end
|
||||||
parent = parent.parent
|
parent = parent.parent
|
||||||
end
|
end
|
||||||
|
|
||||||
unless id.blank?
|
unless id.blank?
|
||||||
@label_elements += Webrat::XML.xpath_search(form.element, ".//label[@for = '#{id}']")
|
@label_elements += Webrat::XML.xpath_search(form.element, ".//label[@for = '#{id}']")
|
||||||
end
|
end
|
||||||
|
|
||||||
@label_elements
|
@label_elements
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_value
|
def default_value
|
||||||
Webrat::XML.attribute(@element, "value")
|
Webrat::XML.attribute(@element, "value")
|
||||||
end
|
end
|
||||||
|
|
||||||
def replace_param_value(params, oval, nval)
|
def replace_param_value(params, oval, nval)
|
||||||
output = Hash.new
|
output = Hash.new
|
||||||
params.each do |key, value|
|
params.each do |key, value|
|
||||||
@ -181,13 +181,13 @@ module Webrat
|
|||||||
output
|
output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ButtonField < Field #:nodoc:
|
class ButtonField < Field #:nodoc:
|
||||||
|
|
||||||
def self.xpath_search
|
def self.xpath_search
|
||||||
[".//button", ".//input[@type = 'submit']", ".//input[@type = 'button']", ".//input[@type = 'image']"]
|
[".//button", ".//input[@type = 'submit']", ".//input[@type = 'button']", ".//input[@type = 'image']"]
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
return nil if @value.nil?
|
return nil if @value.nil?
|
||||||
super
|
super
|
||||||
@ -210,7 +210,7 @@ module Webrat
|
|||||||
def self.xpath_search
|
def self.xpath_search
|
||||||
".//input[@type = 'hidden']"
|
".//input[@type = 'hidden']"
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
if collection_name?
|
if collection_name?
|
||||||
super
|
super
|
||||||
@ -238,7 +238,7 @@ module Webrat
|
|||||||
def self.xpath_search
|
def self.xpath_search
|
||||||
".//input[@type = 'checkbox']"
|
".//input[@type = 'checkbox']"
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
return nil if @value.nil?
|
return nil if @value.nil?
|
||||||
super
|
super
|
||||||
@ -248,7 +248,7 @@ module Webrat
|
|||||||
raise_error_if_disabled
|
raise_error_if_disabled
|
||||||
set(Webrat::XML.attribute(@element, "value") || "on")
|
set(Webrat::XML.attribute(@element, "value") || "on")
|
||||||
end
|
end
|
||||||
|
|
||||||
def checked?
|
def checked?
|
||||||
Webrat::XML.attribute(@element, "checked") == "checked"
|
Webrat::XML.attribute(@element, "checked") == "checked"
|
||||||
end
|
end
|
||||||
@ -271,11 +271,11 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
class PasswordField < Field #:nodoc:
|
class PasswordField < Field #:nodoc:
|
||||||
|
|
||||||
def self.xpath_search
|
def self.xpath_search
|
||||||
".//input[@type = 'password']"
|
".//input[@type = 'password']"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class RadioField < Field #:nodoc:
|
class RadioField < Field #:nodoc:
|
||||||
@ -283,31 +283,31 @@ module Webrat
|
|||||||
def self.xpath_search
|
def self.xpath_search
|
||||||
".//input[@type = 'radio']"
|
".//input[@type = 'radio']"
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
return nil if @value.nil?
|
return nil if @value.nil?
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def choose
|
def choose
|
||||||
raise_error_if_disabled
|
raise_error_if_disabled
|
||||||
other_options.each do |option|
|
other_options.each do |option|
|
||||||
option.set(nil)
|
option.set(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
set(Webrat::XML.attribute(@element, "value") || "on")
|
set(Webrat::XML.attribute(@element, "value") || "on")
|
||||||
end
|
end
|
||||||
|
|
||||||
def checked?
|
def checked?
|
||||||
Webrat::XML.attribute(@element, "checked") == "checked"
|
Webrat::XML.attribute(@element, "checked") == "checked"
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def other_options
|
def other_options
|
||||||
form.fields.select { |f| f.name == name }
|
form.fields.select { |f| f.name == name }
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_value
|
def default_value
|
||||||
if Webrat::XML.attribute(@element, "checked") == "checked"
|
if Webrat::XML.attribute(@element, "checked") == "checked"
|
||||||
Webrat::XML.attribute(@element, "value") || "on"
|
Webrat::XML.attribute(@element, "value") || "on"
|
||||||
@ -323,7 +323,7 @@ module Webrat
|
|||||||
def self.xpath_search
|
def self.xpath_search
|
||||||
".//textarea"
|
".//textarea"
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def default_value
|
def default_value
|
||||||
@ -331,13 +331,13 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class FileField < Field #:nodoc:
|
class FileField < Field #:nodoc:
|
||||||
|
|
||||||
def self.xpath_search
|
def self.xpath_search
|
||||||
".//input[@type = 'file']"
|
".//input[@type = 'file']"
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :content_type
|
attr_accessor :content_type
|
||||||
|
|
||||||
def set(value, content_type = nil)
|
def set(value, content_type = nil)
|
||||||
@ -352,9 +352,9 @@ module Webrat
|
|||||||
replace_param_value(super, @value, test_uploaded_file)
|
replace_param_value(super, @value, test_uploaded_file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def test_uploaded_file
|
def test_uploaded_file
|
||||||
if content_type
|
if content_type
|
||||||
ActionController::TestUploadedFile.new(@value, content_type)
|
ActionController::TestUploadedFile.new(@value, content_type)
|
||||||
@ -386,13 +386,13 @@ module Webrat
|
|||||||
def options
|
def options
|
||||||
@options ||= SelectOption.load_all(@session, @element)
|
@options ||= SelectOption.load_all(@session, @element)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def default_value
|
def default_value
|
||||||
selected_options = Webrat::XML.xpath_search(@element, ".//option[@selected = 'selected']")
|
selected_options = Webrat::XML.xpath_search(@element, ".//option[@selected = 'selected']")
|
||||||
selected_options = Webrat::XML.xpath_search(@element, ".//option[position() = 1]") if selected_options.empty?
|
selected_options = Webrat::XML.xpath_search(@element, ".//option[position() = 1]") if selected_options.empty?
|
||||||
|
|
||||||
selected_options.map do |option|
|
selected_options.map do |option|
|
||||||
return "" if option.nil?
|
return "" if option.nil?
|
||||||
Webrat::XML.attribute(option, "value") || Webrat::XML.inner_html(option)
|
Webrat::XML.attribute(option, "value") || Webrat::XML.inner_html(option)
|
||||||
|
@ -7,7 +7,7 @@ require "webrat/core/locators/field_named_locator"
|
|||||||
module Webrat
|
module Webrat
|
||||||
class Form < Element #:nodoc:
|
class Form < Element #:nodoc:
|
||||||
attr_reader :element
|
attr_reader :element
|
||||||
|
|
||||||
def self.xpath_search
|
def self.xpath_search
|
||||||
".//form"
|
".//form"
|
||||||
end
|
end
|
||||||
@ -15,21 +15,21 @@ module Webrat
|
|||||||
def fields
|
def fields
|
||||||
@fields ||= Field.load_all(@session, @element)
|
@fields ||= Field.load_all(@session, @element)
|
||||||
end
|
end
|
||||||
|
|
||||||
def submit
|
def submit
|
||||||
@session.request_page(form_action, form_method, params)
|
@session.request_page(form_action, form_method, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_named(name, *field_types)
|
def field_named(name, *field_types)
|
||||||
Webrat::Locators::FieldNamedLocator.new(@session, dom, name, *field_types).locate
|
Webrat::Locators::FieldNamedLocator.new(@session, dom, name, *field_types).locate
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def dom
|
def dom
|
||||||
Webrat::XML.xpath_at(@session.dom, path)
|
Webrat::XML.xpath_at(@session.dom, path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def fields_by_type(field_types)
|
def fields_by_type(field_types)
|
||||||
if field_types.any?
|
if field_types.any?
|
||||||
fields.select { |f| field_types.include?(f.class) }
|
fields.select { |f| field_types.include?(f.class) }
|
||||||
@ -37,26 +37,26 @@ module Webrat
|
|||||||
fields
|
fields
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def params
|
def params
|
||||||
all_params = {}
|
all_params = {}
|
||||||
|
|
||||||
fields.each do |field|
|
fields.each do |field|
|
||||||
next if field.to_param.nil?
|
next if field.to_param.nil?
|
||||||
merge(all_params, field.to_param)
|
merge(all_params, field.to_param)
|
||||||
end
|
end
|
||||||
|
|
||||||
all_params
|
all_params
|
||||||
end
|
end
|
||||||
|
|
||||||
def form_method
|
def form_method
|
||||||
Webrat::XML.attribute(@element, "method").blank? ? :get : Webrat::XML.attribute(@element, "method").downcase
|
Webrat::XML.attribute(@element, "method").blank? ? :get : Webrat::XML.attribute(@element, "method").downcase
|
||||||
end
|
end
|
||||||
|
|
||||||
def form_action
|
def form_action
|
||||||
Webrat::XML.attribute(@element, "action").blank? ? @session.current_url : Webrat::XML.attribute(@element, "action")
|
Webrat::XML.attribute(@element, "action").blank? ? @session.current_url : Webrat::XML.attribute(@element, "action")
|
||||||
end
|
end
|
||||||
|
|
||||||
def merge(all_params, new_param)
|
def merge(all_params, new_param)
|
||||||
new_param.each do |key, value|
|
new_param.each do |key, value|
|
||||||
case all_params[key]
|
case all_params[key]
|
||||||
@ -69,7 +69,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def merge_hash_values(a, b) # :nodoc:
|
def merge_hash_values(a, b) # :nodoc:
|
||||||
a.keys.each do |k|
|
a.keys.each do |k|
|
||||||
if b.has_key?(k)
|
if b.has_key?(k)
|
||||||
@ -85,19 +85,19 @@ module Webrat
|
|||||||
end
|
end
|
||||||
a.merge!(b)
|
a.merge!(b)
|
||||||
end
|
end
|
||||||
|
|
||||||
def hash_classes
|
def hash_classes
|
||||||
klasses = [Hash]
|
klasses = [Hash]
|
||||||
|
|
||||||
case Webrat.configuration.mode
|
case Webrat.configuration.mode
|
||||||
when :rails
|
when :rails
|
||||||
klasses << HashWithIndifferentAccess
|
klasses << HashWithIndifferentAccess
|
||||||
when :merb
|
when :merb
|
||||||
klasses << Mash
|
klasses << Mash
|
||||||
end
|
end
|
||||||
|
|
||||||
klasses
|
klasses
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,9 +2,9 @@ require "webrat/core/elements/element"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
class Label < Element #:nodoc:
|
class Label < Element #:nodoc:
|
||||||
|
|
||||||
attr_reader :element
|
attr_reader :element
|
||||||
|
|
||||||
def self.xpath_search
|
def self.xpath_search
|
||||||
".//label"
|
".//label"
|
||||||
end
|
end
|
||||||
@ -12,13 +12,13 @@ module Webrat
|
|||||||
def for_id
|
def for_id
|
||||||
Webrat::XML.attribute(@element, "for")
|
Webrat::XML.attribute(@element, "for")
|
||||||
end
|
end
|
||||||
|
|
||||||
def field
|
def field
|
||||||
Field.load(@session, field_element)
|
Field.load(@session, field_element)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def field_element
|
def field_element
|
||||||
if for_id.blank?
|
if for_id.blank?
|
||||||
Webrat::XML.xpath_at(@element, *Field.xpath_search_excluding_hidden)
|
Webrat::XML.xpath_at(@element, *Field.xpath_search_excluding_hidden)
|
||||||
@ -26,6 +26,6 @@ module Webrat
|
|||||||
Webrat::XML.css_search(@session.current_dom, "#" + for_id).first
|
Webrat::XML.css_search(@session.current_dom, "#" + for_id).first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,30 +4,30 @@ require "webrat/core/elements/element"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
class Link < Element #:nodoc:
|
class Link < Element #:nodoc:
|
||||||
|
|
||||||
def self.xpath_search
|
def self.xpath_search
|
||||||
".//a[@href]"
|
".//a[@href]"
|
||||||
end
|
end
|
||||||
|
|
||||||
def click(options = {})
|
def click(options = {})
|
||||||
method = options[:method] || http_method
|
method = options[:method] || http_method
|
||||||
return if href =~ /^#/ && method == :get
|
return if href =~ /^#/ && method == :get
|
||||||
|
|
||||||
options[:javascript] = true if options[:javascript].nil?
|
options[:javascript] = true if options[:javascript].nil?
|
||||||
|
|
||||||
if options[:javascript]
|
if options[:javascript]
|
||||||
@session.request_page(absolute_href, method, data)
|
@session.request_page(absolute_href, method, data)
|
||||||
else
|
else
|
||||||
@session.request_page(absolute_href, :get, {})
|
@session.request_page(absolute_href, :get, {})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def id
|
def id
|
||||||
Webrat::XML.attribute(@element, "id")
|
Webrat::XML.attribute(@element, "id")
|
||||||
end
|
end
|
||||||
|
|
||||||
def data
|
def data
|
||||||
authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token}
|
authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token}
|
||||||
end
|
end
|
||||||
@ -49,17 +49,17 @@ module Webrat
|
|||||||
href
|
href
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticity_token
|
def authenticity_token
|
||||||
return unless onclick && onclick.include?("s.setAttribute('name', 'authenticity_token');") &&
|
return unless onclick && onclick.include?("s.setAttribute('name', 'authenticity_token');") &&
|
||||||
onclick =~ /s\.setAttribute\('value', '([a-f0-9]{40})'\);/
|
onclick =~ /s\.setAttribute\('value', '([a-f0-9]{40})'\);/
|
||||||
$LAST_MATCH_INFO.captures.first
|
$LAST_MATCH_INFO.captures.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def onclick
|
def onclick
|
||||||
Webrat::XML.attribute(@element, "onclick")
|
Webrat::XML.attribute(@element, "onclick")
|
||||||
end
|
end
|
||||||
|
|
||||||
def http_method
|
def http_method
|
||||||
if !onclick.blank? && onclick.include?("f.submit()")
|
if !onclick.blank? && onclick.include?("f.submit()")
|
||||||
http_method_from_js_form
|
http_method_from_js_form
|
||||||
@ -87,6 +87,6 @@ module Webrat
|
|||||||
raise Webrat::WebratError.new("No HTTP method for _method param in #{onclick.inspect}")
|
raise Webrat::WebratError.new("No HTTP method for _method param in #{onclick.inspect}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,34 +2,34 @@ require "webrat/core/elements/element"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
class SelectOption < Element #:nodoc:
|
class SelectOption < Element #:nodoc:
|
||||||
|
|
||||||
def self.xpath_search
|
def self.xpath_search
|
||||||
".//option"
|
".//option"
|
||||||
end
|
end
|
||||||
|
|
||||||
def choose
|
def choose
|
||||||
select.raise_error_if_disabled
|
select.raise_error_if_disabled
|
||||||
select.set(value)
|
select.set(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def select
|
def select
|
||||||
SelectField.load(@session, select_element)
|
SelectField.load(@session, select_element)
|
||||||
end
|
end
|
||||||
|
|
||||||
def select_element
|
def select_element
|
||||||
parent = @element.parent
|
parent = @element.parent
|
||||||
|
|
||||||
while parent.respond_to?(:parent)
|
while parent.respond_to?(:parent)
|
||||||
return parent if parent.name == 'select'
|
return parent if parent.name == 'select'
|
||||||
parent = parent.parent
|
parent = parent.parent
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def value
|
def value
|
||||||
Webrat::XML.attribute(@element, "value") || Webrat::XML.inner_html(@element)
|
Webrat::XML.attribute(@element, "value") || Webrat::XML.inner_html(@element)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,10 +11,10 @@ require "webrat/core/locators/form_locator"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Locators
|
module Locators
|
||||||
|
|
||||||
def field_by_xpath(xpath)
|
def field_by_xpath(xpath)
|
||||||
Field.load(@session, Webrat::XML.xpath_at(dom, xpath))
|
Field.load(@session, Webrat::XML.xpath_at(dom, xpath))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,37 +2,37 @@ require "webrat/core/locators/locator"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Locators
|
module Locators
|
||||||
|
|
||||||
class AreaLocator < Locator # :nodoc:
|
class AreaLocator < Locator # :nodoc:
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
Area.load(@session, area_element)
|
Area.load(@session, area_element)
|
||||||
end
|
end
|
||||||
|
|
||||||
def area_element
|
def area_element
|
||||||
area_elements.detect do |area_element|
|
area_elements.detect do |area_element|
|
||||||
Webrat::XML.attribute(area_element, "title") =~ matcher ||
|
Webrat::XML.attribute(area_element, "title") =~ matcher ||
|
||||||
Webrat::XML.attribute(area_element, "id") =~ matcher
|
Webrat::XML.attribute(area_element, "id") =~ matcher
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def matcher
|
def matcher
|
||||||
/#{Regexp.escape(@value.to_s)}/i
|
/#{Regexp.escape(@value.to_s)}/i
|
||||||
end
|
end
|
||||||
|
|
||||||
def area_elements
|
def area_elements
|
||||||
Webrat::XML.xpath_search(@dom, Area.xpath_search)
|
Webrat::XML.xpath_search(@dom, Area.xpath_search)
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_message
|
def error_message
|
||||||
"Could not find area with name #{@value}"
|
"Could not find area with name #{@value}"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_area(id_or_title) #:nodoc:
|
def find_area(id_or_title) #:nodoc:
|
||||||
AreaLocator.new(@session, dom, id_or_title).locate!
|
AreaLocator.new(@session, dom, id_or_title).locate!
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,13 +2,13 @@ require "webrat/core/locators/locator"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Locators
|
module Locators
|
||||||
|
|
||||||
class ButtonLocator < Locator # :nodoc:
|
class ButtonLocator < Locator # :nodoc:
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
ButtonField.load(@session, button_element)
|
ButtonField.load(@session, button_element)
|
||||||
end
|
end
|
||||||
|
|
||||||
def button_element
|
def button_element
|
||||||
button_elements.detect do |element|
|
button_elements.detect do |element|
|
||||||
@value.nil? ||
|
@value.nil? ||
|
||||||
@ -18,37 +18,37 @@ module Webrat
|
|||||||
matches_alt?(element)
|
matches_alt?(element)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_id?(element)
|
def matches_id?(element)
|
||||||
(@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") =~ @value) ||
|
(@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") =~ @value) ||
|
||||||
(!@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") == @value.to_s)
|
(!@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") == @value.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_value?(element)
|
def matches_value?(element)
|
||||||
Webrat::XML.attribute(element, "value") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
|
Webrat::XML.attribute(element, "value") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_html?(element)
|
def matches_html?(element)
|
||||||
Webrat::XML.inner_html(element) =~ /#{Regexp.escape(@value.to_s)}/i
|
Webrat::XML.inner_html(element) =~ /#{Regexp.escape(@value.to_s)}/i
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_alt?(element)
|
def matches_alt?(element)
|
||||||
Webrat::XML.attribute(element, "alt") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
|
Webrat::XML.attribute(element, "alt") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
|
||||||
end
|
end
|
||||||
|
|
||||||
def button_elements
|
def button_elements
|
||||||
Webrat::XML.xpath_search(@dom, *ButtonField.xpath_search)
|
Webrat::XML.xpath_search(@dom, *ButtonField.xpath_search)
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_message
|
def error_message
|
||||||
"Could not find button #{@value.inspect}"
|
"Could not find button #{@value.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_button(value) #:nodoc:
|
def find_button(value) #:nodoc:
|
||||||
ButtonLocator.new(@session, dom, value).locate!
|
ButtonLocator.new(@session, dom, value).locate!
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,13 +2,13 @@ require "webrat/core/locators/locator"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Locators
|
module Locators
|
||||||
|
|
||||||
class FieldByIdLocator < Locator # :nodoc:
|
class FieldByIdLocator < Locator # :nodoc:
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
Field.load(@session, field_element)
|
Field.load(@session, field_element)
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_element
|
def field_element
|
||||||
field_elements.detect do |field_element|
|
field_elements.detect do |field_element|
|
||||||
if @value.is_a?(Regexp)
|
if @value.is_a?(Regexp)
|
||||||
@ -18,7 +18,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_elements
|
def field_elements
|
||||||
Webrat::XML.xpath_search(@dom, *Field.xpath_search)
|
Webrat::XML.xpath_search(@dom, *Field.xpath_search)
|
||||||
end
|
end
|
||||||
@ -26,12 +26,12 @@ module Webrat
|
|||||||
def error_message
|
def error_message
|
||||||
"Could not find field with id #{@value.inspect}"
|
"Could not find field with id #{@value.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_with_id(id, *field_types)
|
def field_with_id(id, *field_types)
|
||||||
FieldByIdLocator.new(@session, dom, id, *field_types).locate!
|
FieldByIdLocator.new(@session, dom, id, *field_types).locate!
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,13 +3,13 @@ require "webrat/core/locators/locator"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Locators
|
module Locators
|
||||||
|
|
||||||
class FieldLabeledLocator < Locator # :nodoc:
|
class FieldLabeledLocator < Locator # :nodoc:
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
matching_labels.any? && matching_labels.detect_mapped { |label| label.field }
|
matching_labels.any? && matching_labels.detect_mapped { |label| label.field }
|
||||||
end
|
end
|
||||||
|
|
||||||
def matching_labels
|
def matching_labels
|
||||||
matching_label_elements.sort_by do |label_element|
|
matching_label_elements.sort_by do |label_element|
|
||||||
text(label_element).length
|
text(label_element).length
|
||||||
@ -17,21 +17,21 @@ module Webrat
|
|||||||
Label.load(@session, label_element)
|
Label.load(@session, label_element)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def matching_label_elements
|
def matching_label_elements
|
||||||
label_elements.select do |label_element|
|
label_elements.select do |label_element|
|
||||||
text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
|
text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def label_elements
|
def label_elements
|
||||||
Webrat::XML.xpath_search(@dom, Label.xpath_search)
|
Webrat::XML.xpath_search(@dom, Label.xpath_search)
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_message
|
def error_message
|
||||||
"Could not find field labeled #{@value.inspect}"
|
"Could not find field labeled #{@value.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def text(element)
|
def text(element)
|
||||||
str = Webrat::XML.all_inner_text(element)
|
str = Webrat::XML.all_inner_text(element)
|
||||||
str.gsub!("\n","")
|
str.gsub!("\n","")
|
||||||
@ -39,9 +39,9 @@ module Webrat
|
|||||||
str.squeeze!(" ")
|
str.squeeze!(" ")
|
||||||
str
|
str
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Locates a form field based on a <tt>label</tt> element in the HTML source.
|
# Locates a form field based on a <tt>label</tt> element in the HTML source.
|
||||||
# This can be useful in order to verify that a field is pre-filled with the
|
# This can be useful in order to verify that a field is pre-filled with the
|
||||||
# correct value.
|
# correct value.
|
||||||
@ -51,6 +51,6 @@ module Webrat
|
|||||||
def field_labeled(label, *field_types)
|
def field_labeled(label, *field_types)
|
||||||
FieldLabeledLocator.new(@session, dom, label, *field_types).locate!
|
FieldLabeledLocator.new(@session, dom, label, *field_types).locate!
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,24 +2,24 @@ require "webrat/core/locators/locator"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Locators
|
module Locators
|
||||||
|
|
||||||
class FieldLocator < Locator # :nodoc:
|
class FieldLocator < Locator # :nodoc:
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
FieldByIdLocator.new(@session, @dom, @value).locate ||
|
FieldByIdLocator.new(@session, @dom, @value).locate ||
|
||||||
FieldNamedLocator.new(@session, @dom, @value, *@field_types).locate ||
|
FieldNamedLocator.new(@session, @dom, @value, *@field_types).locate ||
|
||||||
FieldLabeledLocator.new(@session, @dom, @value, *@field_types).locate
|
FieldLabeledLocator.new(@session, @dom, @value, *@field_types).locate
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_message
|
def error_message
|
||||||
"Could not find field: #{@value.inspect}"
|
"Could not find field: #{@value.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def field(*args) # :nodoc:
|
def field(*args) # :nodoc:
|
||||||
FieldLocator.new(@session, dom, *args).locate!
|
FieldLocator.new(@session, dom, *args).locate!
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,23 +2,23 @@ require "webrat/core/locators/locator"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Locators
|
module Locators
|
||||||
|
|
||||||
class FieldNamedLocator < Locator # :nodoc:
|
class FieldNamedLocator < Locator # :nodoc:
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
Field.load(@session, field_element)
|
Field.load(@session, field_element)
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_element
|
def field_element
|
||||||
field_elements.detect do |field_element|
|
field_elements.detect do |field_element|
|
||||||
Webrat::XML.attribute(field_element, "name") == @value.to_s
|
Webrat::XML.attribute(field_element, "name") == @value.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_elements
|
def field_elements
|
||||||
Webrat::XML.xpath_search(@dom, *xpath_searches)
|
Webrat::XML.xpath_search(@dom, *xpath_searches)
|
||||||
end
|
end
|
||||||
|
|
||||||
def xpath_searches
|
def xpath_searches
|
||||||
if @field_types.any?
|
if @field_types.any?
|
||||||
@field_types.map { |field_type| field_type.xpath_search }.flatten
|
@field_types.map { |field_type| field_type.xpath_search }.flatten
|
||||||
@ -26,16 +26,16 @@ module Webrat
|
|||||||
Array(Field.xpath_search)
|
Array(Field.xpath_search)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_message
|
def error_message
|
||||||
"Could not find field named #{@value.inspect}"
|
"Could not find field named #{@value.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_named(name, *field_types)
|
def field_named(name, *field_types)
|
||||||
FieldNamedLocator.new(@session, dom, name, *field_types).locate!
|
FieldNamedLocator.new(@session, dom, name, *field_types).locate!
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,18 +2,18 @@ require "webrat/core/locators/locator"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Locators
|
module Locators
|
||||||
|
|
||||||
class FormLocator < Locator # :nodoc:
|
class FormLocator < Locator # :nodoc:
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
Form.load(@session, form_element)
|
Form.load(@session, form_element)
|
||||||
end
|
end
|
||||||
|
|
||||||
def form_element
|
def form_element
|
||||||
Webrat::XML.css_at(@dom, "#" + @value)
|
Webrat::XML.css_at(@dom, "#" + @value)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,23 +3,23 @@ require "webrat/core/locators/locator"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Locators
|
module Locators
|
||||||
|
|
||||||
class LabelLocator < Locator # :nodoc:
|
class LabelLocator < Locator # :nodoc:
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
Label.load(@session, label_element)
|
Label.load(@session, label_element)
|
||||||
end
|
end
|
||||||
|
|
||||||
def label_element
|
def label_element
|
||||||
label_elements.detect do |label_element|
|
label_elements.detect do |label_element|
|
||||||
text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
|
text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def label_elements
|
def label_elements
|
||||||
Webrat::XML.xpath_search(@dom, Label.xpath_search)
|
Webrat::XML.xpath_search(@dom, Label.xpath_search)
|
||||||
end
|
end
|
||||||
|
|
||||||
def text(label_element)
|
def text(label_element)
|
||||||
str = Webrat::XML.all_inner_text(label_element)
|
str = Webrat::XML.all_inner_text(label_element)
|
||||||
str.gsub!("\n","")
|
str.gsub!("\n","")
|
||||||
@ -27,8 +27,8 @@ module Webrat
|
|||||||
str.squeeze!(" ")
|
str.squeeze!(" ")
|
||||||
str
|
str
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,24 +2,24 @@ require "webrat/core/locators/locator"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Locators
|
module Locators
|
||||||
|
|
||||||
class LinkLocator < Locator # :nodoc:
|
class LinkLocator < Locator # :nodoc:
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
Link.load(@session, link_element)
|
Link.load(@session, link_element)
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_element
|
def link_element
|
||||||
matching_links.min { |a, b| Webrat::XML.all_inner_text(a).length <=> Webrat::XML.all_inner_text(b).length }
|
matching_links.min { |a, b| Webrat::XML.all_inner_text(a).length <=> Webrat::XML.all_inner_text(b).length }
|
||||||
end
|
end
|
||||||
|
|
||||||
def matching_links
|
def matching_links
|
||||||
@matching_links ||= link_elements.select do |link_element|
|
@matching_links ||= link_elements.select do |link_element|
|
||||||
matches_text?(link_element) ||
|
matches_text?(link_element) ||
|
||||||
matches_id?(link_element)
|
matches_id?(link_element)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_text?(link)
|
def matches_text?(link)
|
||||||
if @value.is_a?(Regexp)
|
if @value.is_a?(Regexp)
|
||||||
matcher = @value
|
matcher = @value
|
||||||
@ -39,11 +39,11 @@ module Webrat
|
|||||||
(Webrat::XML.attribute(link, "id") == @value) ? true : false
|
(Webrat::XML.attribute(link, "id") == @value) ? true : false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_elements
|
def link_elements
|
||||||
Webrat::XML.xpath_search(@dom, *Link.xpath_search)
|
Webrat::XML.xpath_search(@dom, *Link.xpath_search)
|
||||||
end
|
end
|
||||||
|
|
||||||
def replace_nbsp(str)
|
def replace_nbsp(str)
|
||||||
str.gsub([0xA0].pack('U'), ' ')
|
str.gsub([0xA0].pack('U'), ' ')
|
||||||
end
|
end
|
||||||
@ -51,16 +51,16 @@ module Webrat
|
|||||||
def replace_nbsp_ref(str)
|
def replace_nbsp_ref(str)
|
||||||
str.gsub(' ',' ').gsub(' ', ' ')
|
str.gsub(' ',' ').gsub(' ', ' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_message
|
def error_message
|
||||||
"Could not find link with text or title or id #{@value.inspect}"
|
"Could not find link with text or title or id #{@value.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_link(text_or_title_or_id) #:nodoc:
|
def find_link(text_or_title_or_id) #:nodoc:
|
||||||
LinkLocator.new(@session, dom, text_or_title_or_id).locate!
|
LinkLocator.new(@session, dom, text_or_title_or_id).locate!
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
module Locators
|
module Locators
|
||||||
|
|
||||||
class Locator # :nodoc:
|
class Locator # :nodoc:
|
||||||
|
|
||||||
def initialize(session, dom, value, *field_types)
|
def initialize(session, dom, value, *field_types)
|
||||||
@ -9,12 +9,12 @@ module Webrat
|
|||||||
@value = value
|
@value = value
|
||||||
@field_types = field_types
|
@field_types = field_types
|
||||||
end
|
end
|
||||||
|
|
||||||
def locate!
|
def locate!
|
||||||
locate || raise(NotFoundError.new(error_message))
|
locate || raise(NotFoundError.new(error_message))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,20 +3,20 @@ require "webrat/core/locators/locator"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Locators
|
module Locators
|
||||||
|
|
||||||
class SelectOptionLocator < Locator # :nodoc:
|
class SelectOptionLocator < Locator # :nodoc:
|
||||||
|
|
||||||
def initialize(session, dom, option_text, id_or_name_or_label)
|
def initialize(session, dom, option_text, id_or_name_or_label)
|
||||||
@session = session
|
@session = session
|
||||||
@dom = dom
|
@dom = dom
|
||||||
@option_text = option_text
|
@option_text = option_text
|
||||||
@id_or_name_or_label = id_or_name_or_label
|
@id_or_name_or_label = id_or_name_or_label
|
||||||
end
|
end
|
||||||
|
|
||||||
def locate
|
def locate
|
||||||
if @id_or_name_or_label
|
if @id_or_name_or_label
|
||||||
field = FieldLocator.new(@session, @dom, @id_or_name_or_label, SelectField).locate!
|
field = FieldLocator.new(@session, @dom, @id_or_name_or_label, SelectField).locate!
|
||||||
|
|
||||||
field.options.detect do |o|
|
field.options.detect do |o|
|
||||||
if @option_text.is_a?(Regexp)
|
if @option_text.is_a?(Regexp)
|
||||||
Webrat::XML.inner_html(o.element) =~ @option_text
|
Webrat::XML.inner_html(o.element) =~ @option_text
|
||||||
@ -32,15 +32,15 @@ module Webrat
|
|||||||
Webrat::XML.inner_html(o) == @option_text.to_s
|
Webrat::XML.inner_html(o) == @option_text.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
SelectOption.load(@session, option_element)
|
SelectOption.load(@session, option_element)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def option_elements
|
def option_elements
|
||||||
Webrat::XML.xpath_search(@dom, *SelectOption.xpath_search)
|
Webrat::XML.xpath_search(@dom, *SelectOption.xpath_search)
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_message
|
def error_message
|
||||||
if @id_or_name_or_label
|
if @id_or_name_or_label
|
||||||
"The '#{@option_text}' option was not found in the #{@id_or_name_or_label.inspect} select box"
|
"The '#{@option_text}' option was not found in the #{@id_or_name_or_label.inspect} select box"
|
||||||
@ -48,12 +48,12 @@ module Webrat
|
|||||||
"Could not find option #{@option_text.inspect}"
|
"Could not find option #{@option_text.inspect}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def select_option(option_text, id_or_name_or_label = nil) #:nodoc:
|
def select_option(option_text, id_or_name_or_label = nil) #:nodoc:
|
||||||
SelectOptionLocator.new(@session, dom, option_text, id_or_name_or_label).locate!
|
SelectOptionLocator.new(@session, dom, option_text, id_or_name_or_label).locate!
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
module Logging #:nodoc:
|
module Logging #:nodoc:
|
||||||
|
|
||||||
def debug_log(message) # :nodoc:
|
def debug_log(message) # :nodoc:
|
||||||
return unless logger
|
return unless logger
|
||||||
logger.debug message
|
logger.debug message
|
||||||
@ -16,6 +16,6 @@ module Webrat
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
module Matchers
|
module Matchers
|
||||||
|
|
||||||
class HasContent #:nodoc:
|
class HasContent #:nodoc:
|
||||||
def initialize(content)
|
def initialize(content)
|
||||||
@content = content
|
@content = content
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches?(stringlike)
|
def matches?(stringlike)
|
||||||
if Webrat.configuration.parse_with_nokogiri?
|
if Webrat.configuration.parse_with_nokogiri?
|
||||||
@document = Webrat.nokogiri_document(stringlike)
|
@document = Webrat.nokogiri_document(stringlike)
|
||||||
else
|
else
|
||||||
@document = Webrat.hpricot_document(stringlike)
|
@document = Webrat.hpricot_document(stringlike)
|
||||||
end
|
end
|
||||||
|
|
||||||
@element = Webrat::XML.inner_text(@document)
|
@element = Webrat::XML.inner_text(@document)
|
||||||
|
|
||||||
case @content
|
case @content
|
||||||
when String
|
when String
|
||||||
@element.include?(@content)
|
@element.include?(@content)
|
||||||
@ -22,7 +22,7 @@ module Webrat
|
|||||||
@element.match(@content)
|
@element.match(@content)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# String:: The failure message.
|
# String:: The failure message.
|
||||||
def failure_message
|
def failure_message
|
||||||
@ -34,11 +34,11 @@ module Webrat
|
|||||||
def negative_failure_message
|
def negative_failure_message
|
||||||
"expected the following element's content to not #{content_message}:\n#{squeeze_space(@element)}"
|
"expected the following element's content to not #{content_message}:\n#{squeeze_space(@element)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def squeeze_space(inner_text)
|
def squeeze_space(inner_text)
|
||||||
inner_text.gsub(/^\s*$/, "").squeeze("\n")
|
inner_text.gsub(/^\s*$/, "").squeeze("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_message
|
def content_message
|
||||||
case @content
|
case @content
|
||||||
when String
|
when String
|
||||||
@ -48,26 +48,26 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Matches the contents of an HTML document with
|
# Matches the contents of an HTML document with
|
||||||
# whatever string is supplied
|
# whatever string is supplied
|
||||||
def contain(content)
|
def contain(content)
|
||||||
HasContent.new(content)
|
HasContent.new(content)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Asserts that the body of the response contain
|
# Asserts that the body of the response contain
|
||||||
# the supplied string or regexp
|
# the supplied string or regexp
|
||||||
def assert_contain(content)
|
def assert_contain(content)
|
||||||
hc = HasContent.new(content)
|
hc = HasContent.new(content)
|
||||||
assert hc.matches?(response_body), hc.failure_message
|
assert hc.matches?(response_body), hc.failure_message
|
||||||
end
|
end
|
||||||
|
|
||||||
# Asserts that the body of the response
|
# Asserts that the body of the response
|
||||||
# does not contain the supplied string or regepx
|
# does not contain the supplied string or regepx
|
||||||
def assert_not_contain(content)
|
def assert_not_contain(content)
|
||||||
hc = HasContent.new(content)
|
hc = HasContent.new(content)
|
||||||
assert !hc.matches?(response_body), hc.negative_failure_message
|
assert !hc.matches?(response_body), hc.negative_failure_message
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,7 @@ require "webrat/core/matchers/have_xpath"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Matchers
|
module Matchers
|
||||||
|
|
||||||
class HaveSelector < HaveXpath #:nodoc:
|
class HaveSelector < HaveXpath #:nodoc:
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# String:: The failure message.
|
# String:: The failure message.
|
||||||
@ -15,7 +15,7 @@ module Webrat
|
|||||||
def negative_failure_message
|
def negative_failure_message
|
||||||
"expected following output to omit a #{tag_inspect}:\n#{@document}"
|
"expected following output to omit a #{tag_inspect}:\n#{@document}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_inspect
|
def tag_inspect
|
||||||
options = @options.dup
|
options = @options.dup
|
||||||
count = options.delete(:count)
|
count = options.delete(:count)
|
||||||
@ -40,9 +40,9 @@ module Webrat
|
|||||||
ast.to_xpath
|
ast.to_xpath
|
||||||
end.first
|
end.first
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Matches HTML content against a CSS 3 selector.
|
# Matches HTML content against a CSS 3 selector.
|
||||||
#
|
#
|
||||||
# ==== Parameters
|
# ==== Parameters
|
||||||
@ -54,21 +54,21 @@ module Webrat
|
|||||||
HaveSelector.new(name, attributes, &block)
|
HaveSelector.new(name, attributes, &block)
|
||||||
end
|
end
|
||||||
alias_method :match_selector, :have_selector
|
alias_method :match_selector, :have_selector
|
||||||
|
|
||||||
|
|
||||||
# Asserts that the body of the response contains
|
# Asserts that the body of the response contains
|
||||||
# the supplied selector
|
# the supplied selector
|
||||||
def assert_have_selector(name, attributes = {}, &block)
|
def assert_have_selector(name, attributes = {}, &block)
|
||||||
matcher = HaveSelector.new(name, attributes, &block)
|
matcher = HaveSelector.new(name, attributes, &block)
|
||||||
assert matcher.matches?(response_body), matcher.failure_message
|
assert matcher.matches?(response_body), matcher.failure_message
|
||||||
end
|
end
|
||||||
|
|
||||||
# Asserts that the body of the response
|
# Asserts that the body of the response
|
||||||
# does not contain the supplied string or regepx
|
# does not contain the supplied string or regepx
|
||||||
def assert_have_no_selector(name, attributes = {}, &block)
|
def assert_have_no_selector(name, attributes = {}, &block)
|
||||||
matcher = HaveSelector.new(name, attributes, &block)
|
matcher = HaveSelector.new(name, attributes, &block)
|
||||||
assert !matcher.matches?(response_body), matcher.negative_failure_message
|
assert !matcher.matches?(response_body), matcher.negative_failure_message
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,16 +6,16 @@ module Webrat
|
|||||||
def have_tag(*args, &block)
|
def have_tag(*args, &block)
|
||||||
have_selector(*args, &block)
|
have_selector(*args, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :match_tag, :have_tag
|
alias_method :match_tag, :have_tag
|
||||||
|
|
||||||
def assert_have_tag(*args, &block)
|
def assert_have_tag(*args, &block)
|
||||||
assert_have_selector(*args, &block)
|
assert_have_selector(*args, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_have_no_tag(*args, &block)
|
def assert_have_no_tag(*args, &block)
|
||||||
assert_have_no_selector(*args, &block)
|
assert_have_no_selector(*args, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,25 +3,25 @@ require "webrat/core/xml/rexml"
|
|||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Matchers
|
module Matchers
|
||||||
|
|
||||||
class HaveXpath #:nodoc:
|
class HaveXpath #:nodoc:
|
||||||
def initialize(expected, options = {}, &block)
|
def initialize(expected, options = {}, &block)
|
||||||
@expected = expected
|
@expected = expected
|
||||||
@options = options
|
@options = options
|
||||||
@block = block
|
@block = block
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches?(stringlike, &block)
|
def matches?(stringlike, &block)
|
||||||
@block ||= block
|
@block ||= block
|
||||||
matched = matches(stringlike)
|
matched = matches(stringlike)
|
||||||
|
|
||||||
if @options[:count]
|
if @options[:count]
|
||||||
matched.size == @options[:count] && (!@block || @block.call(matched))
|
matched.size == @options[:count] && (!@block || @block.call(matched))
|
||||||
else
|
else
|
||||||
matched.any? && (!@block || @block.call(matched))
|
matched.any? && (!@block || @block.call(matched))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches(stringlike)
|
def matches(stringlike)
|
||||||
if Webrat.configuration.parse_with_nokogiri?
|
if Webrat.configuration.parse_with_nokogiri?
|
||||||
nokogiri_matches(stringlike)
|
nokogiri_matches(stringlike)
|
||||||
@ -29,7 +29,7 @@ module Webrat
|
|||||||
rexml_matches(stringlike)
|
rexml_matches(stringlike)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def rexml_matches(stringlike)
|
def rexml_matches(stringlike)
|
||||||
if REXML::Node === stringlike || Array === stringlike
|
if REXML::Node === stringlike || Array === stringlike
|
||||||
@query = query.map { |q| q.gsub(%r'//', './') }
|
@query = query.map { |q| q.gsub(%r'//', './') }
|
||||||
@ -49,48 +49,48 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end.flatten.compact
|
end.flatten.compact
|
||||||
end
|
end
|
||||||
|
|
||||||
def nokogiri_matches(stringlike)
|
def nokogiri_matches(stringlike)
|
||||||
if Nokogiri::XML::NodeSet === stringlike
|
if Nokogiri::XML::NodeSet === stringlike
|
||||||
@query = query.gsub(%r'//', './')
|
@query = query.gsub(%r'//', './')
|
||||||
else
|
else
|
||||||
@query = query
|
@query = query
|
||||||
end
|
end
|
||||||
|
|
||||||
add_options_conditions_to(@query)
|
add_options_conditions_to(@query)
|
||||||
|
|
||||||
@document = Webrat::XML.document(stringlike)
|
@document = Webrat::XML.document(stringlike)
|
||||||
@document.xpath(*@query)
|
@document.xpath(*@query)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_options_conditions_to(query)
|
def add_options_conditions_to(query)
|
||||||
add_attributes_conditions_to(query)
|
add_attributes_conditions_to(query)
|
||||||
add_content_condition_to(query)
|
add_content_condition_to(query)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_attributes_conditions_to(query)
|
def add_attributes_conditions_to(query)
|
||||||
attribute_conditions = []
|
attribute_conditions = []
|
||||||
|
|
||||||
@options.each do |key, value|
|
@options.each do |key, value|
|
||||||
next if [:content, :count].include?(key)
|
next if [:content, :count].include?(key)
|
||||||
attribute_conditions << "@#{key} = #{xpath_escape(value)}"
|
attribute_conditions << "@#{key} = #{xpath_escape(value)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if attribute_conditions.any?
|
if attribute_conditions.any?
|
||||||
query << "[#{attribute_conditions.join(' and ')}]"
|
query << "[#{attribute_conditions.join(' and ')}]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_content_condition_to(query)
|
def add_content_condition_to(query)
|
||||||
if @options[:content]
|
if @options[:content]
|
||||||
query << "[contains(., #{xpath_escape(@options[:content])})]"
|
query << "[contains(., #{xpath_escape(@options[:content])})]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def query
|
def query
|
||||||
@expected
|
@expected
|
||||||
end
|
end
|
||||||
|
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# String:: The failure message.
|
# String:: The failure message.
|
||||||
def failure_message
|
def failure_message
|
||||||
@ -102,15 +102,15 @@ module Webrat
|
|||||||
def negative_failure_message
|
def negative_failure_message
|
||||||
"expected following text to not match xpath #{@expected}:\n#{@document}"
|
"expected following text to not match xpath #{@expected}:\n#{@document}"
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def xpath_escape(string)
|
def xpath_escape(string)
|
||||||
if string.include?("'") && string.include?('"')
|
if string.include?("'") && string.include?('"')
|
||||||
parts = string.split("'").map do |part|
|
parts = string.split("'").map do |part|
|
||||||
"'#{part}'"
|
"'#{part}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
"concat(" + parts.join(", \"'\", ") + ")"
|
"concat(" + parts.join(", \"'\", ") + ")"
|
||||||
elsif string.include?("'")
|
elsif string.include?("'")
|
||||||
"\"#{string}\""
|
"\"#{string}\""
|
||||||
@ -118,9 +118,9 @@ module Webrat
|
|||||||
"'#{string}'"
|
"'#{string}'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Matches HTML content against an XPath query
|
# Matches HTML content against an XPath query
|
||||||
#
|
#
|
||||||
# ==== Parameters
|
# ==== Parameters
|
||||||
@ -132,16 +132,16 @@ module Webrat
|
|||||||
HaveXpath.new(expected, options, &block)
|
HaveXpath.new(expected, options, &block)
|
||||||
end
|
end
|
||||||
alias_method :match_xpath, :have_xpath
|
alias_method :match_xpath, :have_xpath
|
||||||
|
|
||||||
def assert_have_xpath(expected, options = {}, &block)
|
def assert_have_xpath(expected, options = {}, &block)
|
||||||
hs = HaveXpath.new(expected, options, &block)
|
hs = HaveXpath.new(expected, options, &block)
|
||||||
assert hs.matches?(response_body), hs.failure_message
|
assert hs.matches?(response_body), hs.failure_message
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_have_no_xpath(expected, options = {}, &block)
|
def assert_have_no_xpath(expected, options = {}, &block)
|
||||||
hs = HaveXpath.new(expected, options, &block)
|
hs = HaveXpath.new(expected, options, &block)
|
||||||
assert !hs.matches?(response_body), hs.negative_failure_message
|
assert !hs.matches?(response_body), hs.negative_failure_message
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -10,15 +10,15 @@ module Webrat
|
|||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def webrat
|
def webrat
|
||||||
webrat_session
|
webrat_session
|
||||||
end
|
end
|
||||||
|
|
||||||
def webrat_session
|
def webrat_session
|
||||||
@_webrat_session ||= ::Webrat.session_class.new(self)
|
@_webrat_session ||= ::Webrat.session_class.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
# all of these methods delegate to the @session, which should
|
# all of these methods delegate to the @session, which should
|
||||||
# be created transparently.
|
# be created transparently.
|
||||||
#
|
#
|
||||||
@ -31,7 +31,7 @@ module Webrat
|
|||||||
:header, :http_accept, :basic_auth,
|
:header, :http_accept, :basic_auth,
|
||||||
:save_and_open_page,
|
:save_and_open_page,
|
||||||
:fills_in, :fill_in,
|
:fills_in, :fill_in,
|
||||||
:checks, :check,
|
:checks, :check,
|
||||||
:unchecks, :uncheck,
|
:unchecks, :uncheck,
|
||||||
:chooses, :choose,
|
:chooses, :choose,
|
||||||
:selects, :select,
|
:selects, :select,
|
||||||
@ -47,15 +47,15 @@ module Webrat
|
|||||||
:select_option,
|
:select_option,
|
||||||
:set_hidden_field, :submit_form,
|
:set_hidden_field, :submit_form,
|
||||||
:request_page, :current_dom,
|
:request_page, :current_dom,
|
||||||
:response_body,
|
:response_body,
|
||||||
:selects_date, :selects_time, :selects_datetime,
|
:selects_date, :selects_time, :selects_datetime,
|
||||||
:select_date, :select_time, :select_datetime,
|
:select_date, :select_time, :select_datetime,
|
||||||
:field_by_xpath,
|
:field_by_xpath,
|
||||||
:field_with_id,
|
:field_with_id,
|
||||||
:selenium,
|
:selenium,
|
||||||
:simulate, :automate
|
:simulate, :automate
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module Webrat #:nodoc:
|
module Webrat #:nodoc:
|
||||||
module MIME #:nodoc:
|
module MIME #:nodoc:
|
||||||
|
|
||||||
def self.mime_type(string_or_symbol) #:nodoc:
|
def self.mime_type(string_or_symbol) #:nodoc:
|
||||||
if string_or_symbol.is_a?(String)
|
if string_or_symbol.is_a?(String)
|
||||||
string_or_symbol
|
string_or_symbol
|
||||||
@ -24,6 +24,6 @@ module Webrat #:nodoc:
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,21 +2,21 @@ module Webrat
|
|||||||
module SaveAndOpenPage
|
module SaveAndOpenPage
|
||||||
# Saves the page out to RAILS_ROOT/tmp/ and opens it in the default
|
# Saves the page out to RAILS_ROOT/tmp/ and opens it in the default
|
||||||
# web browser if on OS X. Useful for debugging.
|
# web browser if on OS X. Useful for debugging.
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
# save_and_open_page
|
# save_and_open_page
|
||||||
def save_and_open_page
|
def save_and_open_page
|
||||||
return unless File.exist?(saved_page_dir)
|
return unless File.exist?(saved_page_dir)
|
||||||
|
|
||||||
filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.html"
|
filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.html"
|
||||||
|
|
||||||
File.open(filename, "w") do |f|
|
File.open(filename, "w") do |f|
|
||||||
f.write rewrite_css_and_image_references(response_body)
|
f.write rewrite_css_and_image_references(response_body)
|
||||||
end
|
end
|
||||||
|
|
||||||
open_in_browser(filename)
|
open_in_browser(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
def open_in_browser(path) # :nodoc
|
def open_in_browser(path) # :nodoc
|
||||||
platform = ruby_platform
|
platform = ruby_platform
|
||||||
if platform =~ /cygwin/ || platform =~ /win32/
|
if platform =~ /cygwin/ || platform =~ /win32/
|
||||||
@ -25,26 +25,26 @@ module Webrat
|
|||||||
`open #{path}`
|
`open #{path}`
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def rewrite_css_and_image_references(response_html) # :nodoc:
|
def rewrite_css_and_image_references(response_html) # :nodoc:
|
||||||
return response_html unless doc_root
|
return response_html unless doc_root
|
||||||
response_html.gsub(/"\/(stylesheets|images)/, doc_root + '/\1')
|
response_html.gsub(/"\/(stylesheets|images)/, doc_root + '/\1')
|
||||||
end
|
end
|
||||||
|
|
||||||
def saved_page_dir #:nodoc:
|
def saved_page_dir #:nodoc:
|
||||||
File.expand_path(".")
|
File.expand_path(".")
|
||||||
end
|
end
|
||||||
|
|
||||||
def doc_root #:nodoc:
|
def doc_root #:nodoc:
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# accessor for testing
|
# accessor for testing
|
||||||
def ruby_platform
|
def ruby_platform
|
||||||
RUBY_PLATFORM
|
RUBY_PLATFORM
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,36 +6,36 @@ module Webrat
|
|||||||
# An HTML element (link, button, field, etc.) that Webrat expected was not found on the page
|
# An HTML element (link, button, field, etc.) that Webrat expected was not found on the page
|
||||||
class NotFoundError < WebratError
|
class NotFoundError < WebratError
|
||||||
end
|
end
|
||||||
|
|
||||||
class Scope
|
class Scope
|
||||||
include Logging
|
include Logging
|
||||||
include Locators
|
include Locators
|
||||||
|
|
||||||
def self.from_page(session, response, response_body) #:nodoc:
|
def self.from_page(session, response, response_body) #:nodoc:
|
||||||
new(session) do
|
new(session) do
|
||||||
@response = response
|
@response = response
|
||||||
@response_body = response_body
|
@response_body = response_body
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_scope(session, scope, selector) #:nodoc:
|
def self.from_scope(session, scope, selector) #:nodoc:
|
||||||
new(session) do
|
new(session) do
|
||||||
@scope = scope
|
@scope = scope
|
||||||
@selector = selector
|
@selector = selector
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :session
|
attr_reader :session
|
||||||
|
|
||||||
def initialize(session, &block) #:nodoc:
|
def initialize(session, &block) #:nodoc:
|
||||||
@session = session
|
@session = session
|
||||||
instance_eval(&block) if block_given?
|
instance_eval(&block) if block_given?
|
||||||
|
|
||||||
if @selector && scoped_dom.nil?
|
if @selector && scoped_dom.nil?
|
||||||
raise Webrat::NotFoundError.new("The scope was not found on the page: #{@selector.inspect}")
|
raise Webrat::NotFoundError.new("The scope was not found on the page: #{@selector.inspect}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Verifies an input field or textarea exists on the current page, and stores a value for
|
# Verifies an input field or textarea exists on the current page, and stores a value for
|
||||||
# it which will be sent when the form is submitted.
|
# it which will be sent when the form is submitted.
|
||||||
#
|
#
|
||||||
@ -53,7 +53,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
webrat_deprecate :fills_in, :fill_in
|
webrat_deprecate :fills_in, :fill_in
|
||||||
|
|
||||||
# Verifies that a hidden field exists on the current page and sets
|
# Verifies that a hidden field exists on the current page and sets
|
||||||
# the value to that given by the <tt>:to</tt> option.
|
# the value to that given by the <tt>:to</tt> option.
|
||||||
#
|
#
|
||||||
@ -63,7 +63,7 @@ module Webrat
|
|||||||
field = locate_field(field_locator, HiddenField)
|
field = locate_field(field_locator, HiddenField)
|
||||||
field.set(options[:to])
|
field.set(options[:to])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Verifies that an input checkbox exists on the current page and marks it
|
# Verifies that an input checkbox exists on the current page and marks it
|
||||||
# as checked, so that the value will be submitted with the form.
|
# as checked, so that the value will be submitted with the form.
|
||||||
#
|
#
|
||||||
@ -74,7 +74,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
webrat_deprecate :checks, :check
|
webrat_deprecate :checks, :check
|
||||||
|
|
||||||
# Verifies that an input checkbox exists on the current page and marks it
|
# Verifies that an input checkbox exists on the current page and marks it
|
||||||
# as unchecked, so that the value will not be submitted with the form.
|
# as unchecked, so that the value will not be submitted with the form.
|
||||||
#
|
#
|
||||||
@ -85,7 +85,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
webrat_deprecate :unchecks, :uncheck
|
webrat_deprecate :unchecks, :uncheck
|
||||||
|
|
||||||
# Verifies that an input radio button exists on the current page and marks it
|
# Verifies that an input radio button exists on the current page and marks it
|
||||||
# as checked, so that the value will be submitted with the form.
|
# as checked, so that the value will be submitted with the form.
|
||||||
#
|
#
|
||||||
@ -96,7 +96,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
webrat_deprecate :chooses, :choose
|
webrat_deprecate :chooses, :choose
|
||||||
|
|
||||||
# Verifies that a an option element exists on the current page with the specified
|
# Verifies that a an option element exists on the current page with the specified
|
||||||
# text. You can optionally restrict the search to a specific select list by
|
# text. You can optionally restrict the search to a specific select list by
|
||||||
# assigning <tt>options[:from]</tt> the value of the select list's name or
|
# assigning <tt>options[:from]</tt> the value of the select list's name or
|
||||||
@ -111,7 +111,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
webrat_deprecate :selects, :select
|
webrat_deprecate :selects, :select
|
||||||
|
|
||||||
DATE_TIME_SUFFIXES = {
|
DATE_TIME_SUFFIXES = {
|
||||||
:year => '1i',
|
:year => '1i',
|
||||||
:month => '2i',
|
:month => '2i',
|
||||||
@ -120,9 +120,9 @@ module Webrat
|
|||||||
:minute => '5i'
|
:minute => '5i'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Verifies that date elements (year, month, day) exist on the current page
|
# Verifies that date elements (year, month, day) exist on the current page
|
||||||
# with the specified values. You can optionally restrict the search to a specific
|
# with the specified values. You can optionally restrict the search to a specific
|
||||||
# date's elements by assigning <tt>options[:from]</tt> the value of the date's
|
# date's elements by assigning <tt>options[:from]</tt> the value of the date's
|
||||||
# label. Selects all the date elements with date provided. The date provided may
|
# label. Selects all the date elements with date provided. The date provided may
|
||||||
# be a string or a Date/Time object.
|
# be a string or a Date/Time object.
|
||||||
#
|
#
|
||||||
@ -136,15 +136,15 @@ module Webrat
|
|||||||
# select_date Date.parse("December 25, 2000"), :from => "Event"
|
# select_date Date.parse("December 25, 2000"), :from => "Event"
|
||||||
# select_date "April 26, 1982", :id_prefix => 'birthday'
|
# select_date "April 26, 1982", :id_prefix => 'birthday'
|
||||||
def select_date(date_to_select, options ={})
|
def select_date(date_to_select, options ={})
|
||||||
date = date_to_select.is_a?(Date) || date_to_select.is_a?(Time) ?
|
date = date_to_select.is_a?(Date) || date_to_select.is_a?(Time) ?
|
||||||
date_to_select : Date.parse(date_to_select)
|
date_to_select : Date.parse(date_to_select)
|
||||||
|
|
||||||
id_prefix = locate_id_prefix(options) do
|
id_prefix = locate_id_prefix(options) do
|
||||||
year_field = FieldByIdLocator.new(@session, dom, /(.*?)_#{DATE_TIME_SUFFIXES[:year]}$/).locate
|
year_field = FieldByIdLocator.new(@session, dom, /(.*?)_#{DATE_TIME_SUFFIXES[:year]}$/).locate
|
||||||
raise NotFoundError.new("No date fields were found") unless year_field && year_field.id =~ /(.*?)_1i/
|
raise NotFoundError.new("No date fields were found") unless year_field && year_field.id =~ /(.*?)_1i/
|
||||||
$1
|
$1
|
||||||
end
|
end
|
||||||
|
|
||||||
select date.year, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:year]}"
|
select date.year, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:year]}"
|
||||||
select date.strftime('%B'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:month]}"
|
select date.strftime('%B'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:month]}"
|
||||||
select date.day, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:day]}"
|
select date.day, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:day]}"
|
||||||
@ -152,9 +152,9 @@ module Webrat
|
|||||||
|
|
||||||
webrat_deprecate :selects_date, :select_date
|
webrat_deprecate :selects_date, :select_date
|
||||||
|
|
||||||
# Verifies that time elements (hour, minute) exist on the current page
|
# Verifies that time elements (hour, minute) exist on the current page
|
||||||
# with the specified values. You can optionally restrict the search to a specific
|
# with the specified values. You can optionally restrict the search to a specific
|
||||||
# time's elements by assigning <tt>options[:from]</tt> the value of the time's
|
# time's elements by assigning <tt>options[:from]</tt> the value of the time's
|
||||||
# label. Selects all the time elements with date provided. The time provided may
|
# label. Selects all the time elements with date provided. The time provided may
|
||||||
# be a string or a Time object.
|
# be a string or a Time object.
|
||||||
#
|
#
|
||||||
@ -164,28 +164,28 @@ module Webrat
|
|||||||
#
|
#
|
||||||
# Note: Just like Rails' time_select helper this assumes the form is using
|
# Note: Just like Rails' time_select helper this assumes the form is using
|
||||||
# 24 hour select boxes, and not 12 hours with AM/PM.
|
# 24 hour select boxes, and not 12 hours with AM/PM.
|
||||||
#
|
#
|
||||||
# Examples:
|
# Examples:
|
||||||
# select_time "9:30"
|
# select_time "9:30"
|
||||||
# select_date "3:30PM", :from => "Party Time"
|
# select_date "3:30PM", :from => "Party Time"
|
||||||
# select_date Time.parse("10:00PM"), :from => "Event"
|
# select_date Time.parse("10:00PM"), :from => "Event"
|
||||||
# select_date "10:30AM", :id_prefix => 'meeting'
|
# select_date "10:30AM", :id_prefix => 'meeting'
|
||||||
def select_time(time_to_select, options ={})
|
def select_time(time_to_select, options ={})
|
||||||
time = time_to_select.is_a?(Time) ? time_to_select : Time.parse(time_to_select)
|
time = time_to_select.is_a?(Time) ? time_to_select : Time.parse(time_to_select)
|
||||||
|
|
||||||
id_prefix = locate_id_prefix(options) do
|
id_prefix = locate_id_prefix(options) do
|
||||||
hour_field = FieldByIdLocator.new(@session, dom, /(.*?)_#{DATE_TIME_SUFFIXES[:hour]}$/).locate
|
hour_field = FieldByIdLocator.new(@session, dom, /(.*?)_#{DATE_TIME_SUFFIXES[:hour]}$/).locate
|
||||||
raise NotFoundError.new("No time fields were found") unless hour_field && hour_field.id =~ /(.*?)_4i/
|
raise NotFoundError.new("No time fields were found") unless hour_field && hour_field.id =~ /(.*?)_4i/
|
||||||
$1
|
$1
|
||||||
end
|
end
|
||||||
|
|
||||||
select time.hour.to_s.rjust(2,'0'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:hour]}"
|
select time.hour.to_s.rjust(2,'0'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:hour]}"
|
||||||
select time.min.to_s.rjust(2,'0'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:minute]}"
|
select time.min.to_s.rjust(2,'0'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:minute]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
webrat_deprecate :selects_time, :select_time
|
webrat_deprecate :selects_time, :select_time
|
||||||
|
|
||||||
# Verifies and selects all the date and time elements on the current page.
|
# Verifies and selects all the date and time elements on the current page.
|
||||||
# See #select_time and #select_date for more details and available options.
|
# See #select_time and #select_date for more details and available options.
|
||||||
#
|
#
|
||||||
# Examples:
|
# Examples:
|
||||||
@ -194,16 +194,16 @@ module Webrat
|
|||||||
# select_datetime Time.parse("December 25, 2000 15:30"), :from => "Event"
|
# select_datetime Time.parse("December 25, 2000 15:30"), :from => "Event"
|
||||||
# select_datetime "April 26, 1982 5:50PM", :id_prefix => 'birthday'
|
# select_datetime "April 26, 1982 5:50PM", :id_prefix => 'birthday'
|
||||||
def select_datetime(time_to_select, options ={})
|
def select_datetime(time_to_select, options ={})
|
||||||
time = time_to_select.is_a?(Time) ? time_to_select : Time.parse(time_to_select)
|
time = time_to_select.is_a?(Time) ? time_to_select : Time.parse(time_to_select)
|
||||||
|
|
||||||
options[:id_prefix] ||= (options[:from] ? FieldByIdLocator.new(@session, dom, options[:from]).locate : nil)
|
options[:id_prefix] ||= (options[:from] ? FieldByIdLocator.new(@session, dom, options[:from]).locate : nil)
|
||||||
|
|
||||||
select_date time, options
|
select_date time, options
|
||||||
select_time time, options
|
select_time time, options
|
||||||
end
|
end
|
||||||
|
|
||||||
webrat_deprecate :selects_datetime, :select_datetime
|
webrat_deprecate :selects_datetime, :select_datetime
|
||||||
|
|
||||||
# Verifies that an input file field exists on the current page and sets
|
# Verifies that an input file field exists on the current page and sets
|
||||||
# its value to the given +file+, so that the file will be uploaded
|
# its value to the given +file+, so that the file will be uploaded
|
||||||
# along with the form. An optional <tt>content_type</tt> may be given.
|
# along with the form. An optional <tt>content_type</tt> may be given.
|
||||||
@ -229,13 +229,13 @@ module Webrat
|
|||||||
def click_area(area_name)
|
def click_area(area_name)
|
||||||
find_area(area_name).click
|
find_area(area_name).click
|
||||||
end
|
end
|
||||||
|
|
||||||
webrat_deprecate :clicks_area, :click_area
|
webrat_deprecate :clicks_area, :click_area
|
||||||
|
|
||||||
# Issues a request for the URL pointed to by a link on the current page,
|
# Issues a request for the URL pointed to by a link on the current page,
|
||||||
# follows any redirects, and verifies the final page load was successful.
|
# follows any redirects, and verifies the final page load was successful.
|
||||||
#
|
#
|
||||||
# click_link has very basic support for detecting Rails-generated
|
# click_link has very basic support for detecting Rails-generated
|
||||||
# JavaScript onclick handlers for PUT, POST and DELETE links, as well as
|
# JavaScript onclick handlers for PUT, POST and DELETE links, as well as
|
||||||
# CSRF authenticity tokens if they are present.
|
# CSRF authenticity tokens if they are present.
|
||||||
#
|
#
|
||||||
@ -243,15 +243,15 @@ module Webrat
|
|||||||
#
|
#
|
||||||
# Passing a :method in the options hash overrides the HTTP method used
|
# Passing a :method in the options hash overrides the HTTP method used
|
||||||
# for making the link request
|
# for making the link request
|
||||||
#
|
#
|
||||||
# It will try to find links by (in order of precedence):
|
# It will try to find links by (in order of precedence):
|
||||||
# innerHTML, with simple handling
|
# innerHTML, with simple handling
|
||||||
# title
|
# title
|
||||||
# id
|
# id
|
||||||
#
|
#
|
||||||
# innerHTML and title are matchable by text subtring or Regexp
|
# innerHTML and title are matchable by text subtring or Regexp
|
||||||
# id is matchable by full text equality or Regexp
|
# id is matchable by full text equality or Regexp
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
# click_link "Sign up"
|
# click_link "Sign up"
|
||||||
# click_link "Sign up", :javascript => false
|
# click_link "Sign up", :javascript => false
|
||||||
@ -261,7 +261,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
webrat_deprecate :clicks_link, :click_link
|
webrat_deprecate :clicks_link, :click_link
|
||||||
|
|
||||||
# Verifies that a submit button exists for the form, then submits the form, follows
|
# Verifies that a submit button exists for the form, then submits the form, follows
|
||||||
# any redirects, and verifies the final page was successful.
|
# any redirects, and verifies the final page was successful.
|
||||||
#
|
#
|
||||||
@ -288,38 +288,38 @@ module Webrat
|
|||||||
def submit_form(id)
|
def submit_form(id)
|
||||||
FormLocator.new(@session, dom, id).locate.submit
|
FormLocator.new(@session, dom, id).locate.submit
|
||||||
end
|
end
|
||||||
|
|
||||||
def dom # :nodoc:
|
def dom # :nodoc:
|
||||||
return @dom if @dom
|
return @dom if @dom
|
||||||
|
|
||||||
if @selector
|
if @selector
|
||||||
@dom = scoped_dom
|
@dom = scoped_dom
|
||||||
else
|
else
|
||||||
@dom = page_dom
|
@dom = page_dom
|
||||||
end
|
end
|
||||||
|
|
||||||
return @dom
|
return @dom
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def page_dom #:nodoc:
|
def page_dom #:nodoc:
|
||||||
return @response.dom if @response.respond_to?(:dom)
|
return @response.dom if @response.respond_to?(:dom)
|
||||||
|
|
||||||
if @session.xml_content_type?
|
if @session.xml_content_type?
|
||||||
dom = Webrat::XML.xml_document(@response_body)
|
dom = Webrat::XML.xml_document(@response_body)
|
||||||
else
|
else
|
||||||
dom = Webrat::XML.html_document(@response_body)
|
dom = Webrat::XML.html_document(@response_body)
|
||||||
end
|
end
|
||||||
|
|
||||||
Webrat.define_dom_method(@response, dom)
|
Webrat.define_dom_method(@response, dom)
|
||||||
return dom
|
return dom
|
||||||
end
|
end
|
||||||
|
|
||||||
def scoped_dom
|
def scoped_dom
|
||||||
Webrat::XML.css_at(@scope.dom, @selector)
|
Webrat::XML.css_at(@scope.dom, @selector)
|
||||||
end
|
end
|
||||||
|
|
||||||
def locate_field(field_locator, *field_types) #:nodoc:
|
def locate_field(field_locator, *field_types) #:nodoc:
|
||||||
if field_locator.is_a?(Field)
|
if field_locator.is_a?(Field)
|
||||||
field_locator
|
field_locator
|
||||||
@ -327,10 +327,10 @@ module Webrat
|
|||||||
field(field_locator, *field_types)
|
field(field_locator, *field_types)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def locate_id_prefix(options, &location_strategy) #:nodoc:
|
def locate_id_prefix(options, &location_strategy) #:nodoc:
|
||||||
return options[:id_prefix] if options[:id_prefix]
|
return options[:id_prefix] if options[:id_prefix]
|
||||||
|
|
||||||
if options[:from]
|
if options[:from]
|
||||||
if (label = LabelLocator.new(@session, dom, options[:from]).locate)
|
if (label = LabelLocator.new(@session, dom, options[:from]).locate)
|
||||||
label.for_id
|
label.for_id
|
||||||
@ -341,10 +341,10 @@ module Webrat
|
|||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def forms #:nodoc:
|
def forms #:nodoc:
|
||||||
@forms ||= Form.load_all(@session, dom)
|
@forms ||= Form.load_all(@session, dom)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,7 +11,7 @@ module Webrat
|
|||||||
|
|
||||||
class InfiniteRedirectError < WebratError
|
class InfiniteRedirectError < WebratError
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.session_class
|
def self.session_class
|
||||||
case Webrat.configuration.mode
|
case Webrat.configuration.mode
|
||||||
when :rails
|
when :rails
|
||||||
@ -77,7 +77,7 @@ For example:
|
|||||||
def doc_root #:nodoc:
|
def doc_root #:nodoc:
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def header(key, value)
|
def header(key, value)
|
||||||
@custom_headers[key] = value
|
@custom_headers[key] = value
|
||||||
end
|
end
|
||||||
@ -122,13 +122,13 @@ For example:
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_for_infinite_redirects
|
def check_for_infinite_redirects
|
||||||
if current_url == response_location
|
if current_url == response_location
|
||||||
@_identical_redirect_count ||= 0
|
@_identical_redirect_count ||= 0
|
||||||
@_identical_redirect_count += 1
|
@_identical_redirect_count += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if infinite_redirect_limit_exceeded?
|
if infinite_redirect_limit_exceeded?
|
||||||
raise InfiniteRedirectError.new("#{Webrat.configuration.infinite_redirect_limit} redirects to the same URL (#{current_url.inspect})")
|
raise InfiniteRedirectError.new("#{Webrat.configuration.infinite_redirect_limit} redirects to the same URL (#{current_url.inspect})")
|
||||||
end
|
end
|
||||||
@ -138,7 +138,7 @@ For example:
|
|||||||
Webrat.configuration.infinite_redirect_limit &&
|
Webrat.configuration.infinite_redirect_limit &&
|
||||||
(@_identical_redirect_count || 0) > Webrat.configuration.infinite_redirect_limit
|
(@_identical_redirect_count || 0) > Webrat.configuration.infinite_redirect_limit
|
||||||
end
|
end
|
||||||
|
|
||||||
def success_code? #:nodoc:
|
def success_code? #:nodoc:
|
||||||
(200..499).include?(response_code)
|
(200..499).include?(response_code)
|
||||||
end
|
end
|
||||||
@ -154,7 +154,7 @@ For example:
|
|||||||
response_location_host_domain = response_location_host.split('.')[-2..-1].join('.') rescue response_location_host
|
response_location_host_domain = response_location_host.split('.')[-2..-1].join('.') rescue response_location_host
|
||||||
current_host_domain == response_location_host_domain
|
current_host_domain == response_location_host_domain
|
||||||
end
|
end
|
||||||
|
|
||||||
#easy helper to pull out where we were redirected to
|
#easy helper to pull out where we were redirected to
|
||||||
def redirected_to
|
def redirected_to
|
||||||
redirect? ? response_location : nil
|
redirect? ? response_location : nil
|
||||||
@ -276,6 +276,6 @@ For example:
|
|||||||
@_scopes = nil
|
@_scopes = nil
|
||||||
@_page_scope = nil
|
@_page_scope = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,7 +4,7 @@ require "webrat/core/xml/rexml"
|
|||||||
|
|
||||||
module Webrat #:nodoc:
|
module Webrat #:nodoc:
|
||||||
module XML #:nodoc:
|
module XML #:nodoc:
|
||||||
|
|
||||||
def self.document(stringlike) #:nodoc:
|
def self.document(stringlike) #:nodoc:
|
||||||
if Webrat.configuration.parse_with_nokogiri?
|
if Webrat.configuration.parse_with_nokogiri?
|
||||||
Webrat.nokogiri_document(stringlike)
|
Webrat.nokogiri_document(stringlike)
|
||||||
@ -12,7 +12,7 @@ module Webrat #:nodoc:
|
|||||||
Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
|
Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.html_document(stringlike) #:nodoc:
|
def self.html_document(stringlike) #:nodoc:
|
||||||
if Webrat.configuration.parse_with_nokogiri?
|
if Webrat.configuration.parse_with_nokogiri?
|
||||||
Webrat.html_nokogiri_document(stringlike)
|
Webrat.html_nokogiri_document(stringlike)
|
||||||
@ -20,7 +20,7 @@ module Webrat #:nodoc:
|
|||||||
Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
|
Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.xml_document(stringlike) #:nodoc:
|
def self.xml_document(stringlike) #:nodoc:
|
||||||
if Webrat.configuration.parse_with_nokogiri?
|
if Webrat.configuration.parse_with_nokogiri?
|
||||||
Webrat.xml_nokogiri_document(stringlike)
|
Webrat.xml_nokogiri_document(stringlike)
|
||||||
@ -36,7 +36,7 @@ module Webrat #:nodoc:
|
|||||||
element.to_s
|
element.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.inner_html(element)
|
def self.inner_html(element)
|
||||||
if Webrat.configuration.parse_with_nokogiri?
|
if Webrat.configuration.parse_with_nokogiri?
|
||||||
element.inner_html
|
element.inner_html
|
||||||
@ -44,7 +44,7 @@ module Webrat #:nodoc:
|
|||||||
element.text
|
element.text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.all_inner_text(element)
|
def self.all_inner_text(element)
|
||||||
if Webrat.configuration.parse_with_nokogiri?
|
if Webrat.configuration.parse_with_nokogiri?
|
||||||
element.inner_text
|
element.inner_text
|
||||||
@ -52,7 +52,7 @@ module Webrat #:nodoc:
|
|||||||
Hpricot(element.to_s).children.first.inner_text
|
Hpricot(element.to_s).children.first.inner_text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.inner_text(element)
|
def self.inner_text(element)
|
||||||
if Webrat.configuration.parse_with_nokogiri?
|
if Webrat.configuration.parse_with_nokogiri?
|
||||||
element.inner_text
|
element.inner_text
|
||||||
@ -64,7 +64,7 @@ module Webrat #:nodoc:
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.xpath_to(element)
|
def self.xpath_to(element)
|
||||||
if Webrat.configuration.parse_with_nokogiri?
|
if Webrat.configuration.parse_with_nokogiri?
|
||||||
element.path
|
element.path
|
||||||
@ -72,25 +72,25 @@ module Webrat #:nodoc:
|
|||||||
element.xpath
|
element.xpath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.attribute(element, attribute_name)
|
def self.attribute(element, attribute_name)
|
||||||
return element[attribute_name] if element.is_a?(Hash)
|
return element[attribute_name] if element.is_a?(Hash)
|
||||||
|
|
||||||
if Webrat.configuration.parse_with_nokogiri?
|
if Webrat.configuration.parse_with_nokogiri?
|
||||||
element[attribute_name]
|
element[attribute_name]
|
||||||
else
|
else
|
||||||
element.attributes[attribute_name]
|
element.attributes[attribute_name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.xpath_at(*args)
|
def self.xpath_at(*args)
|
||||||
xpath_search(*args).first
|
xpath_search(*args).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.css_at(*args)
|
def self.css_at(*args)
|
||||||
css_search(*args).first
|
css_search(*args).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.xpath_search(element, *searches)
|
def self.xpath_search(element, *searches)
|
||||||
searches.flatten.map do |search|
|
searches.flatten.map do |search|
|
||||||
if Webrat.configuration.parse_with_nokogiri?
|
if Webrat.configuration.parse_with_nokogiri?
|
||||||
@ -100,16 +100,16 @@ module Webrat #:nodoc:
|
|||||||
end
|
end
|
||||||
end.flatten.compact
|
end.flatten.compact
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.css_search(element, *searches) #:nodoc:
|
def self.css_search(element, *searches) #:nodoc:
|
||||||
xpath_search(element, css_to_xpath(*searches))
|
xpath_search(element, css_to_xpath(*searches))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.css_to_xpath(*selectors)
|
def self.css_to_xpath(*selectors)
|
||||||
selectors.map do |rule|
|
selectors.map do |rule|
|
||||||
Nokogiri::CSS.xpath_for(rule, :prefix => ".//")
|
Nokogiri::CSS.xpath_for(rule, :prefix => ".//")
|
||||||
end.flatten.uniq
|
end.flatten.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
|
|
||||||
def self.hpricot_document(stringlike)
|
def self.hpricot_document(stringlike)
|
||||||
return stringlike.dom if stringlike.respond_to?(:dom)
|
return stringlike.dom if stringlike.respond_to?(:dom)
|
||||||
|
|
||||||
@ -15,5 +15,5 @@ module Webrat
|
|||||||
Hpricot(stringlike.to_s)
|
Hpricot(stringlike.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
require "webrat/core_extensions/meta_class"
|
require "webrat/core_extensions/meta_class"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
|
|
||||||
def self.nokogiri_document(stringlike) #:nodoc:
|
def self.nokogiri_document(stringlike) #:nodoc:
|
||||||
return stringlike.dom if stringlike.respond_to?(:dom)
|
return stringlike.dom if stringlike.respond_to?(:dom)
|
||||||
|
|
||||||
if Nokogiri::HTML::Document === stringlike
|
if Nokogiri::HTML::Document === stringlike
|
||||||
stringlike
|
stringlike
|
||||||
elsif Nokogiri::XML::NodeSet === stringlike
|
elsif Nokogiri::XML::NodeSet === stringlike
|
||||||
@ -17,10 +17,10 @@ module Webrat
|
|||||||
Nokogiri::HTML(stringlike.to_s)
|
Nokogiri::HTML(stringlike.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.html_nokogiri_document(stringlike) #:nodoc:
|
def self.html_nokogiri_document(stringlike) #:nodoc:
|
||||||
return stringlike.dom if stringlike.respond_to?(:dom)
|
return stringlike.dom if stringlike.respond_to?(:dom)
|
||||||
|
|
||||||
if Nokogiri::HTML::Document === stringlike
|
if Nokogiri::HTML::Document === stringlike
|
||||||
stringlike
|
stringlike
|
||||||
elsif Nokogiri::XML::NodeSet === stringlike
|
elsif Nokogiri::XML::NodeSet === stringlike
|
||||||
@ -33,10 +33,10 @@ module Webrat
|
|||||||
Nokogiri::HTML(stringlike.to_s)
|
Nokogiri::HTML(stringlike.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.xml_nokogiri_document(stringlike) #:nodoc:
|
def self.xml_nokogiri_document(stringlike) #:nodoc:
|
||||||
return stringlike.dom if stringlike.respond_to?(:dom)
|
return stringlike.dom if stringlike.respond_to?(:dom)
|
||||||
|
|
||||||
if Nokogiri::HTML::Document === stringlike
|
if Nokogiri::HTML::Document === stringlike
|
||||||
stringlike
|
stringlike
|
||||||
elsif Nokogiri::XML::NodeSet === stringlike
|
elsif Nokogiri::XML::NodeSet === stringlike
|
||||||
@ -49,20 +49,20 @@ module Webrat
|
|||||||
Nokogiri::XML(stringlike.to_s)
|
Nokogiri::XML(stringlike.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.define_dom_method(object, dom) #:nodoc:
|
def self.define_dom_method(object, dom) #:nodoc:
|
||||||
object.meta_class.send(:define_method, :dom) do
|
object.meta_class.send(:define_method, :dom) do
|
||||||
dom
|
dom
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
module Nokogiri #:nodoc:
|
module Nokogiri #:nodoc:
|
||||||
module CSS #:nodoc:
|
module CSS #:nodoc:
|
||||||
class XPathVisitor #:nodoc:
|
class XPathVisitor #:nodoc:
|
||||||
|
|
||||||
def visit_pseudo_class_text(node) #:nodoc:
|
def visit_pseudo_class_text(node) #:nodoc:
|
||||||
"@type='text'"
|
"@type='text'"
|
||||||
end
|
end
|
||||||
@ -70,7 +70,7 @@ module Nokogiri #:nodoc:
|
|||||||
def visit_pseudo_class_password(node) #:nodoc:
|
def visit_pseudo_class_password(node) #:nodoc:
|
||||||
"@type='password'"
|
"@type='password'"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
|
|
||||||
def self.rexml_document(stringlike)
|
def self.rexml_document(stringlike)
|
||||||
stringlike = stringlike.body.to_s if stringlike.respond_to?(:body)
|
stringlike = stringlike.body.to_s if stringlike.respond_to?(:body)
|
||||||
|
|
||||||
@ -20,5 +20,5 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,7 @@ class Object #:nodoc:
|
|||||||
def blank?
|
def blank?
|
||||||
respond_to?(:empty?) ? empty? : !self
|
respond_to?(:empty?) ? empty? : !self
|
||||||
end
|
end
|
||||||
|
|
||||||
# An object is present if it's not blank.
|
# An object is present if it's not blank.
|
||||||
def present?
|
def present?
|
||||||
!blank?
|
!blank?
|
||||||
|
@ -5,4 +5,4 @@ class Module #:nodoc:
|
|||||||
__send__(new_method_name, *args)
|
__send__(new_method_name, *args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
class Array #:nodoc:
|
class Array #:nodoc:
|
||||||
|
|
||||||
def detect_mapped
|
def detect_mapped
|
||||||
each do |element|
|
each do |element|
|
||||||
result = yield element
|
result = yield element
|
||||||
return result if result
|
return result if result
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -3,4 +3,4 @@ class ::Object #:nodoc:
|
|||||||
class << self; self end
|
class << self; self end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
class TCPSocket
|
class TCPSocket
|
||||||
|
|
||||||
def self.wait_for_service_with_timeout(options)
|
def self.wait_for_service_with_timeout(options)
|
||||||
start_time = Time.now
|
start_time = Time.now
|
||||||
|
|
||||||
until listening_service?(options)
|
until listening_service?(options)
|
||||||
verbose_wait
|
verbose_wait
|
||||||
|
|
||||||
if options[:timeout] && (Time.now > start_time + options[:timeout])
|
if options[:timeout] && (Time.now > start_time + options[:timeout])
|
||||||
raise SocketError.new("Socket did not open within #{options[:timeout]} seconds")
|
raise SocketError.new("Socket did not open within #{options[:timeout]} seconds")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.wait_for_service_termination_with_timeout(options)
|
def self.wait_for_service_termination_with_timeout(options)
|
||||||
start_time = Time.now
|
start_time = Time.now
|
||||||
|
|
||||||
while listening_service?(options)
|
while listening_service?(options)
|
||||||
verbose_wait
|
verbose_wait
|
||||||
|
|
||||||
if options[:timeout] && (Time.now > start_time + options[:timeout])
|
if options[:timeout] && (Time.now > start_time + options[:timeout])
|
||||||
raise SocketError.new("Socket did not terminate within #{options[:timeout]} seconds")
|
raise SocketError.new("Socket did not terminate within #{options[:timeout]} seconds")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -2,14 +2,14 @@ require "mechanize"
|
|||||||
|
|
||||||
module Webrat #:nodoc:
|
module Webrat #:nodoc:
|
||||||
class MechanizeSession < Session #:nodoc:
|
class MechanizeSession < Session #:nodoc:
|
||||||
|
|
||||||
attr_accessor :response
|
attr_accessor :response
|
||||||
alias :page :response
|
alias :page :response
|
||||||
|
|
||||||
def request_page(url, http_method, data) #:nodoc:
|
def request_page(url, http_method, data) #:nodoc:
|
||||||
super(absolute_url(url), http_method, data)
|
super(absolute_url(url), http_method, data)
|
||||||
end
|
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
|
||||||
@ -26,7 +26,7 @@ module Webrat #:nodoc:
|
|||||||
end
|
end
|
||||||
@response = mechanize.post(url, post_data)
|
@response = mechanize.post(url, post_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def response_body
|
def response_body
|
||||||
@response.content
|
@response.content
|
||||||
end
|
end
|
||||||
@ -34,13 +34,13 @@ module Webrat #:nodoc:
|
|||||||
def response_code
|
def response_code
|
||||||
@response.code.to_i
|
@response.code.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def mechanize
|
def mechanize
|
||||||
@mechanize ||= WWW::Mechanize.new
|
@mechanize ||= WWW::Mechanize.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def_delegators :mechanize, :basic_auth
|
def_delegators :mechanize, :basic_auth
|
||||||
|
|
||||||
def absolute_url(url) #:nodoc:
|
def absolute_url(url) #:nodoc:
|
||||||
current_host, current_path = split_current_url
|
current_host, current_path = split_current_url
|
||||||
if url =~ Regexp.new('^https?://')
|
if url =~ Regexp.new('^https?://')
|
||||||
@ -53,13 +53,13 @@ module Webrat #:nodoc:
|
|||||||
url
|
url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def split_current_url
|
def split_current_url
|
||||||
current_url =~ Regexp.new('^(https?://[^/]+)(/.*)?')
|
current_url =~ Regexp.new('^(https?://[^/]+)(/.*)?')
|
||||||
[Regexp.last_match(1), Regexp.last_match(2)]
|
[Regexp.last_match(1), Regexp.last_match(2)]
|
||||||
end
|
end
|
||||||
|
|
||||||
def absolute_path(current_path, url)
|
def absolute_path(current_path, url)
|
||||||
levels_up = url.split('/').find_all { |x| x == '..' }.size
|
levels_up = url.split('/').find_all { |x| x == '..' }.size
|
||||||
ancestor = if current_path.nil?
|
ancestor = if current_path.nil?
|
||||||
|
@ -6,4 +6,4 @@ require "webrat"
|
|||||||
|
|
||||||
Webrat.configure do |config|
|
Webrat.configure do |config|
|
||||||
config.mode = :merb
|
config.mode = :merb
|
||||||
end
|
end
|
||||||
|
@ -10,36 +10,36 @@ require "merb-core"
|
|||||||
module Webrat
|
module Webrat
|
||||||
class MerbSession < Session #:nodoc:
|
class MerbSession < Session #:nodoc:
|
||||||
include Merb::Test::MakeRequest
|
include Merb::Test::MakeRequest
|
||||||
|
|
||||||
attr_accessor :response
|
attr_accessor :response
|
||||||
|
|
||||||
def get(url, data, headers = nil)
|
def get(url, data, headers = nil)
|
||||||
do_request(url, data, headers, "GET")
|
do_request(url, data, headers, "GET")
|
||||||
end
|
end
|
||||||
|
|
||||||
def post(url, data, headers = nil)
|
def post(url, data, headers = nil)
|
||||||
do_request(url, data, headers, "POST")
|
do_request(url, data, headers, "POST")
|
||||||
end
|
end
|
||||||
|
|
||||||
def put(url, data, headers = nil)
|
def put(url, data, headers = nil)
|
||||||
do_request(url, data, headers, "PUT")
|
do_request(url, data, headers, "PUT")
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(url, data, headers = nil)
|
def delete(url, data, headers = nil)
|
||||||
do_request(url, data, headers, "DELETE")
|
do_request(url, data, headers, "DELETE")
|
||||||
end
|
end
|
||||||
|
|
||||||
def response_body
|
def response_body
|
||||||
@response.body.to_s
|
@response.body.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def response_code
|
def response_code
|
||||||
@response.status
|
@response.status
|
||||||
end
|
end
|
||||||
|
|
||||||
def do_request(url, data, headers, method)
|
def do_request(url, data, headers, method)
|
||||||
@response = request(url,
|
@response = request(url,
|
||||||
:params => (data && data.any?) ? data : nil,
|
:params => (data && data.any?) ? data : nil,
|
||||||
:headers => headers,
|
:headers => headers,
|
||||||
:method => method)
|
:method => method)
|
||||||
end
|
end
|
||||||
|
@ -7,7 +7,7 @@ require "action_controller/record_identifier"
|
|||||||
module Webrat
|
module Webrat
|
||||||
class RailsSession < Session #:nodoc:
|
class RailsSession < Session #:nodoc:
|
||||||
include ActionController::RecordIdentifier
|
include ActionController::RecordIdentifier
|
||||||
|
|
||||||
# The Rails version of within supports passing in a model and Webrat
|
# The Rails version of within supports passing in a model and Webrat
|
||||||
# will apply a scope based on Rails' dom_id for that model.
|
# will apply a scope based on Rails' dom_id for that model.
|
||||||
#
|
#
|
||||||
@ -22,7 +22,7 @@ module Webrat
|
|||||||
super('#' + dom_id(selector_or_object), &block)
|
super('#' + dom_id(selector_or_object), &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def doc_root
|
def doc_root
|
||||||
File.expand_path(File.join(RAILS_ROOT, 'public'))
|
File.expand_path(File.join(RAILS_ROOT, 'public'))
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Supports using the matchers in controller, helper, and view specs if you're
|
# Supports using the matchers in controller, helper, and view specs if you're
|
||||||
# using rspec-rails. Just add a require statement to spec/spec_helper.rb or env.rb:
|
# using rspec-rails. Just add a require statement to spec/spec_helper.rb or env.rb:
|
||||||
#
|
#
|
||||||
# require 'webrat/rspec-rails'
|
# require 'webrat/rspec-rails'
|
||||||
#
|
#
|
||||||
require "webrat/core/matchers"
|
require "webrat/core/matchers"
|
||||||
@ -10,4 +10,4 @@ Spec::Runner.configure do |config|
|
|||||||
config.include(Webrat::Matchers, :type => :controller)
|
config.include(Webrat::Matchers, :type => :controller)
|
||||||
config.include(Webrat::Matchers, :type => :helper)
|
config.include(Webrat::Matchers, :type => :helper)
|
||||||
config.include(Webrat::Matchers, :type => :view)
|
config.include(Webrat::Matchers, :type => :view)
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
module Selenium
|
module Selenium
|
||||||
|
|
||||||
class ApplicationServer
|
class ApplicationServer
|
||||||
|
|
||||||
def self.boot
|
def self.boot
|
||||||
case Webrat.configuration.application_framework
|
case Webrat.configuration.application_framework
|
||||||
when :sinatra
|
when :sinatra
|
||||||
@ -30,25 +30,25 @@ For example:
|
|||||||
STR
|
STR
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def boot
|
def boot
|
||||||
start
|
start
|
||||||
wait
|
wait
|
||||||
stop_at_exit
|
stop_at_exit
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop_at_exit
|
def stop_at_exit
|
||||||
at_exit do
|
at_exit do
|
||||||
stop
|
stop
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def wait
|
def wait
|
||||||
$stderr.print "==> Waiting for #{Webrat.configuration.application_framework} application server on port #{Webrat.configuration.application_port}... "
|
$stderr.print "==> Waiting for #{Webrat.configuration.application_framework} application server on port #{Webrat.configuration.application_port}... "
|
||||||
wait_for_socket
|
wait_for_socket
|
||||||
$stderr.print "Ready!\n"
|
$stderr.print "Ready!\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def wait_for_socket
|
def wait_for_socket
|
||||||
silence_stream(STDOUT) do
|
silence_stream(STDOUT) do
|
||||||
TCPSocket.wait_for_service_with_timeout \
|
TCPSocket.wait_for_service_with_timeout \
|
||||||
@ -64,8 +64,8 @@ For example:
|
|||||||
FileUtils.mkdir_p File.expand_path(file_path)
|
FileUtils.mkdir_p File.expand_path(file_path)
|
||||||
File.expand_path("#{file_path}/#{pid_file_name}")
|
File.expand_path("#{file_path}/#{pid_file_name}")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
require "webrat/selenium/matchers/have_xpath"
|
require "webrat/selenium/matchers/have_xpath"
|
||||||
require "webrat/selenium/matchers/have_selector"
|
require "webrat/selenium/matchers/have_selector"
|
||||||
# require "webrat/selenium/matchers/have_tag"
|
# require "webrat/selenium/matchers/have_tag"
|
||||||
require "webrat/selenium/matchers/have_content"
|
require "webrat/selenium/matchers/have_content"
|
||||||
|
@ -5,14 +5,14 @@ module Webrat
|
|||||||
def initialize(content)
|
def initialize(content)
|
||||||
@content = content
|
@content = content
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches?(response)
|
def matches?(response)
|
||||||
if @content.is_a?(Regexp)
|
if @content.is_a?(Regexp)
|
||||||
text_finder = "regexp:#{@content.source}"
|
text_finder = "regexp:#{@content.source}"
|
||||||
else
|
else
|
||||||
text_finder = @content
|
text_finder = @content
|
||||||
end
|
end
|
||||||
|
|
||||||
response.session.wait_for do
|
response.session.wait_for do
|
||||||
response.selenium.is_text_present(text_finder)
|
response.selenium.is_text_present(text_finder)
|
||||||
end
|
end
|
||||||
@ -47,7 +47,7 @@ module Webrat
|
|||||||
def contain(content)
|
def contain(content)
|
||||||
HasContent.new(content)
|
HasContent.new(content)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Asserts that the body of the response contain
|
# Asserts that the body of the response contain
|
||||||
# the supplied string or regexp
|
# the supplied string or regexp
|
||||||
def assert_contain(content)
|
def assert_contain(content)
|
||||||
@ -63,4 +63,4 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ module Webrat
|
|||||||
def initialize(expected)
|
def initialize(expected)
|
||||||
@expected = expected
|
@expected = expected
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches?(response)
|
def matches?(response)
|
||||||
response.session.wait_for do
|
response.session.wait_for do
|
||||||
response.selenium.is_element_present("css=#{@expected}")
|
response.selenium.is_element_present("css=#{@expected}")
|
||||||
@ -26,11 +26,11 @@ module Webrat
|
|||||||
"expected following text to not match selector #{@expected}:\n#{@document}"
|
"expected following text to not match selector #{@expected}:\n#{@document}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def have_selector(content)
|
def have_selector(content)
|
||||||
HaveSelector.new(content)
|
HaveSelector.new(content)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Asserts that the body of the response contains
|
# Asserts that the body of the response contains
|
||||||
# the supplied selector
|
# the supplied selector
|
||||||
def assert_have_selector(expected)
|
def assert_have_selector(expected)
|
||||||
@ -46,4 +46,4 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,72 +1,72 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
module Selenium
|
module Selenium
|
||||||
module Matchers
|
module Matchers
|
||||||
|
|
||||||
class HaveTag < HaveSelector #:nodoc:
|
class HaveTag < HaveSelector #:nodoc:
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# String:: The failure message.
|
# String:: The failure message.
|
||||||
def failure_message
|
def failure_message
|
||||||
"expected following output to contain a #{tag_inspect} tag:\n#{@document}"
|
"expected following output to contain a #{tag_inspect} tag:\n#{@document}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# String:: The failure message to be displayed in negative matches.
|
# String:: The failure message to be displayed in negative matches.
|
||||||
def negative_failure_message
|
def negative_failure_message
|
||||||
"expected following output to omit a #{tag_inspect}:\n#{@document}"
|
"expected following output to omit a #{tag_inspect}:\n#{@document}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_inspect
|
def tag_inspect
|
||||||
options = @expected.last.dup
|
options = @expected.last.dup
|
||||||
content = options.delete(:content)
|
content = options.delete(:content)
|
||||||
|
|
||||||
html = "<#{@expected.first}"
|
html = "<#{@expected.first}"
|
||||||
options.each do |k,v|
|
options.each do |k,v|
|
||||||
html << " #{k}='#{v}'"
|
html << " #{k}='#{v}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
if content
|
if content
|
||||||
html << ">#{content}</#{@expected.first}>"
|
html << ">#{content}</#{@expected.first}>"
|
||||||
else
|
else
|
||||||
html << "/>"
|
html << "/>"
|
||||||
end
|
end
|
||||||
|
|
||||||
html
|
html
|
||||||
end
|
end
|
||||||
|
|
||||||
def query
|
def query
|
||||||
options = @expected.last.dup
|
options = @expected.last.dup
|
||||||
selector = @expected.first.to_s
|
selector = @expected.first.to_s
|
||||||
|
|
||||||
selector << ":contains('#{options.delete(:content)}')" if options[:content]
|
selector << ":contains('#{options.delete(:content)}')" if options[:content]
|
||||||
|
|
||||||
options.each do |key, value|
|
options.each do |key, value|
|
||||||
selector << "[#{key}='#{value}']"
|
selector << "[#{key}='#{value}']"
|
||||||
end
|
end
|
||||||
|
|
||||||
Nokogiri::CSS.parse(selector).map { |ast| ast.to_xpath }
|
Nokogiri::CSS.parse(selector).map { |ast| ast.to_xpath }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def have_tag(name, attributes = {}, &block)
|
def have_tag(name, attributes = {}, &block)
|
||||||
HaveTag.new([name, attributes], &block)
|
HaveTag.new([name, attributes], &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :match_tag, :have_tag
|
alias_method :match_tag, :have_tag
|
||||||
|
|
||||||
# Asserts that the body of the response contains
|
# Asserts that the body of the response contains
|
||||||
# the supplied tag with the associated selectors
|
# the supplied tag with the associated selectors
|
||||||
def assert_have_tag(name, attributes = {})
|
def assert_have_tag(name, attributes = {})
|
||||||
ht = HaveTag.new([name, attributes])
|
ht = HaveTag.new([name, attributes])
|
||||||
assert ht.matches?(response), ht.failure_message
|
assert ht.matches?(response), ht.failure_message
|
||||||
end
|
end
|
||||||
|
|
||||||
# Asserts that the body of the response
|
# Asserts that the body of the response
|
||||||
# does not contain the supplied string or regepx
|
# does not contain the supplied string or regepx
|
||||||
def assert_have_no_tag(name, attributes = {})
|
def assert_have_no_tag(name, attributes = {})
|
||||||
ht = HaveTag.new([name, attributes])
|
ht = HaveTag.new([name, attributes])
|
||||||
assert !ht.matches?(response), ht.negative_failure_message
|
assert !ht.matches?(response), ht.negative_failure_message
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ module Webrat
|
|||||||
def initialize(expected)
|
def initialize(expected)
|
||||||
@expected = expected
|
@expected = expected
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches?(response)
|
def matches?(response)
|
||||||
response.session.wait_for do
|
response.session.wait_for do
|
||||||
response.selenium.is_element_present("xpath=#{@expected}")
|
response.selenium.is_element_present("xpath=#{@expected}")
|
||||||
@ -26,11 +26,11 @@ module Webrat
|
|||||||
"expected following text to not match xpath #{@expected}:\n#{@document}"
|
"expected following text to not match xpath #{@expected}:\n#{@document}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def have_xpath(xpath)
|
def have_xpath(xpath)
|
||||||
HaveXpath.new(xpath)
|
HaveXpath.new(xpath)
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_have_xpath(expected)
|
def assert_have_xpath(expected)
|
||||||
hs = HaveXpath.new(expected)
|
hs = HaveXpath.new(expected)
|
||||||
assert hs.matches?(response), hs.failure_message
|
assert hs.matches?(response), hs.failure_message
|
||||||
@ -42,4 +42,4 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
module Selenium
|
module Selenium
|
||||||
|
|
||||||
class MerbApplicationServer < ApplicationServer
|
class MerbApplicationServer < ApplicationServer
|
||||||
|
|
||||||
def start
|
def start
|
||||||
system start_command
|
system start_command
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
silence_stream(STDOUT) do
|
silence_stream(STDOUT) do
|
||||||
pid = File.read(pid_file)
|
pid = File.read(pid_file)
|
||||||
@ -14,7 +14,7 @@ module Webrat
|
|||||||
FileUtils.rm_f pid_file
|
FileUtils.rm_f pid_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def fail
|
def fail
|
||||||
$stderr.puts
|
$stderr.puts
|
||||||
$stderr.puts
|
$stderr.puts
|
||||||
@ -25,11 +25,11 @@ module Webrat
|
|||||||
$stderr.puts " #{start_command}"
|
$stderr.puts " #{start_command}"
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
def pid_file
|
def pid_file
|
||||||
"log/merb.#{Webrat.configuration.application_port}.pid"
|
"log/merb.#{Webrat.configuration.application_port}.pid"
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_command
|
def start_command
|
||||||
"#{merb_command} -d -p #{Webrat.configuration.application_port} -e #{Webrat.configuration.application_environment}"
|
"#{merb_command} -d -p #{Webrat.configuration.application_port} -e #{Webrat.configuration.application_environment}"
|
||||||
end
|
end
|
||||||
@ -41,8 +41,8 @@ module Webrat
|
|||||||
merb_cmd = 'merb'
|
merb_cmd = 'merb'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
module Selenium
|
module Selenium
|
||||||
|
|
||||||
class RailsApplicationServer < ApplicationServer
|
class RailsApplicationServer < ApplicationServer
|
||||||
|
|
||||||
def start
|
def start
|
||||||
system start_command
|
system start_command
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
silence_stream(STDOUT) do
|
silence_stream(STDOUT) do
|
||||||
system stop_command
|
system stop_command
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def fail
|
def fail
|
||||||
$stderr.puts
|
$stderr.puts
|
||||||
$stderr.puts
|
$stderr.puts
|
||||||
@ -23,11 +23,11 @@ module Webrat
|
|||||||
$stderr.puts " #{start_command}"
|
$stderr.puts " #{start_command}"
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
def pid_file
|
def pid_file
|
||||||
prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium.pid")
|
prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium.pid")
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_command
|
def start_command
|
||||||
"mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &"
|
"mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &"
|
||||||
end
|
end
|
||||||
@ -35,8 +35,8 @@ module Webrat
|
|||||||
def stop_command
|
def stop_command
|
||||||
"mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
|
"mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,49 +1,49 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
module Selenium
|
module Selenium
|
||||||
|
|
||||||
class SeleniumRCServer
|
class SeleniumRCServer
|
||||||
|
|
||||||
def self.boot
|
def self.boot
|
||||||
new.boot
|
new.boot
|
||||||
end
|
end
|
||||||
|
|
||||||
def boot
|
def boot
|
||||||
return if selenium_grid?
|
return if selenium_grid?
|
||||||
|
|
||||||
start
|
start
|
||||||
wait
|
wait
|
||||||
stop_at_exit
|
stop_at_exit
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
silence_stream(STDOUT) do
|
silence_stream(STDOUT) do
|
||||||
remote_control.start :background => true
|
remote_control.start :background => true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop_at_exit
|
def stop_at_exit
|
||||||
at_exit do
|
at_exit do
|
||||||
stop
|
stop
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote_control
|
def remote_control
|
||||||
return @remote_control if @remote_control
|
return @remote_control if @remote_control
|
||||||
|
|
||||||
@remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5)
|
@remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5)
|
||||||
@remote_control.jar_file = jar_path
|
@remote_control.jar_file = jar_path
|
||||||
|
|
||||||
return @remote_control
|
return @remote_control
|
||||||
end
|
end
|
||||||
|
|
||||||
def jar_path
|
def jar_path
|
||||||
File.expand_path(__FILE__ + "../../../../../vendor/selenium-server.jar")
|
File.expand_path(__FILE__ + "../../../../../vendor/selenium-server.jar")
|
||||||
end
|
end
|
||||||
|
|
||||||
def selenium_grid?
|
def selenium_grid?
|
||||||
Webrat.configuration.selenium_server_address
|
Webrat.configuration.selenium_server_address
|
||||||
end
|
end
|
||||||
|
|
||||||
def wait
|
def wait
|
||||||
$stderr.print "==> Waiting for Selenium RC server on port #{Webrat.configuration.selenium_server_port}... "
|
$stderr.print "==> Waiting for Selenium RC server on port #{Webrat.configuration.selenium_server_port}... "
|
||||||
wait_for_socket
|
wait_for_socket
|
||||||
@ -51,7 +51,7 @@ module Webrat
|
|||||||
rescue SocketError
|
rescue SocketError
|
||||||
fail
|
fail
|
||||||
end
|
end
|
||||||
|
|
||||||
def wait_for_socket
|
def wait_for_socket
|
||||||
silence_stream(STDOUT) do
|
silence_stream(STDOUT) do
|
||||||
TCPSocket.wait_for_service_with_timeout \
|
TCPSocket.wait_for_service_with_timeout \
|
||||||
@ -60,21 +60,21 @@ module Webrat
|
|||||||
:timeout => 15 # seconds
|
:timeout => 15 # seconds
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def fail
|
def fail
|
||||||
$stderr.puts
|
$stderr.puts
|
||||||
$stderr.puts
|
$stderr.puts
|
||||||
$stderr.puts "==> Failed to boot the Selenium RC server... exiting!"
|
$stderr.puts "==> Failed to boot the Selenium RC server... exiting!"
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
silence_stream(STDOUT) do
|
silence_stream(STDOUT) do
|
||||||
::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5).stop
|
::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5).stop
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -181,7 +181,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def silence_stream(stream)
|
def silence_stream(stream)
|
||||||
old_stream = stream.dup
|
old_stream = stream.dup
|
||||||
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
|
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
|
||||||
@ -208,7 +208,7 @@ module Webrat
|
|||||||
$browser = ::Selenium::Client::Driver.new(Webrat.configuration.selenium_server_address || "localhost",
|
$browser = ::Selenium::Client::Driver.new(Webrat.configuration.selenium_server_address || "localhost",
|
||||||
Webrat.configuration.selenium_server_port, Webrat.configuration.selenium_browser_key, "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port}")
|
Webrat.configuration.selenium_server_port, Webrat.configuration.selenium_browser_key, "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port}")
|
||||||
$browser.set_speed(0) unless Webrat.configuration.selenium_server_address
|
$browser.set_speed(0) unless Webrat.configuration.selenium_server_address
|
||||||
|
|
||||||
at_exit do
|
at_exit do
|
||||||
silence_stream(STDOUT) do
|
silence_stream(STDOUT) do
|
||||||
$browser.stop
|
$browser.stop
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
module Selenium
|
module Selenium
|
||||||
|
|
||||||
class SinatraApplicationServer < ApplicationServer
|
class SinatraApplicationServer < ApplicationServer
|
||||||
|
|
||||||
def start
|
def start
|
||||||
fork do
|
fork do
|
||||||
File.open('rack.pid', 'w') { |fp| fp.write Process.pid }
|
File.open('rack.pid', 'w') { |fp| fp.write Process.pid }
|
||||||
exec 'rackup', File.expand_path(Dir.pwd + '/config.ru'), '-p', Webrat.configuration.application_port.to_s
|
exec 'rackup', File.expand_path(Dir.pwd + '/config.ru'), '-p', Webrat.configuration.application_port.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
silence_stream(STDOUT) do
|
silence_stream(STDOUT) do
|
||||||
pid = File.read(pid_file)
|
pid = File.read(pid_file)
|
||||||
@ -17,19 +17,19 @@ module Webrat
|
|||||||
FileUtils.rm_f pid_file
|
FileUtils.rm_f pid_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def fail
|
def fail
|
||||||
$stderr.puts
|
$stderr.puts
|
||||||
$stderr.puts
|
$stderr.puts
|
||||||
$stderr.puts "==> Failed to boot the Sinatra application server... exiting!"
|
$stderr.puts "==> Failed to boot the Sinatra application server... exiting!"
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
def pid_file
|
def pid_file
|
||||||
prepare_pid_file(Dir.pwd, 'rack.pid')
|
prepare_pid_file(Dir.pwd, 'rack.pid')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -31,4 +31,4 @@ module Webrat #:nodoc:
|
|||||||
def delete(url, data, headers = nil)
|
def delete(url, data, headers = nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
class Application < Merb::Controller
|
class Application < Merb::Controller
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
class Exceptions < Merb::Controller
|
class Exceptions < Merb::Controller
|
||||||
|
|
||||||
# handle NotFound exceptions (404)
|
# handle NotFound exceptions (404)
|
||||||
def not_found
|
def not_found
|
||||||
render :format => :html
|
render :format => :html
|
||||||
@ -10,4 +10,4 @@ class Exceptions < Merb::Controller
|
|||||||
render :format => :html
|
render :format => :html
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
class Testing < Application
|
class Testing < Application
|
||||||
|
|
||||||
def show_form
|
def show_form
|
||||||
render
|
render
|
||||||
end
|
end
|
||||||
|
|
||||||
def submit_form
|
def submit_form
|
||||||
end
|
end
|
||||||
|
|
||||||
def internal_redirect
|
def internal_redirect
|
||||||
redirect "/"
|
redirect "/"
|
||||||
end
|
end
|
||||||
|
|
||||||
def external_redirect
|
def external_redirect
|
||||||
redirect "http://google.com"
|
redirect "http://google.com"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
# Go to http://wiki.merbivore.com/pages/init-rb
|
# Go to http://wiki.merbivore.com/pages/init-rb
|
||||||
|
|
||||||
# Specify a specific version of a dependency
|
# Specify a specific version of a dependency
|
||||||
# dependency "RedCloth", "> 3.0"
|
# dependency "RedCloth", "> 3.0"
|
||||||
|
|
||||||
# use_orm :none
|
# use_orm :none
|
||||||
use_test :rspec
|
use_test :rspec
|
||||||
use_template_engine :erb
|
use_template_engine :erb
|
||||||
|
|
||||||
Merb::Config.use do |c|
|
Merb::Config.use do |c|
|
||||||
c[:use_mutex] = false
|
c[:use_mutex] = false
|
||||||
c[:session_store] = 'cookie' # can also be 'memory', 'memcache', 'container', 'datamapper
|
c[:session_store] = 'cookie' # can also be 'memory', 'memcache', 'container', 'datamapper
|
||||||
|
|
||||||
# cookie session store configuration
|
# cookie session store configuration
|
||||||
c[:session_secret_key] = 'adb9ea7a0e94b5513503f58623a393c5efe18851' # required for cookie session store
|
c[:session_secret_key] = 'adb9ea7a0e94b5513503f58623a393c5efe18851' # required for cookie session store
|
||||||
c[:session_id_key] = '_merb_session_id' # cookie session id key, defaults to "_session_id"
|
c[:session_id_key] = '_merb_session_id' # cookie session id key, defaults to "_session_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
Merb::BootLoader.before_app_loads do
|
Merb::BootLoader.before_app_loads do
|
||||||
# This will get executed after dependencies have been loaded but before your app's classes have loaded.
|
# This will get executed after dependencies have been loaded but before your app's classes have loaded.
|
||||||
end
|
end
|
||||||
|
|
||||||
Merb::BootLoader.after_app_loads do
|
Merb::BootLoader.after_app_loads do
|
||||||
# This will get executed after your app's classes have been loaded.
|
# This will get executed after your app's classes have been loaded.
|
||||||
end
|
end
|
||||||
|
@ -8,4 +8,4 @@ end
|
|||||||
use Merb::Rack::Static, Merb.dir_for(:public)
|
use Merb::Rack::Static, Merb.dir_for(:public)
|
||||||
|
|
||||||
# this is our main merb application
|
# this is our main merb application
|
||||||
run Merb::Rack::Application.new
|
run Merb::Rack::Application.new
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# match("/books/:book_id/:action").
|
# match("/books/:book_id/:action").
|
||||||
# to(:controller => "books")
|
# to(:controller => "books")
|
||||||
#
|
#
|
||||||
# Or, use placeholders in the "to" results for more complicated routing, e.g.:
|
# Or, use placeholders in the "to" results for more complicated routing, e.g.:
|
||||||
#
|
#
|
||||||
# match("/admin/:module/:controller/:action/:id").
|
# match("/admin/:module/:controller/:action/:id").
|
||||||
@ -30,4 +30,4 @@ Merb::Router.prepare do
|
|||||||
match("/").to(:controller => "testing", :action => "show_form")
|
match("/").to(:controller => "testing", :action => "show_form")
|
||||||
match("/internal_redirect").to(:controller => "testing", :action => "internal_redirect")
|
match("/internal_redirect").to(:controller => "testing", :action => "internal_redirect")
|
||||||
match("/external_redirect").to(:controller => "testing", :action => "external_redirect")
|
match("/external_redirect").to(:controller => "testing", :action => "external_redirect")
|
||||||
end
|
end
|
||||||
|
@ -21,4 +21,4 @@ end
|
|||||||
|
|
||||||
Webrat.configure do |config|
|
Webrat.configure do |config|
|
||||||
config.mode = :merb
|
config.mode = :merb
|
||||||
end
|
end
|
||||||
|
@ -19,7 +19,7 @@ describe "Webrat" do
|
|||||||
response.status.should == 200
|
response.status.should == 200
|
||||||
response.should contain("Webrat Form")
|
response.should contain("Webrat Form")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should check the value of a field" do
|
it "should check the value of a field" do
|
||||||
visit "/"
|
visit "/"
|
||||||
field_labeled("Prefilled").value.should == "text"
|
field_labeled("Prefilled").value.should == "text"
|
||||||
@ -29,4 +29,4 @@ describe "Webrat" do
|
|||||||
response = visit "/external_redirect"
|
response = visit "/external_redirect"
|
||||||
response.status.should == 302
|
response.status.should == 302
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,9 +12,9 @@ if File.directory?(gems_dir)
|
|||||||
Gem.clear_paths
|
Gem.clear_paths
|
||||||
Gem.path.replace([File.expand_path(gems_dir)])
|
Gem.path.replace([File.expand_path(gems_dir)])
|
||||||
ENV["PATH"] = "#{File.dirname(__FILE__)}:#{ENV["PATH"]}"
|
ENV["PATH"] = "#{File.dirname(__FILE__)}:#{ENV["PATH"]}"
|
||||||
|
|
||||||
gem_file = File.join(gems_dir, "specifications", "<%= spec.name %>-*.gemspec")
|
gem_file = File.join(gems_dir, "specifications", "<%= spec.name %>-*.gemspec")
|
||||||
|
|
||||||
if local_gem = Dir[gem_file].last
|
if local_gem = Dir[gem_file].last
|
||||||
version = File.basename(local_gem)[/-([\.\d]+)\.gemspec$/, 1]
|
version = File.basename(local_gem)[/-([\.\d]+)\.gemspec$/, 1]
|
||||||
end
|
end
|
||||||
@ -28,4 +28,4 @@ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
|
|||||||
end
|
end
|
||||||
|
|
||||||
gem '<%= @spec.name %>', version
|
gem '<%= @spec.name %>', version
|
||||||
load '<%= bin_file_name %>'
|
load '<%= bin_file_name %>'
|
||||||
|
@ -7,21 +7,21 @@ module Gem
|
|||||||
BUNDLED_SPECS = File.join(Dir.pwd, "gems", "specifications")
|
BUNDLED_SPECS = File.join(Dir.pwd, "gems", "specifications")
|
||||||
MAIN_INDEX = Gem::SourceIndex.from_gems_in(BUNDLED_SPECS)
|
MAIN_INDEX = Gem::SourceIndex.from_gems_in(BUNDLED_SPECS)
|
||||||
FALLBACK_INDEX = Gem::SourceIndex.from_installed_gems
|
FALLBACK_INDEX = Gem::SourceIndex.from_installed_gems
|
||||||
|
|
||||||
def self.source_index
|
def self.source_index
|
||||||
MultiSourceIndex.new
|
MultiSourceIndex.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.searcher
|
def self.searcher
|
||||||
MultiPathSearcher.new
|
MultiPathSearcher.new
|
||||||
end
|
end
|
||||||
|
|
||||||
class ArbitrarySearcher < GemPathSearcher
|
class ArbitrarySearcher < GemPathSearcher
|
||||||
def initialize(source_index)
|
def initialize(source_index)
|
||||||
@source_index = source_index
|
@source_index = source_index
|
||||||
super()
|
super()
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_gemspecs
|
def init_gemspecs
|
||||||
@source_index.map { |_, spec| spec }.sort { |a,b|
|
@source_index.map { |_, spec| spec }.sort { |a,b|
|
||||||
(a.name <=> b.name).nonzero? || (b.version <=> a.version)
|
(a.name <=> b.name).nonzero? || (b.version <=> a.version)
|
||||||
@ -34,31 +34,31 @@ module Gem
|
|||||||
@main_searcher = ArbitrarySearcher.new(MAIN_INDEX)
|
@main_searcher = ArbitrarySearcher.new(MAIN_INDEX)
|
||||||
@fallback_searcher = ArbitrarySearcher.new(FALLBACK_INDEX)
|
@fallback_searcher = ArbitrarySearcher.new(FALLBACK_INDEX)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find(path)
|
def find(path)
|
||||||
try = @main_searcher.find(path)
|
try = @main_searcher.find(path)
|
||||||
return try if try
|
return try if try
|
||||||
@fallback_searcher.find(path)
|
@fallback_searcher.find(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_all(path)
|
def find_all(path)
|
||||||
try = @main_searcher.find_all(path)
|
try = @main_searcher.find_all(path)
|
||||||
return try unless try.empty?
|
return try unless try.empty?
|
||||||
@fallback_searcher.find_all(path)
|
@fallback_searcher.find_all(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class MultiSourceIndex
|
class MultiSourceIndex
|
||||||
def search(*args)
|
def search(*args)
|
||||||
try = MAIN_INDEX.search(*args)
|
try = MAIN_INDEX.search(*args)
|
||||||
return try unless try.empty?
|
return try unless try.empty?
|
||||||
FALLBACK_INDEX.search(*args)
|
FALLBACK_INDEX.search(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_name(*args)
|
def find_name(*args)
|
||||||
try = MAIN_INDEX.find_name(*args)
|
try = MAIN_INDEX.find_name(*args)
|
||||||
return try unless try.empty?
|
return try unless try.empty?
|
||||||
FALLBACK_INDEX.find_name(*args)
|
FALLBACK_INDEX.find_name(*args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,12 +2,12 @@ require "erb"
|
|||||||
|
|
||||||
Gem.pre_install_hooks.push(proc do |installer|
|
Gem.pre_install_hooks.push(proc do |installer|
|
||||||
$INSTALLING << installer.spec
|
$INSTALLING << installer.spec
|
||||||
|
|
||||||
unless File.file?(installer.bin_dir / "common.rb")
|
unless File.file?(installer.bin_dir / "common.rb")
|
||||||
FileUtils.mkdir_p(installer.bin_dir)
|
FileUtils.mkdir_p(installer.bin_dir)
|
||||||
FileUtils.cp(File.dirname(__FILE__) / "common.rb", installer.bin_dir / "common.rb")
|
FileUtils.cp(File.dirname(__FILE__) / "common.rb", installer.bin_dir / "common.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
include ColorfulMessages
|
include ColorfulMessages
|
||||||
name = installer.spec.name
|
name = installer.spec.name
|
||||||
if $GEMS && versions = ($GEMS.assoc(name) || [])[1]
|
if $GEMS && versions = ($GEMS.assoc(name) || [])[1]
|
||||||
@ -25,19 +25,19 @@ end)
|
|||||||
|
|
||||||
class ::Gem::Uninstaller
|
class ::Gem::Uninstaller
|
||||||
def self._with_silent_ui
|
def self._with_silent_ui
|
||||||
|
|
||||||
ui = Gem::DefaultUserInteraction.ui
|
ui = Gem::DefaultUserInteraction.ui
|
||||||
def ui.say(str)
|
def ui.say(str)
|
||||||
puts "- #{str}"
|
puts "- #{str}"
|
||||||
end
|
end
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
class << Gem::DefaultUserInteraction.ui
|
class << Gem::DefaultUserInteraction.ui
|
||||||
remove_method :say
|
remove_method :say
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self._uninstall(source_index, name, op, version)
|
def self._uninstall(source_index, name, op, version)
|
||||||
unless source_index.find_name(name, "#{op} #{version}").empty?
|
unless source_index.find_name(name, "#{op} #{version}").empty?
|
||||||
uninstaller = Gem::Uninstaller.new(
|
uninstaller = Gem::Uninstaller.new(
|
||||||
@ -50,7 +50,7 @@ class ::Gem::Uninstaller
|
|||||||
_with_silent_ui { uninstaller.uninstall }
|
_with_silent_ui { uninstaller.uninstall }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self._uninstall_others(source_index, name, version)
|
def self._uninstall_others(source_index, name, version)
|
||||||
_uninstall(source_index, name, "<", version)
|
_uninstall(source_index, name, "<", version)
|
||||||
_uninstall(source_index, name, ">", version)
|
_uninstall(source_index, name, ">", version)
|
||||||
@ -67,14 +67,14 @@ end)
|
|||||||
|
|
||||||
class ::Gem::DependencyInstaller
|
class ::Gem::DependencyInstaller
|
||||||
alias old_fg find_gems_with_sources
|
alias old_fg find_gems_with_sources
|
||||||
|
|
||||||
def find_gems_with_sources(dep)
|
def find_gems_with_sources(dep)
|
||||||
if @source_index.any? { |_, installed_spec|
|
if @source_index.any? { |_, installed_spec|
|
||||||
installed_spec.satisfies_requirement?(dep)
|
installed_spec.satisfies_requirement?(dep)
|
||||||
}
|
}
|
||||||
return []
|
return []
|
||||||
end
|
end
|
||||||
|
|
||||||
old_fg(dep)
|
old_fg(dep)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -83,9 +83,9 @@ class ::Gem::SpecFetcher
|
|||||||
alias old_fetch fetch
|
alias old_fetch fetch
|
||||||
def fetch(dependency, all = false, matching_platform = true)
|
def fetch(dependency, all = false, matching_platform = true)
|
||||||
idx = Gem::SourceIndex.from_installed_gems
|
idx = Gem::SourceIndex.from_installed_gems
|
||||||
|
|
||||||
dep = idx.search(dependency).sort.last
|
dep = idx.search(dependency).sort.last
|
||||||
|
|
||||||
if dep
|
if dep
|
||||||
file = dep.loaded_from.dup
|
file = dep.loaded_from.dup
|
||||||
file.gsub!(/specifications/, "cache")
|
file.gsub!(/specifications/, "cache")
|
||||||
@ -121,4 +121,4 @@ class ::Gem::Specification
|
|||||||
end
|
end
|
||||||
specs + specs.map {|s| s.recursive_dependencies(self, index)}.flatten.uniq
|
specs + specs.map {|s| s.recursive_dependencies(self, index)}.flatten.uniq
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,7 +18,7 @@ module Thor::Tasks
|
|||||||
@dependencies << [name, versions]
|
@dependencies << [name, versions]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Gem < Thor
|
class Gem < Thor
|
||||||
def full_list
|
def full_list
|
||||||
@idx.load_gems_in("gems/specifications")
|
@idx.load_gems_in("gems/specifications")
|
||||||
@ -34,7 +34,7 @@ module Thor::Tasks
|
|||||||
[spec] + deps
|
[spec] + deps
|
||||||
end.flatten.uniq
|
end.flatten.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def rescue_failures(error = StandardError, prc = nil)
|
def rescue_failures(error = StandardError, prc = nil)
|
||||||
begin
|
begin
|
||||||
yield
|
yield
|
||||||
@ -67,12 +67,12 @@ module Thor::Tasks
|
|||||||
end
|
end
|
||||||
exit!
|
exit!
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def _install(dep)
|
def _install(dep)
|
||||||
@idx.load_gems_in("gems/specifications")
|
@idx.load_gems_in("gems/specifications")
|
||||||
return if @idx.search(dep).last
|
return if @idx.search(dep).last
|
||||||
|
|
||||||
installer = ::Gem::DependencyInstaller.new(
|
installer = ::Gem::DependencyInstaller.new(
|
||||||
:bin_dir => Dir.pwd / "bin",
|
:bin_dir => Dir.pwd / "bin",
|
||||||
:install_dir => Dir.pwd / "gems",
|
:install_dir => Dir.pwd / "gems",
|
||||||
@ -90,4 +90,4 @@ module Thor::Tasks
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,34 +5,34 @@ class String
|
|||||||
end
|
end
|
||||||
|
|
||||||
module ColorfulMessages
|
module ColorfulMessages
|
||||||
|
|
||||||
# red
|
# red
|
||||||
def error(*messages)
|
def error(*messages)
|
||||||
puts messages.map { |msg| "\033[1;31m#{msg}\033[0m" }
|
puts messages.map { |msg| "\033[1;31m#{msg}\033[0m" }
|
||||||
end
|
end
|
||||||
|
|
||||||
# yellow
|
# yellow
|
||||||
def warning(*messages)
|
def warning(*messages)
|
||||||
puts messages.map { |msg| "\033[1;33m#{msg}\033[0m" }
|
puts messages.map { |msg| "\033[1;33m#{msg}\033[0m" }
|
||||||
end
|
end
|
||||||
|
|
||||||
# green
|
# green
|
||||||
def success(*messages)
|
def success(*messages)
|
||||||
puts messages.map { |msg| "\033[1;32m#{msg}\033[0m" }
|
puts messages.map { |msg| "\033[1;32m#{msg}\033[0m" }
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :message, :success
|
alias_method :message, :success
|
||||||
|
|
||||||
# magenta
|
# magenta
|
||||||
def note(*messages)
|
def note(*messages)
|
||||||
puts messages.map { |msg| "\033[1;35m#{msg}\033[0m" }
|
puts messages.map { |msg| "\033[1;35m#{msg}\033[0m" }
|
||||||
end
|
end
|
||||||
|
|
||||||
# blue
|
# blue
|
||||||
def info(*messages)
|
def info(*messages)
|
||||||
puts messages.map { |msg| "\033[1;34m#{msg}\033[0m" }
|
puts messages.map { |msg| "\033[1;34m#{msg}\033[0m" }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module ThorUI
|
module ThorUI
|
||||||
|
@ -7,9 +7,9 @@ class ApplicationController < ActionController::Base
|
|||||||
# See ActionController::RequestForgeryProtection for details
|
# See ActionController::RequestForgeryProtection for details
|
||||||
# Uncomment the :secret if you're not using the cookie session store
|
# Uncomment the :secret if you're not using the cookie session store
|
||||||
protect_from_forgery # :secret => 'ceaca978d06f1c9db5c84193c1447572'
|
protect_from_forgery # :secret => 'ceaca978d06f1c9db5c84193c1447572'
|
||||||
|
|
||||||
# See ActionController::Base for details
|
# See ActionController::Base for details
|
||||||
# Uncomment this to filter the contents of submitted sensitive data parameters
|
# Uncomment this to filter the contents of submitted sensitive data parameters
|
||||||
# from your application log (in this case, all fields with names like "password").
|
# from your application log (in this case, all fields with names like "password").
|
||||||
# filter_parameter_logging :password
|
# filter_parameter_logging :password
|
||||||
end
|
end
|
||||||
|
@ -12,28 +12,28 @@ class WebratController < ApplicationController
|
|||||||
def submit
|
def submit
|
||||||
render :text => "OK <a href='/' id='link_id'>Test Link Text</a>"
|
render :text => "OK <a href='/' id='link_id'>Test Link Text</a>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def internal_redirect
|
def internal_redirect
|
||||||
redirect_to submit_path
|
redirect_to submit_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def infinite_redirect
|
def infinite_redirect
|
||||||
redirect_to infinite_redirect_path
|
redirect_to infinite_redirect_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def external_redirect
|
def external_redirect
|
||||||
redirect_to "http://google.com"
|
redirect_to "http://google.com"
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_redirect_form
|
def before_redirect_form
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_to_show_params
|
def redirect_to_show_params
|
||||||
redirect_to show_params_path(:custom_param => "123")
|
redirect_to show_params_path(:custom_param => "123")
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_params
|
def show_params
|
||||||
render :text => params.to_json
|
render :text => params.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -14,4 +14,4 @@ config.action_view.debug_rjs = true
|
|||||||
config.action_controller.perform_caching = false
|
config.action_controller.perform_caching = false
|
||||||
|
|
||||||
# Don't care if the mailer can't send
|
# Don't care if the mailer can't send
|
||||||
config.action_mailer.raise_delivery_errors = false
|
config.action_mailer.raise_delivery_errors = false
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Be sure to restart your server when you modify this file.
|
# Be sure to restart your server when you modify this file.
|
||||||
|
|
||||||
# Add new inflection rules using the following format
|
# Add new inflection rules using the following format
|
||||||
# (all these examples are active by default):
|
# (all these examples are active by default):
|
||||||
# ActiveSupport::Inflector.inflections do |inflect|
|
# ActiveSupport::Inflector.inflections do |inflect|
|
||||||
# inflect.plural /^(ox)$/i, '\1en'
|
# inflect.plural /^(ox)$/i, '\1en'
|
||||||
|
@ -14,4 +14,4 @@ ActiveSupport.use_standard_json_time_format = true
|
|||||||
|
|
||||||
# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
|
# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
|
||||||
# if you're including raw json in an HTML page.
|
# if you're including raw json in an HTML page.
|
||||||
ActiveSupport.escape_html_entities_in_json = false
|
ActiveSupport.escape_html_entities_in_json = false
|
||||||
|
@ -4,11 +4,11 @@ ActionController::Routing::Routes.draw do |map|
|
|||||||
webrat.internal_redirect "/internal_redirect", :action => "internal_redirect"
|
webrat.internal_redirect "/internal_redirect", :action => "internal_redirect"
|
||||||
webrat.external_redirect "/external_redirect", :action => "external_redirect"
|
webrat.external_redirect "/external_redirect", :action => "external_redirect"
|
||||||
webrat.infinite_redirect "/infinite_redirect", :action => "infinite_redirect"
|
webrat.infinite_redirect "/infinite_redirect", :action => "infinite_redirect"
|
||||||
|
|
||||||
webrat.before_redirect_form "/before_redirect_form", :action => "before_redirect_form"
|
webrat.before_redirect_form "/before_redirect_form", :action => "before_redirect_form"
|
||||||
webrat.redirect_to_show_params "/redirect_to_show_params", :action => "redirect_to_show_params"
|
webrat.redirect_to_show_params "/redirect_to_show_params", :action => "redirect_to_show_params"
|
||||||
webrat.show_params "/show_params", :action => "show_params"
|
webrat.show_params "/show_params", :action => "show_params"
|
||||||
|
|
||||||
webrat.root :action => "form"
|
webrat.root :action => "form"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -66,13 +66,13 @@ class WebratTest < ActionController::IntegrationTest
|
|||||||
visit root_path
|
visit root_path
|
||||||
assert_have_selector "h1"
|
assert_have_selector "h1"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should detect infinite redirects" do
|
test "should detect infinite redirects" do
|
||||||
assert_raises Webrat::InfiniteRedirectError do
|
assert_raises Webrat::InfiniteRedirectError do
|
||||||
visit infinite_redirect_path
|
visit infinite_redirect_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# test "should be able to assert have tag" do
|
# test "should be able to assert have tag" do
|
||||||
# visit root_path
|
# visit root_path
|
||||||
# assert_have_tag "h1"
|
# assert_have_tag "h1"
|
||||||
|
@ -22,4 +22,4 @@ Dispatcher.class_eval do
|
|||||||
def self.failsafe_response(output, status, exception = nil)
|
def self.failsafe_response(output, status, exception = nil)
|
||||||
raise exception
|
raise exception
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -24,7 +24,7 @@ describe Webrat::Configuration do
|
|||||||
config = Webrat::Configuration.new
|
config = Webrat::Configuration.new
|
||||||
config.should open_error_files
|
config.should open_error_files
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should detect infinite redirects after 10" do
|
it "should detect infinite redirects after 10" do
|
||||||
config = Webrat::Configuration.new
|
config = Webrat::Configuration.new
|
||||||
config.infinite_redirect_limit.should == 10
|
config.infinite_redirect_limit.should == 10
|
||||||
@ -43,7 +43,7 @@ describe Webrat::Configuration do
|
|||||||
Webrat.configure do |config|
|
Webrat.configure do |config|
|
||||||
config.open_error_files = false
|
config.open_error_files = false
|
||||||
end
|
end
|
||||||
|
|
||||||
Webrat.configure do |config|
|
Webrat.configure do |config|
|
||||||
config.selenium_server_port = 1234
|
config.selenium_server_port = 1234
|
||||||
end
|
end
|
||||||
@ -52,7 +52,7 @@ describe Webrat::Configuration do
|
|||||||
config.should_not open_error_files
|
config.should_not open_error_files
|
||||||
config.selenium_server_port.should == 1234
|
config.selenium_server_port.should == 1234
|
||||||
end
|
end
|
||||||
|
|
||||||
[:rails,
|
[:rails,
|
||||||
:selenium,
|
:selenium,
|
||||||
:rack,
|
:rack,
|
||||||
@ -70,7 +70,7 @@ describe Webrat::Configuration do
|
|||||||
config.should_receive(:require).with("webrat/merb_session")
|
config.should_receive(:require).with("webrat/merb_session")
|
||||||
config.mode = :merb
|
config.mode = :merb
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Selenium" do
|
describe "Selenium" do
|
||||||
before :each do
|
before :each do
|
||||||
@config = Webrat::Configuration.new
|
@config = Webrat::Configuration.new
|
||||||
|
@ -8,13 +8,13 @@ module Webrat
|
|||||||
<input type='checkbox' checked='checked' />
|
<input type='checkbox' checked='checked' />
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
|
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
|
||||||
checkbox = CheckboxField.new(nil, element)
|
checkbox = CheckboxField.new(nil, element)
|
||||||
checkbox.inspect.should =~ /#<Webrat::CheckboxField @element=<input type=['"]checkbox['"] checked(=['"]checked['"])?\/?>>/
|
checkbox.inspect.should =~ /#<Webrat::CheckboxField @element=<input type=['"]checkbox['"] checked(=['"]checked['"])?\/?>>/
|
||||||
end
|
end
|
||||||
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
|
||||||
@ -22,7 +22,7 @@ module Webrat
|
|||||||
<input type='checkbox' checked='checked' />
|
<input type='checkbox' checked='checked' />
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
|
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
|
||||||
checkbox = CheckboxField.new(nil, element)
|
checkbox = CheckboxField.new(nil, element)
|
||||||
checkbox.should be_checked
|
checkbox.should be_checked
|
||||||
@ -34,13 +34,13 @@ module Webrat
|
|||||||
<input type='checkbox' />
|
<input type='checkbox' />
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
|
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
|
||||||
checkbox = CheckboxField.new(nil, element)
|
checkbox = CheckboxField.new(nil, element)
|
||||||
checkbox.should_not be_checked
|
checkbox.should_not be_checked
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe RadioField do
|
describe RadioField 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
|
||||||
@ -48,7 +48,7 @@ module Webrat
|
|||||||
<input type='radio' checked='checked' />
|
<input type='radio' checked='checked' />
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
|
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
|
||||||
radio_button = RadioField.new(nil, element)
|
radio_button = RadioField.new(nil, element)
|
||||||
radio_button.should be_checked
|
radio_button.should be_checked
|
||||||
@ -58,8 +58,8 @@ module Webrat
|
|||||||
html = <<-HTML
|
html = <<-HTML
|
||||||
<html><input type='radio' /></html>
|
<html><input type='radio' /></html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
|
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
|
||||||
radio_button = RadioField.new(nil, element)
|
radio_button = RadioField.new(nil, element)
|
||||||
radio_button.should_not be_checked
|
radio_button.should_not be_checked
|
||||||
end
|
end
|
||||||
|
@ -7,18 +7,18 @@ describe Webrat::Link do
|
|||||||
webrat_session = mock(Webrat::TestSession)
|
webrat_session = mock(Webrat::TestSession)
|
||||||
@link_text_with_nbsp = 'Link' + [0xA0].pack("U") + 'Text'
|
@link_text_with_nbsp = 'Link' + [0xA0].pack("U") + 'Text'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should pass through relative urls" do
|
it "should pass through relative urls" do
|
||||||
link = Webrat::Link.new(webrat_session, {"href" => "/path"})
|
link = Webrat::Link.new(webrat_session, {"href" => "/path"})
|
||||||
webrat_session.should_receive(:request_page).with("/path", :get, {})
|
webrat_session.should_receive(:request_page).with("/path", :get, {})
|
||||||
link.click
|
link.click
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shouldnt put base url onto " do
|
it "shouldnt put base url onto " do
|
||||||
url = "https://www.example.com/path"
|
url = "https://www.example.com/path"
|
||||||
webrat_session.should_receive(:request_page).with(url, :get, {})
|
webrat_session.should_receive(:request_page).with(url, :get, {})
|
||||||
link = Webrat::Link.new(webrat_session, {"href" => url})
|
link = Webrat::Link.new(webrat_session, {"href" => url})
|
||||||
link.click
|
link.click
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
||||||
|
|
||||||
describe Webrat::Logging do
|
describe Webrat::Logging do
|
||||||
|
|
||||||
it "should not log if there is no logger" do
|
it "should not log if there is no logger" do
|
||||||
klass = Class.new
|
klass = Class.new
|
||||||
klass.send(:include, Webrat::Logging)
|
klass.send(:include, Webrat::Logging)
|
||||||
klass.new.debug_log "Testing"
|
klass.new.debug_log "Testing"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -137,7 +137,7 @@ describe Webrat::Session do
|
|||||||
webrat_session.redirect?.should be_false
|
webrat_session.redirect?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#internal_redirect?" do
|
describe "#internal_redirect?" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
webrat_session = Webrat::Session.new
|
webrat_session = Webrat::Session.new
|
||||||
@ -149,19 +149,19 @@ describe Webrat::Session do
|
|||||||
webrat_session.stub!(:response_location => "http://example.com")
|
webrat_session.stub!(:response_location => "http://example.com")
|
||||||
webrat_session.internal_redirect?.should be_true
|
webrat_session.internal_redirect?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return true if the last response was a redirect and the hosts are the same but the subdomains are different" do
|
it "should return true if the last response was a redirect and the hosts are the same but the subdomains are different" do
|
||||||
webrat_session.stub!(:redirect? => true)
|
webrat_session.stub!(:redirect? => true)
|
||||||
webrat_session.stub!(:current_url => "http://example.com")
|
webrat_session.stub!(:current_url => "http://example.com")
|
||||||
webrat_session.stub!(:response_location => "http://myName.example.com")
|
webrat_session.stub!(:response_location => "http://myName.example.com")
|
||||||
webrat_session.internal_redirect?.should be_true
|
webrat_session.internal_redirect?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return false if the last response was not a redirect" do
|
it "should return false if the last response was not a redirect" do
|
||||||
webrat_session.stub!(:redirect? => false)
|
webrat_session.stub!(:redirect? => false)
|
||||||
webrat_session.internal_redirect?.should be_false
|
webrat_session.internal_redirect?.should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return false if the last response was a redirect but the host of the current_url doesn't matches that of the response location" do
|
it "should return false if the last response was a redirect but the host of the current_url doesn't matches that of the response location" do
|
||||||
webrat_session.stub!(:redirect? => true)
|
webrat_session.stub!(:redirect? => true)
|
||||||
webrat_session.stub!(:current_url => "http://example.com")
|
webrat_session.stub!(:current_url => "http://example.com")
|
||||||
@ -176,23 +176,23 @@ describe Webrat::Session do
|
|||||||
webrat_session.internal_redirect?.should be_false
|
webrat_session.internal_redirect?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#redirected_to" do
|
describe "#redirected_to" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
webrat_session = Webrat::Session.new
|
webrat_session = Webrat::Session.new
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return nil if not redirected" do
|
it "should return nil if not redirected" do
|
||||||
webrat_session.stub!(:redirect? => false)
|
webrat_session.stub!(:redirect? => false)
|
||||||
webrat_session.redirected_to.should be_nil
|
webrat_session.redirected_to.should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the response_location if redirected" do
|
it "should return the response_location if redirected" do
|
||||||
webrat_session.stub!(:redirect? => true)
|
webrat_session.stub!(:redirect? => true)
|
||||||
webrat_session.stub!(:response_location => "http://www.example.com")
|
webrat_session.stub!(:response_location => "http://www.example.com")
|
||||||
webrat_session.redirected_to.should == "http://www.example.com"
|
webrat_session.redirected_to.should == "http://www.example.com"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -10,26 +10,26 @@ describe Webrat::MechanizeSession do
|
|||||||
before(:each) do
|
before(:each) do
|
||||||
@mech = Webrat::MechanizeSession.new
|
@mech = Webrat::MechanizeSession.new
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "headers method" do
|
describe "headers method" do
|
||||||
it "should return empty headers for a newly initialized session" do
|
it "should return empty headers for a newly initialized session" do
|
||||||
@mech.headers.should == {}
|
@mech.headers.should == {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "post" do
|
describe "post" do
|
||||||
def url
|
def url
|
||||||
'http://test.host/users'
|
'http://test.host/users'
|
||||||
end
|
end
|
||||||
|
|
||||||
def data
|
def data
|
||||||
{:user => {:first_name => 'Nancy', :last_name => 'Callahan'}}
|
{:user => {:first_name => 'Nancy', :last_name => 'Callahan'}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def flattened_data
|
def flattened_data
|
||||||
{'user[first_name]' => 'Nancy', 'user[last_name]' => 'Callahan'}
|
{'user[first_name]' => 'Nancy', 'user[last_name]' => 'Callahan'}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should flatten model post data" do
|
it "should flatten model post data" do
|
||||||
mechanize = mock(:mechanize)
|
mechanize = mock(:mechanize)
|
||||||
WWW::Mechanize.stub!(:new => mechanize)
|
WWW::Mechanize.stub!(:new => mechanize)
|
||||||
@ -37,45 +37,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
|
describe "#absolute_url" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@session = Webrat::MechanizeSession.new
|
@session = Webrat::MechanizeSession.new
|
||||||
@session.stub!(:current_url).and_return(absolute_url)
|
@session.stub!(:current_url).and_return(absolute_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
def absolute_url
|
def absolute_url
|
||||||
'http://test.host/users/fred/cabbages'
|
'http://test.host/users/fred/cabbages'
|
||||||
end
|
end
|
||||||
|
|
||||||
def rooted_url
|
def rooted_url
|
||||||
'/users/fred/cabbages'
|
'/users/fred/cabbages'
|
||||||
end
|
end
|
||||||
|
|
||||||
def relative_url
|
def relative_url
|
||||||
'../../wilma'
|
'../../wilma'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return unmodified url if prefixed with scheme" do
|
it "should return unmodified url if prefixed with scheme" do
|
||||||
@session.absolute_url(absolute_url).should == absolute_url
|
@session.absolute_url(absolute_url).should == absolute_url
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should prefix scheme and hostname if url begins with /" do
|
it "should prefix scheme and hostname if url begins with /" do
|
||||||
@session.absolute_url(rooted_url).should == absolute_url
|
@session.absolute_url(rooted_url).should == absolute_url
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should resolve sibling URLs relative to current path" do
|
it "should resolve sibling URLs relative to current path" do
|
||||||
@session.absolute_url(relative_url).should == 'http://test.host/users/wilma'
|
@session.absolute_url(relative_url).should == 'http://test.host/users/wilma'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should cope with sibling URLs from root of site" do
|
it "should cope with sibling URLs from root of site" do
|
||||||
@session.stub!(:current_url).and_return('http://test.host')
|
@session.stub!(:current_url).and_return('http://test.host')
|
||||||
@session.absolute_url(relative_url).should == 'http://test.host/wilma'
|
@session.absolute_url(relative_url).should == 'http://test.host/wilma'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should cope with https" do
|
it "should cope with https" do
|
||||||
@session.stub!(:current_url).and_return('https://test.host')
|
@session.stub!(:current_url).and_return('https://test.host')
|
||||||
@session.absolute_url(relative_url).should == 'https://test.host/wilma'
|
@session.absolute_url(relative_url).should == 'https://test.host/wilma'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -10,13 +10,13 @@ describe Webrat::MerbSession do
|
|||||||
session.should_receive(:request).with('url', {:params=> nil, :method=>"GET", :headers=>nil}).and_return(response)
|
session.should_receive(:request).with('url', {:params=> nil, :method=>"GET", :headers=>nil}).and_return(response)
|
||||||
session.get('url', {}, nil)
|
session.get('url', {}, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
%w{post put delete}.each do |request_method|
|
%w{post put delete}.each do |request_method|
|
||||||
it "should call do request with method #{request_method.upcase} for a #{request_method} call" do
|
it "should call do request with method #{request_method.upcase} for a #{request_method} call" do
|
||||||
session = Webrat::MerbSession.new
|
session = Webrat::MerbSession.new
|
||||||
response = OpenStruct.new
|
response = OpenStruct.new
|
||||||
response.status = 200
|
response.status = 200
|
||||||
|
|
||||||
session.should_receive(:request).with('url', {:params=>nil, :method=>request_method.upcase, :headers=>nil}).and_return(response)
|
session.should_receive(:request).with('url', {:params=>nil, :method=>request_method.upcase, :headers=>nil}).and_return(response)
|
||||||
session.send(request_method, 'url', {}, nil)
|
session.send(request_method, 'url', {}, nil)
|
||||||
end
|
end
|
||||||
@ -30,13 +30,13 @@ describe Webrat::MerbSession do
|
|||||||
@response.body = 'test response'
|
@response.body = 'test response'
|
||||||
@session.instance_variable_set(:@response, @response)
|
@session.instance_variable_set(:@response, @response)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return body of a request as a response_body" do
|
it "should return body of a request as a response_body" do
|
||||||
@session.response_body.should == @response.body
|
@session.response_body.should == @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return status of a request as a response_code" do
|
it "should return status of a request as a response_code" do
|
||||||
@session.response_code.should == @response.status
|
@session.response_code.should == @response.status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,7 +7,7 @@ if defined?(Nokogiri::XML) && Webrat.configuration.parse_with_nokogiri?
|
|||||||
def fail
|
def fail
|
||||||
raise_error(Spec::Expectations::ExpectationNotMetError)
|
raise_error(Spec::Expectations::ExpectationNotMetError)
|
||||||
end
|
end
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@text_and_password = <<-HTML
|
@text_and_password = <<-HTML
|
||||||
<div>
|
<div>
|
||||||
@ -16,29 +16,29 @@ if defined?(Nokogiri::XML) && Webrat.configuration.parse_with_nokogiri?
|
|||||||
<span type="text"/>
|
<span type="text"/>
|
||||||
</div>
|
</div>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
@text_only = <<-HTML
|
@text_only = <<-HTML
|
||||||
<div>
|
<div>
|
||||||
<input type="text" disabled="disabled" />
|
<input type="text" disabled="disabled" />
|
||||||
</div>
|
</div>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
@password_only = <<-HTML
|
@password_only = <<-HTML
|
||||||
<div>
|
<div>
|
||||||
<input type="password"/>
|
<input type="password"/>
|
||||||
<div>
|
<div>
|
||||||
HTML
|
HTML
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ":text" do
|
describe ":text" do
|
||||||
it "passes have_selector(:text) if a node with type=text exists" do
|
it "passes have_selector(:text) if a node with type=text exists" do
|
||||||
@text_and_password.should have_selector(":text")
|
@text_and_password.should have_selector(":text")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "passes not have_selector(:text) if no node with text=text exists" do
|
it "passes not have_selector(:text) if no node with text=text exists" do
|
||||||
@password_only.should_not have_selector(":text")
|
@password_only.should_not have_selector(":text")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails have_selector(:text) if no node with type=text exists" do
|
it "fails have_selector(:text) if no node with type=text exists" do
|
||||||
lambda { @password_only.should have_selector(":text") }.should fail
|
lambda { @password_only.should have_selector(":text") }.should fail
|
||||||
end
|
end
|
||||||
@ -46,21 +46,21 @@ if defined?(Nokogiri::XML) && Webrat.configuration.parse_with_nokogiri?
|
|||||||
it "fails not have_selector(:text) if a node with type=text exists" do
|
it "fails not have_selector(:text) if a node with type=text exists" do
|
||||||
lambda { @text_only.should_not have_selector(":text") }.should fail
|
lambda { @text_only.should_not have_selector(":text") }.should fail
|
||||||
end
|
end
|
||||||
|
|
||||||
it "works together with other selectors" do
|
it "works together with other selectors" do
|
||||||
@text_and_password.should have_selector("input:text[type*='te']")
|
@text_and_password.should have_selector("input:text[type*='te']")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ":password" do
|
describe ":password" do
|
||||||
it "passes have_selector(:password) if a node with type=password exists" do
|
it "passes have_selector(:password) if a node with type=password exists" do
|
||||||
@text_and_password.should have_selector(":password")
|
@text_and_password.should have_selector(":password")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "passes not have_selector(:text) if no node with text=text exists" do
|
it "passes not have_selector(:text) if no node with text=text exists" do
|
||||||
@text_only.should_not have_selector(":password")
|
@text_only.should_not have_selector(":password")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails have_selector(:password) if no node with type=password exists" do
|
it "fails have_selector(:password) if no node with type=password exists" do
|
||||||
lambda { @text_only.should have_selector(":password") }.should fail
|
lambda { @text_only.should have_selector(":password") }.should fail
|
||||||
end
|
end
|
||||||
@ -68,10 +68,10 @@ if defined?(Nokogiri::XML) && Webrat.configuration.parse_with_nokogiri?
|
|||||||
it "fails not have_selector(:password) if a node with type=password exists" do
|
it "fails not have_selector(:password) if a node with type=password exists" do
|
||||||
lambda { @password_only.should_not have_selector(":password") }.should fail
|
lambda { @password_only.should_not have_selector(":password") }.should fail
|
||||||
end
|
end
|
||||||
|
|
||||||
it "works together with other selectors" do
|
it "works together with other selectors" do
|
||||||
@text_and_password.should have_selector("input:password[type*='pa']")
|
@text_and_password.should have_selector("input:password[type*='pa']")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -78,4 +78,4 @@ describe "attach_file" do
|
|||||||
attach_file "Picture", @filename, "image/png"
|
attach_file "Picture", @filename, "image/png"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -85,7 +85,7 @@ describe Webrat::RailsSession do
|
|||||||
it "should provide a doc_root" do
|
it "should provide a doc_root" do
|
||||||
Webrat::RailsSession.new(mock("integration session")).should respond_to(:doc_root)
|
Webrat::RailsSession.new(mock("integration session")).should respond_to(:doc_root)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should accept an ActiveRecord argument to #within and translate to a selector using dom_id" do
|
it "should accept an ActiveRecord argument to #within and translate to a selector using dom_id" do
|
||||||
body = <<-HTML
|
body = <<-HTML
|
||||||
<a href="/page1">Edit</a>
|
<a href="/page1">Edit</a>
|
||||||
@ -93,18 +93,18 @@ describe Webrat::RailsSession do
|
|||||||
<a href="/page2">Edit</a>
|
<a href="/page2">Edit</a>
|
||||||
</div>
|
</div>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
response = mock("response", :body => body, :headers => {}, :code => 200)
|
response = mock("response", :body => body, :headers => {}, :code => 200)
|
||||||
@integration_session.stub!(:response => response)
|
@integration_session.stub!(:response => response)
|
||||||
@integration_session.should_receive(:get).with("/page2", {}, nil)
|
@integration_session.should_receive(:get).with("/page2", {}, nil)
|
||||||
|
|
||||||
rails_session = Webrat::RailsSession.new(@integration_session)
|
rails_session = Webrat::RailsSession.new(@integration_session)
|
||||||
|
|
||||||
object = Object.new
|
object = Object.new
|
||||||
object.stub!(:id => nil)
|
object.stub!(:id => nil)
|
||||||
|
|
||||||
rails_session.within(object) do
|
rails_session.within(object) do
|
||||||
rails_session.click_link 'Edit'
|
rails_session.click_link 'Edit'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -9,7 +9,7 @@ describe "Basic Auth HTTP headers" do
|
|||||||
webrat_session.should_receive(:get).with("/", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ=\n"})
|
webrat_session.should_receive(:get).with("/", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ=\n"})
|
||||||
visit("/")
|
visit("/")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be present in form submits" do
|
it "should be present in form submits" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
|
@ -20,10 +20,10 @@ describe "check" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
lambda { check "remember_me" }.should raise_error(Webrat::NotFoundError)
|
lambda { check "remember_me" }.should raise_error(Webrat::NotFoundError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should check rails style checkboxes" do
|
it "should check rails style checkboxes" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -35,12 +35,12 @@ describe "check" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"})
|
webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"})
|
||||||
check "TOS"
|
check "TOS"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should result in the value on being posted if not specified" do
|
it "should result in the value on being posted if not specified" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -50,12 +50,12 @@ describe "check" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
webrat_session.should_receive(:post).with("/login", "remember_me" => "on")
|
webrat_session.should_receive(:post).with("/login", "remember_me" => "on")
|
||||||
check "remember_me"
|
check "remember_me"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should fail if the checkbox is disabled" do
|
it "should fail if the checkbox is disabled" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -65,10 +65,10 @@ describe "check" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
lambda { check "remember_me" }.should raise_error(Webrat::DisabledFieldError)
|
lambda { check "remember_me" }.should raise_error(Webrat::DisabledFieldError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should result in a custom value being posted" do
|
it "should result in a custom value being posted" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -78,7 +78,7 @@ describe "check" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
webrat_session.should_receive(:post).with("/login", "remember_me" => "yes")
|
webrat_session.should_receive(:post).with("/login", "remember_me" => "yes")
|
||||||
check "remember_me"
|
check "remember_me"
|
||||||
click_button
|
click_button
|
||||||
@ -105,10 +105,10 @@ describe "uncheck" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
lambda { uncheck "remember_me" }.should raise_error(Webrat::NotFoundError)
|
lambda { uncheck "remember_me" }.should raise_error(Webrat::NotFoundError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should fail if the checkbox is disabled" do
|
it "should fail if the checkbox is disabled" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -120,7 +120,7 @@ describe "uncheck" do
|
|||||||
HTML
|
HTML
|
||||||
lambda { uncheck "remember_me" }.should raise_error(Webrat::DisabledFieldError)
|
lambda { uncheck "remember_me" }.should raise_error(Webrat::DisabledFieldError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should uncheck rails style checkboxes" do
|
it "should uncheck rails style checkboxes" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -151,7 +151,7 @@ describe "uncheck" do
|
|||||||
uncheck "remember_me"
|
uncheck "remember_me"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should work with checkboxes with the same name" do
|
it "should work with checkboxes with the same name" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -169,7 +169,7 @@ describe "uncheck" do
|
|||||||
check 'Option 2'
|
check 'Option 2'
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should uncheck rails style checkboxes nested inside a label" do
|
it "should uncheck rails style checkboxes nested inside a label" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -187,5 +187,5 @@ describe "uncheck" do
|
|||||||
uncheck "TOS"
|
uncheck "TOS"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -8,10 +8,10 @@ describe "choose" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
lambda { choose "first option" }.should raise_error(Webrat::NotFoundError)
|
lambda { choose "first option" }.should raise_error(Webrat::NotFoundError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should fail if input is not a radio button" do
|
it "should fail if input is not a radio button" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -20,10 +20,10 @@ describe "choose" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
lambda { choose "first_option" }.should raise_error(Webrat::NotFoundError)
|
lambda { choose "first_option" }.should raise_error(Webrat::NotFoundError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should check rails style radio buttons" do
|
it "should check rails style radio buttons" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -40,7 +40,7 @@ describe "choose" do
|
|||||||
choose "Male"
|
choose "Male"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should only submit last chosen value" do
|
it "should only submit last chosen value" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -58,7 +58,7 @@ describe "choose" do
|
|||||||
choose "Male"
|
choose "Male"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should fail if the radio button is disabled" do
|
it "should fail if the radio button is disabled" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -68,10 +68,10 @@ describe "choose" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
lambda { choose "first_option" }.should raise_error(Webrat::DisabledFieldError)
|
lambda { choose "first_option" }.should raise_error(Webrat::DisabledFieldError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should result in the value on being posted if not specified" do
|
it "should result in the value on being posted if not specified" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -85,7 +85,7 @@ describe "choose" do
|
|||||||
choose "first_option"
|
choose "first_option"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should result in the value on being posted if not specified and checked by default" do
|
it "should result in the value on being posted if not specified and checked by default" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -98,7 +98,7 @@ describe "choose" do
|
|||||||
webrat_session.should_receive(:post).with("/login", "first_option" => "on")
|
webrat_session.should_receive(:post).with("/login", "first_option" => "on")
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should result in the value of the selected radio button being posted when a subsequent one is checked by default" do
|
it "should result in the value of the selected radio button being posted when a subsequent one is checked by default" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
|
@ -425,7 +425,7 @@ describe "click_button" do
|
|||||||
webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""})
|
webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""})
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should recognize button tags" do
|
it "should recognize button tags" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -448,9 +448,9 @@ describe "click_button" do
|
|||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
webrat_session.should_receive(:get)
|
webrat_session.should_receive(:get)
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should recognize image button tags" do
|
it "should recognize image button tags" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
|
@ -15,7 +15,7 @@ describe "fill_in" do
|
|||||||
fill_in "User Text", :with => "filling text area"
|
fill_in "User Text", :with => "filling text area"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should work with password fields" do
|
it "should work with password fields" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -37,10 +37,10 @@ describe "fill_in" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
lambda { fill_in "Email", :with => "foo@example.com" }.should raise_error(Webrat::NotFoundError)
|
lambda { fill_in "Email", :with => "foo@example.com" }.should raise_error(Webrat::NotFoundError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should fail if input is disabled" do
|
it "should fail if input is disabled" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -51,10 +51,10 @@ describe "fill_in" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
lambda { fill_in "Email", :with => "foo@example.com" }.should raise_error(Webrat::DisabledFieldError)
|
lambda { fill_in "Email", :with => "foo@example.com" }.should raise_error(Webrat::DisabledFieldError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should allow overriding default form values" do
|
it "should allow overriding default form values" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -69,7 +69,7 @@ describe "fill_in" do
|
|||||||
fill_in "user[email]", :with => "foo@example.com"
|
fill_in "user[email]", :with => "foo@example.com"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should choose the shortest label match" do
|
it "should choose the shortest label match" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -82,12 +82,12 @@ describe "fill_in" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
webrat_session.should_receive(:post).with("/login", "user" => {"mail1" => "", "mail2" => "value"})
|
webrat_session.should_receive(:post).with("/login", "user" => {"mail1" => "", "mail2" => "value"})
|
||||||
fill_in "Some", :with => "value"
|
fill_in "Some", :with => "value"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should choose the first label match if closest is a tie" do
|
it "should choose the first label match if closest is a tie" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -100,12 +100,12 @@ describe "fill_in" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
webrat_session.should_receive(:post).with("/login", "user" => {"mail1" => "value", "mail2" => ""})
|
webrat_session.should_receive(:post).with("/login", "user" => {"mail1" => "value", "mail2" => ""})
|
||||||
fill_in "Some mail", :with => "value"
|
fill_in "Some mail", :with => "value"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should anchor label matches to start of label" do
|
it "should anchor label matches to start of label" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -115,10 +115,10 @@ describe "fill_in" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
lambda { fill_in "mail", :with => "value" }.should raise_error(Webrat::NotFoundError)
|
lambda { fill_in "mail", :with => "value" }.should raise_error(Webrat::NotFoundError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should anchor label matches to word boundaries" do
|
it "should anchor label matches to word boundaries" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -128,10 +128,10 @@ describe "fill_in" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
lambda { fill_in "Email", :with => "value" }.should raise_error(Webrat::NotFoundError)
|
lambda { fill_in "Email", :with => "value" }.should raise_error(Webrat::NotFoundError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should work with inputs nested in labels" do
|
it "should work with inputs nested in labels" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -148,7 +148,7 @@ describe "fill_in" do
|
|||||||
fill_in "Email", :with => "foo@example.com"
|
fill_in "Email", :with => "foo@example.com"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should work with full input names" do
|
it "should work with full input names" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -176,7 +176,7 @@ describe "fill_in" do
|
|||||||
fill_in "user[email]", :with => "foo@example.com"
|
fill_in "user[email]", :with => "foo@example.com"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should work with symbols" do
|
it "should work with symbols" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -191,7 +191,7 @@ describe "fill_in" do
|
|||||||
fill_in :email, :with => "foo@example.com"
|
fill_in :email, :with => "foo@example.com"
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should escape field values" do
|
it "should escape field values" do
|
||||||
with_html <<-HTML
|
with_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
|
@ -11,7 +11,7 @@ describe "field_by_xpath" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
field = field_by_xpath(".//input")
|
field = field_by_xpath(".//input")
|
||||||
field.should_not be_nil
|
field.should_not be_nil
|
||||||
field.id.should == "element_42"
|
field.id.should == "element_42"
|
||||||
|
@ -8,24 +8,24 @@ describe "field_labeled" do
|
|||||||
with_html(html)
|
with_html(html)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_labeled(label)
|
def field_labeled(label)
|
||||||
@label = label
|
@label = label
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_return_a type, opts
|
def should_return_a type, opts
|
||||||
it "should return a textfield" do
|
it "should return a textfield" do
|
||||||
field_labeled(opts[:for]).should be_an_instance_of(type)
|
field_labeled(opts[:for]).should be_an_instance_of(type)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_an_id_of id, opts
|
def with_an_id_of id, opts
|
||||||
it "should return an element with the correct id" do
|
it "should return an element with the correct id" do
|
||||||
field_labeled(opts[:for]).should match_id(id)
|
field_labeled(opts[:for]).should match_id(id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_raise_error_matching regexp, opts
|
def should_raise_error_matching regexp, opts
|
||||||
it "should raise with wrong label" do
|
it "should raise with wrong label" do
|
||||||
lambda {
|
lambda {
|
||||||
@ -34,7 +34,7 @@ describe "field_labeled" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def match_id(id)
|
def match_id(id)
|
||||||
simple_matcher "element with id #{id.inspect}" do |element, matcher|
|
simple_matcher "element with id #{id.inspect}" do |element, matcher|
|
||||||
if id.is_a?(Regexp)
|
if id.is_a?(Regexp)
|
||||||
@ -44,7 +44,7 @@ describe "field_labeled" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "finding a text field" do
|
describe "finding a text field" do
|
||||||
using_this_html <<-HTML
|
using_this_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -54,12 +54,12 @@ describe "field_labeled" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
should_return_a Webrat::TextField, :for => "The Label"
|
should_return_a Webrat::TextField, :for => "The Label"
|
||||||
with_an_id_of "element_42", :for => "The Label"
|
with_an_id_of "element_42", :for => "The Label"
|
||||||
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "finding a hidden field" do
|
describe "finding a hidden field" do
|
||||||
using_this_html <<-HTML
|
using_this_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -69,12 +69,12 @@ describe "field_labeled" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
should_return_a Webrat::HiddenField, :for => "The Label"
|
should_return_a Webrat::HiddenField, :for => "The Label"
|
||||||
with_an_id_of "element_42", :for => "The Label"
|
with_an_id_of "element_42", :for => "The Label"
|
||||||
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "finding a checkbox" do
|
describe "finding a checkbox" do
|
||||||
using_this_html <<-HTML
|
using_this_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -84,12 +84,12 @@ describe "field_labeled" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
should_return_a Webrat::CheckboxField, :for => "The Label"
|
should_return_a Webrat::CheckboxField, :for => "The Label"
|
||||||
with_an_id_of "element_42", :for => "The Label"
|
with_an_id_of "element_42", :for => "The Label"
|
||||||
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "finding a radio button" do
|
describe "finding a radio button" do
|
||||||
using_this_html <<-HTML
|
using_this_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -99,13 +99,13 @@ describe "field_labeled" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
should_return_a Webrat::RadioField, :for => "The Label"
|
should_return_a Webrat::RadioField, :for => "The Label"
|
||||||
with_an_id_of "element_42", :for => "The Label"
|
with_an_id_of "element_42", :for => "The Label"
|
||||||
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
describe "finding a text area" do
|
describe "finding a text area" do
|
||||||
using_this_html <<-HTML
|
using_this_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -115,12 +115,12 @@ describe "field_labeled" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
should_return_a Webrat::TextareaField, :for => "The Label"
|
should_return_a Webrat::TextareaField, :for => "The Label"
|
||||||
with_an_id_of "element_42", :for => "The Label"
|
with_an_id_of "element_42", :for => "The Label"
|
||||||
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "finding a field with it's label containing newlines" do
|
describe "finding a field with it's label containing newlines" do
|
||||||
using_this_html <<-HTML
|
using_this_html <<-HTML
|
||||||
<html>
|
<html>
|
||||||
@ -153,5 +153,5 @@ describe "field_labeled" do
|
|||||||
should_return_a Webrat::TextField, :for => "The Label"
|
should_return_a Webrat::TextField, :for => "The Label"
|
||||||
with_an_id_of "element_42", :for => "The Label"
|
with_an_id_of "element_42", :for => "The Label"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -10,7 +10,7 @@ describe "field_with_id" do
|
|||||||
</form>
|
</form>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
field_with_id("user's name").id.should == "user's name"
|
field_with_id("user's name").id.should == "user's name"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
|||||||
|
|
||||||
describe "contain" do
|
describe "contain" do
|
||||||
include Webrat::Matchers
|
include Webrat::Matchers
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@body = <<-HTML
|
@body = <<-HTML
|
||||||
<div id='main'>
|
<div id='main'>
|
||||||
@ -25,62 +25,62 @@ describe "contain" do
|
|||||||
</div>
|
</div>
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#matches?" do
|
describe "#matches?" do
|
||||||
it "should call element#contains? when the argument is a string" do
|
it "should call element#contains? when the argument is a string" do
|
||||||
@body.should contain("hello, world!")
|
@body.should contain("hello, world!")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should call element#matches? when the argument is a regular expression" do
|
it "should call element#matches? when the argument is a regular expression" do
|
||||||
@body.should contain(/hello, world/)
|
@body.should contain(/hello, world/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "asserts for contains," do
|
describe "asserts for contains," do
|
||||||
include Test::Unit::Assertions
|
include Test::Unit::Assertions
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
should_receive(:response_body).and_return @body
|
should_receive(:response_body).and_return @body
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "assert_contain" do
|
describe "assert_contain" do
|
||||||
it "should pass when containing the text" do
|
it "should pass when containing the text" do
|
||||||
assert_contain("hello, world")
|
assert_contain("hello, world")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should pass when containing the regexp" do
|
it "should pass when containing the regexp" do
|
||||||
assert_contain(/hello, world/)
|
assert_contain(/hello, world/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should throw an exception when the body doesnt contain the text" do
|
it "should throw an exception when the body doesnt contain the text" do
|
||||||
lambda {
|
lambda {
|
||||||
assert_contain("monkeys")
|
assert_contain("monkeys")
|
||||||
}.should raise_error(Test::Unit::AssertionFailedError)
|
}.should raise_error(Test::Unit::AssertionFailedError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should throw an exception when the body doesnt contain the regexp" do
|
it "should throw an exception when the body doesnt contain the regexp" do
|
||||||
lambda {
|
lambda {
|
||||||
assert_contain(/monkeys/)
|
assert_contain(/monkeys/)
|
||||||
}.should raise_error(Test::Unit::AssertionFailedError)
|
}.should raise_error(Test::Unit::AssertionFailedError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "assert_not_contain" do
|
describe "assert_not_contain" do
|
||||||
it "should pass when not containing the text" do
|
it "should pass when not containing the text" do
|
||||||
assert_not_contain("monkeys")
|
assert_not_contain("monkeys")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should pass when not containing the regexp" do
|
it "should pass when not containing the regexp" do
|
||||||
assert_not_contain(/monkeys/)
|
assert_not_contain(/monkeys/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should throw an exception when the body does contain the text" do
|
it "should throw an exception when the body does contain the text" do
|
||||||
lambda {
|
lambda {
|
||||||
assert_not_contain("hello, world")
|
assert_not_contain("hello, world")
|
||||||
}.should raise_error(Test::Unit::AssertionFailedError)
|
}.should raise_error(Test::Unit::AssertionFailedError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should throw an exception when the body does contain the regexp" do
|
it "should throw an exception when the body does contain the regexp" do
|
||||||
lambda {
|
lambda {
|
||||||
assert_not_contain(/hello, world/)
|
assert_not_contain(/hello, world/)
|
||||||
@ -93,21 +93,21 @@ describe "contain" do
|
|||||||
it "should include the content string" do
|
it "should include the content string" do
|
||||||
hc = Webrat::Matchers::HasContent.new("hello, world!")
|
hc = Webrat::Matchers::HasContent.new("hello, world!")
|
||||||
hc.matches?(@body)
|
hc.matches?(@body)
|
||||||
|
|
||||||
hc.failure_message.should include("\"hello, world!\"")
|
hc.failure_message.should include("\"hello, world!\"")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should include the content regular expresson" do
|
it "should include the content regular expresson" do
|
||||||
hc = Webrat::Matchers::HasContent.new(/hello,\sworld!/)
|
hc = Webrat::Matchers::HasContent.new(/hello,\sworld!/)
|
||||||
hc.matches?(@body)
|
hc.matches?(@body)
|
||||||
|
|
||||||
hc.failure_message.should include("/hello,\\sworld!/")
|
hc.failure_message.should include("/hello,\\sworld!/")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should include the element's inner content" do
|
it "should include the element's inner content" do
|
||||||
hc = Webrat::Matchers::HasContent.new(/hello,\sworld!/)
|
hc = Webrat::Matchers::HasContent.new(/hello,\sworld!/)
|
||||||
hc.matches?(@body)
|
hc.matches?(@body)
|
||||||
|
|
||||||
hc.failure_message.should include("hello, world!")
|
hc.failure_message.should include("hello, world!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
|||||||
|
|
||||||
describe "have_selector" do
|
describe "have_selector" do
|
||||||
include Webrat::Matchers
|
include Webrat::Matchers
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@body = <<-HTML
|
@body = <<-HTML
|
||||||
<div id='main'>
|
<div id='main'>
|
||||||
@ -17,21 +17,21 @@ describe "have_selector" do
|
|||||||
</div>
|
</div>
|
||||||
HTML
|
HTML
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to match a CSS selector" do
|
it "should be able to match a CSS selector" do
|
||||||
@body.should have_selector("div")
|
@body.should have_selector("div")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not match a CSS selector that does not exist" do
|
it "should not match a CSS selector that does not exist" do
|
||||||
@body.should_not have_selector("p")
|
@body.should_not have_selector("p")
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "specifying attributes" do
|
describe "specifying attributes" do
|
||||||
it "should be able to specify the attributes of the tag" do
|
it "should be able to specify the attributes of the tag" do
|
||||||
@body.should have_selector("div", :class => "inner")
|
@body.should have_selector("div", :class => "inner")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "specifying content" do
|
describe "specifying content" do
|
||||||
it "should be able to specify the content of the tag" do
|
it "should be able to specify the content of the tag" do
|
||||||
@body.should have_selector("div", :content => "hello, world!")
|
@body.should have_selector("div", :content => "hello, world!")
|
||||||
@ -49,7 +49,7 @@ describe "have_selector" do
|
|||||||
@body.should have_selector("h4", :content => "Welcome 'Bryan\"")
|
@body.should have_selector("h4", :content => "Welcome 'Bryan\"")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "specifying counts" do
|
describe "specifying counts" do
|
||||||
it "should be able to specify the number of occurences of the tag" do
|
it "should be able to specify the number of occurences of the tag" do
|
||||||
@body.should have_selector("li", :count => 2)
|
@body.should have_selector("li", :count => 2)
|
||||||
@ -61,7 +61,7 @@ describe "have_selector" do
|
|||||||
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "specifying nested elements" do
|
describe "specifying nested elements" do
|
||||||
it "should be able to loop over all the matched elements" do
|
it "should be able to loop over all the matched elements" do
|
||||||
@body.should have_selector("div") do |node|
|
@body.should have_selector("div") do |node|
|
||||||
@ -90,7 +90,7 @@ describe "have_selector" do
|
|||||||
end
|
end
|
||||||
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should work with items that have multiple child nodes" do
|
it "should work with items that have multiple child nodes" do
|
||||||
@body.should have_selector("ul") do |n|
|
@body.should have_selector("ul") do |n|
|
||||||
n.should have_selector("li", :content => "First")
|
n.should have_selector("li", :content => "First")
|
||||||
@ -98,32 +98,32 @@ describe "have_selector" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Test::Unit assertions" do
|
describe "Test::Unit assertions" do
|
||||||
include Test::Unit::Assertions
|
include Test::Unit::Assertions
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
should_receive(:response_body).and_return @body
|
should_receive(:response_body).and_return @body
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "assert_have_selector" do
|
describe "assert_have_selector" do
|
||||||
it "should pass when body contains the selection" do
|
it "should pass when body contains the selection" do
|
||||||
assert_have_selector("div")
|
assert_have_selector("div")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should throw an exception when the body doesnt have matching selection" do
|
it "should throw an exception when the body doesnt have matching selection" do
|
||||||
lambda {
|
lambda {
|
||||||
assert_have_selector("p")
|
assert_have_selector("p")
|
||||||
}.should raise_error(Test::Unit::AssertionFailedError)
|
}.should raise_error(Test::Unit::AssertionFailedError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "assert_have_not_selector" do
|
describe "assert_have_not_selector" do
|
||||||
it "should pass when the body doesn't contan the selection" do
|
it "should pass when the body doesn't contan the selection" do
|
||||||
assert_have_no_selector("p")
|
assert_have_no_selector("p")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should throw an exception when the body does contain the selection" do
|
it "should throw an exception when the body does contain the selection" do
|
||||||
lambda {
|
lambda {
|
||||||
assert_have_no_selector("div")
|
assert_have_no_selector("div")
|
||||||
@ -131,5 +131,5 @@ describe "have_selector" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
|||||||
describe "have_tag" do
|
describe "have_tag" do
|
||||||
include Webrat::Matchers
|
include Webrat::Matchers
|
||||||
include Webrat::HaveTagMatcher
|
include Webrat::HaveTagMatcher
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@body = <<-HTML
|
@body = <<-HTML
|
||||||
<div id='main'>
|
<div id='main'>
|
||||||
@ -15,21 +15,21 @@ describe "have_tag" do
|
|||||||
it "should be an alias for have_selector" do
|
it "should be an alias for have_selector" do
|
||||||
@body.should have_tag("div")
|
@body.should have_tag("div")
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "asserts for tags" do
|
describe "asserts for tags" do
|
||||||
include Test::Unit::Assertions
|
include Test::Unit::Assertions
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
should_receive(:response_body).and_return @body
|
should_receive(:response_body).and_return @body
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "assert_have_tag" do
|
describe "assert_have_tag" do
|
||||||
it "should be an alias for assert_have_selector" do
|
it "should be an alias for assert_have_selector" do
|
||||||
assert_have_tag("div")
|
assert_have_tag("div")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "assert_have_no_tag" do
|
describe "assert_have_no_tag" do
|
||||||
it "should be an alias for assert_have_no_selector" do
|
it "should be an alias for assert_have_no_selector" do
|
||||||
assert_have_no_tag("p")
|
assert_have_no_tag("p")
|
||||||
|
@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
|||||||
|
|
||||||
describe "have_xpath" do
|
describe "have_xpath" do
|
||||||
include Webrat::Matchers
|
include Webrat::Matchers
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@body = <<-HTML
|
@body = <<-HTML
|
||||||
<div id='main'>
|
<div id='main'>
|
||||||
@ -17,49 +17,49 @@ describe "have_xpath" do
|
|||||||
</div>
|
</div>
|
||||||
HTML
|
HTML
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to match an XPATH" do
|
it "should be able to match an XPATH" do
|
||||||
@body.should have_xpath("//div")
|
@body.should have_xpath("//div")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to match an XPATH with attributes" do
|
it "should be able to match an XPATH with attributes" do
|
||||||
@body.should have_xpath("//div", :class => "inner")
|
@body.should have_xpath("//div", :class => "inner")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to match an XPATH with content" do
|
it "should be able to match an XPATH with content" do
|
||||||
@body.should have_xpath("//div", :content => "hello, world!")
|
@body.should have_xpath("//div", :content => "hello, world!")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not match an XPATH without content" do
|
it "should not match an XPATH without content" do
|
||||||
@body.should_not have_xpath("//div", :content => "not present")
|
@body.should_not have_xpath("//div", :content => "not present")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to match an XPATH with content and class" do
|
it "should be able to match an XPATH with content and class" do
|
||||||
@body.should have_xpath("//div", :class => "inner", :content => "hello, world!")
|
@body.should have_xpath("//div", :class => "inner", :content => "hello, world!")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not match an XPATH with content and wrong class" do
|
it "should not match an XPATH with content and wrong class" do
|
||||||
@body.should_not have_xpath("//div", :class => "outer", :content => "hello, world!")
|
@body.should_not have_xpath("//div", :class => "outer", :content => "hello, world!")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not match an XPATH with wrong content and class" do
|
it "should not match an XPATH with wrong content and class" do
|
||||||
@body.should_not have_xpath("//div", :class => "inner", :content => "wrong")
|
@body.should_not have_xpath("//div", :class => "inner", :content => "wrong")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not match an XPATH with wrong content and wrong class" do
|
it "should not match an XPATH with wrong content and wrong class" do
|
||||||
@body.should_not have_xpath("//div", :class => "outer", :content => "wrong")
|
@body.should_not have_xpath("//div", :class => "outer", :content => "wrong")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not match a XPATH that does not exist" do
|
it "should not match a XPATH that does not exist" do
|
||||||
@body.should_not have_xpath("//p")
|
@body.should_not have_xpath("//p")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to loop over all the matched elements" do
|
it "should be able to loop over all the matched elements" do
|
||||||
@body.should have_xpath("//div") do |node|
|
@body.should have_xpath("//div") do |node|
|
||||||
node.first.name.should == "div"
|
node.first.name.should == "div"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not match if any of the matchers in the block fail" do
|
it "should not match if any of the matchers in the block fail" do
|
||||||
lambda {
|
lambda {
|
||||||
@body.should have_xpath("//div") do |node|
|
@body.should have_xpath("//div") do |node|
|
||||||
@ -67,19 +67,19 @@ describe "have_xpath" do
|
|||||||
end
|
end
|
||||||
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to use #have_xpath in the block" do
|
it "should be able to use #have_xpath in the block" do
|
||||||
@body.should have_xpath("//div[@id='main']") do |node|
|
@body.should have_xpath("//div[@id='main']") do |node|
|
||||||
node.should have_xpath("./div[@class='inner']")
|
node.should have_xpath("./div[@class='inner']")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should convert absolute paths to relative in the block" do
|
it "should convert absolute paths to relative in the block" do
|
||||||
@body.should have_xpath("//div[@id='main']") do |node|
|
@body.should have_xpath("//div[@id='main']") do |node|
|
||||||
node.should have_xpath("//div[@class='inner']")
|
node.should have_xpath("//div[@class='inner']")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not match any parent tags in the block" do
|
it "should not match any parent tags in the block" do
|
||||||
lambda {
|
lambda {
|
||||||
@body.should have_xpath("//div[@class='inner']") do |node|
|
@body.should have_xpath("//div[@class='inner']") do |node|
|
||||||
@ -87,15 +87,15 @@ describe "have_xpath" do
|
|||||||
end
|
end
|
||||||
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'asserts for xpath' do
|
describe 'asserts for xpath' do
|
||||||
include Test::Unit::Assertions
|
include Test::Unit::Assertions
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
should_receive(:response_body).and_return @body
|
should_receive(:response_body).and_return @body
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "assert_have_xpath" do
|
describe "assert_have_xpath" do
|
||||||
it "should pass when body contains the selection" do
|
it "should pass when body contains the selection" do
|
||||||
assert_have_xpath("//div")
|
assert_have_xpath("//div")
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user