Merge commit 'krist0ff/master'
est.txt Rakefile lib/webrat/merb.rb spec/spec_helper.rb Conflicts: History.txt Manifest.txt Rakefile lib/webrat/merb.rb spec/spec_helper.rb
This commit is contained in:
commit
f831b497f3
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
coverage
|
coverage
|
||||||
|
.DS_Store
|
||||||
pkg
|
pkg
|
||||||
doc
|
doc
|
||||||
ri
|
ri
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
* Minor enhancements
|
* Minor enhancements
|
||||||
|
|
||||||
|
* Add Webrat.root method for cross-framework support (Krzysztof Zylawy)
|
||||||
* Add #select_date for quickly filling out Rails-style date fields (Alex Lang)
|
* Add #select_date for quickly filling out Rails-style date fields (Alex Lang)
|
||||||
* Support selecting options by their values (Alex Lang)
|
* Support selecting options by their values (Alex Lang)
|
||||||
* Support for clicking areas of an image map (Alex Lang)
|
* Support for clicking areas of an image map (Alex Lang)
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
VERSION = '0.2.1'
|
VERSION = '0.2.2'
|
||||||
|
def self.root
|
||||||
|
defined?(RAILS_ROOT) ? RAILS_ROOT : Merb.root
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require "rubygems"
|
require "rubygems"
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
require "cgi"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
class Field
|
class Field
|
||||||
|
|
||||||
@ -6,12 +8,11 @@ module Webrat
|
|||||||
if %w[submit image].include?(element["type"])
|
if %w[submit image].include?(element["type"])
|
||||||
field_class = "button"
|
field_class = "button"
|
||||||
else
|
else
|
||||||
field_class = element["type"] || "text"
|
field_class = element["type"] || "text" #default type; 'type' attribute is not mandatory
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
field_class = element.name
|
field_class = element.name
|
||||||
end
|
end
|
||||||
|
|
||||||
Webrat.const_get("#{field_class.capitalize}Field")
|
Webrat.const_get("#{field_class.capitalize}Field")
|
||||||
rescue NameError
|
rescue NameError
|
||||||
raise "Invalid field element: #{element.inspect}"
|
raise "Invalid field element: #{element.inspect}"
|
||||||
@ -120,10 +121,10 @@ module Webrat
|
|||||||
def param_parser
|
def param_parser
|
||||||
if defined?(CGIMethods)
|
if defined?(CGIMethods)
|
||||||
CGIMethods
|
CGIMethods
|
||||||
else
|
elsif defined?(ActionController::AbstractRequest)
|
||||||
require "action_controller"
|
|
||||||
require "action_controller/integration"
|
|
||||||
ActionController::AbstractRequest
|
ActionController::AbstractRequest
|
||||||
|
else
|
||||||
|
Webrat::ParamParser #used for Merb
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -150,10 +151,6 @@ module Webrat
|
|||||||
@element.innerHTML =~ /#{Regexp.escape(text.to_s)}/i
|
@element.innerHTML =~ /#{Regexp.escape(text.to_s)}/i
|
||||||
end
|
end
|
||||||
|
|
||||||
# def matches_id?(id)
|
|
||||||
# @element["id"] =~ /^\W*#{Regexp.escape(id.to_s)}/i
|
|
||||||
# end
|
|
||||||
|
|
||||||
def matches_value?(value)
|
def matches_value?(value)
|
||||||
@element["value"] =~ /^\W*#{Regexp.escape(value.to_s)}/i || matches_text?(value) || matches_alt?(value)
|
@element["value"] =~ /^\W*#{Regexp.escape(value.to_s)}/i || matches_text?(value) || matches_alt?(value)
|
||||||
end
|
end
|
||||||
@ -183,7 +180,7 @@ module Webrat
|
|||||||
else
|
else
|
||||||
checkbox_with_same_name = @form.find_field(name, CheckboxField)
|
checkbox_with_same_name = @form.find_field(name, CheckboxField)
|
||||||
|
|
||||||
if checkbox_with_same_name.to_param.nil?
|
if checkbox_with_same_name.to_param.blank?
|
||||||
super
|
super
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
|
@ -103,7 +103,7 @@ module Webrat
|
|||||||
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)
|
||||||
case [a[k], b[k]].map(&:class)
|
case [a[k], b[k]].map{|value| value.class}
|
||||||
when [Hash, Hash]
|
when [Hash, Hash]
|
||||||
a[k] = merge_hash_values(a[k], b[k])
|
a[k] = merge_hash_values(a[k], b[k])
|
||||||
b.delete(k)
|
b.delete(k)
|
||||||
|
@ -3,7 +3,7 @@ module Webrat
|
|||||||
|
|
||||||
def debug_log(message) # :nodoc:
|
def debug_log(message) # :nodoc:
|
||||||
return unless logger
|
return unless logger
|
||||||
logger.debug(message)
|
logger.debug message
|
||||||
end
|
end
|
||||||
|
|
||||||
def logger # :nodoc:
|
def logger # :nodoc:
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
Dir[File.join(File.dirname(__FILE__), "merb", "*.rb")].sort.each do |file|
|
||||||
|
require File.expand_path(file)
|
||||||
|
end
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
class Session
|
class Session
|
||||||
include Merb::Test::RequestHelper
|
include Merb::Test::RequestHelper
|
||||||
@ -30,7 +34,7 @@ module Webrat
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
def do_request(url, data, headers, method)
|
def do_request(url, data, headers, method)
|
||||||
@response = request(url, :params => data, :headers => headers, :method => method)
|
@response = request(url, :params => (data && data.any?) ? data : nil, :headers => headers, :method => method)
|
||||||
self.get(@response.headers['Location'], nil, @response.headers) if @response.status == 302
|
self.get(@response.headers['Location'], nil, @response.headers) if @response.status == 302
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
require "cgi"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
class ParamParser
|
class ParamParser
|
||||||
def self.parse_query_parameters(query_string)
|
def self.parse_query_parameters(query_string)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
require "cgi"
|
||||||
|
require "strscan"
|
||||||
|
|
||||||
class UrlEncodedPairParser < StringScanner #:nodoc:
|
class UrlEncodedPairParser < StringScanner #:nodoc:
|
||||||
attr_reader :top, :parent, :result
|
attr_reader :top, :parent, :result
|
||||||
|
|
||||||
|
@ -145,6 +145,18 @@ describe "fills_in" do
|
|||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should work if the input type is not set" do
|
||||||
|
@session.response_body = <<-EOS
|
||||||
|
<form method="post" action="/login">
|
||||||
|
<input id="user_email" name="user[email]" />
|
||||||
|
<input type="submit" />
|
||||||
|
</form>
|
||||||
|
EOS
|
||||||
|
@session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
||||||
|
@session.fills_in "user[email]", :with => "foo@example.com"
|
||||||
|
@session.clicks_button
|
||||||
|
end
|
||||||
|
|
||||||
it "should work with symbols" do
|
it "should work with symbols" do
|
||||||
@session.response_body = <<-EOS
|
@session.response_body = <<-EOS
|
||||||
<form method="post" action="/login">
|
<form method="post" action="/login">
|
||||||
|
@ -16,8 +16,6 @@ else
|
|||||||
require File.join(File.dirname(__FILE__), "webrat", "#{ENV["TEST_MODE"]}", "helper.rb")
|
require File.join(File.dirname(__FILE__), "webrat", "#{ENV["TEST_MODE"]}", "helper.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Spec::Runner.configure do |config|
|
Spec::Runner.configure do |config|
|
||||||
# Nothing to configure yet
|
# Nothing to configure yet
|
||||||
end
|
end
|
48
spec/webrat/merb/indifferent_access_spec.rb
Normal file
48
spec/webrat/merb/indifferent_access_spec.rb
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
||||||
|
require File.expand_path(File.dirname(__FILE__) + "/helper")
|
||||||
|
|
||||||
|
describe HashWithIndifferentAccess do
|
||||||
|
it "should not update constructor when not a hash" do
|
||||||
|
HashWithIndifferentAccess.should_receive(:update).never
|
||||||
|
HashWithIndifferentAccess.new('test')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should get the default for key" do
|
||||||
|
h = HashWithIndifferentAccess.new(:test => 'me')
|
||||||
|
h.should_receive(:super).never
|
||||||
|
|
||||||
|
h.default(:test).should == 'me'
|
||||||
|
end
|
||||||
|
|
||||||
|
context "a hash with a test value applied" do
|
||||||
|
|
||||||
|
setup do
|
||||||
|
@h = HashWithIndifferentAccess.new
|
||||||
|
@h[:test] = 'me'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should assign a new value" do
|
||||||
|
@h[:test].should == 'me'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return true if asked for existing key" do
|
||||||
|
@h.key?(:test).should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return array of values for keys" do
|
||||||
|
@h.values_at(:test).should == ['me']
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should merge with another hash" do
|
||||||
|
another = HashWithIndifferentAccess.new(:value => 'test')
|
||||||
|
@h.merge(another).values_at(:test, :value).should == ['me','test']
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should delete the key" do
|
||||||
|
@h.delete(:test)
|
||||||
|
@h.any?.should be_false
|
||||||
|
@h[:test].should be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
43
spec/webrat/merb/session_spec.rb
Normal file
43
spec/webrat/merb/session_spec.rb
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
||||||
|
require File.expand_path(File.dirname(__FILE__) + "/helper")
|
||||||
|
|
||||||
|
describe Webrat::Session do
|
||||||
|
|
||||||
|
it "should not pass empty params if data is and empty hash" do
|
||||||
|
session = Webrat::Session.new
|
||||||
|
response = OpenStruct.new
|
||||||
|
response.status = 200
|
||||||
|
session.should_receive(:request).with('url', {:params=> nil, :method=>"GET", :headers=>nil}).and_return(response)
|
||||||
|
session.get('url', {}, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
%w{post put delete}.each do |request_method|
|
||||||
|
it "should call do request with method #{request_method.upcase} for a #{request_method} call" do
|
||||||
|
session = Webrat::Session.new
|
||||||
|
response = OpenStruct.new
|
||||||
|
response.status = 200
|
||||||
|
|
||||||
|
session.should_receive(:request).with('url', {:params=>nil, :method=>request_method.upcase, :headers=>nil}).and_return(response)
|
||||||
|
session.send(request_method, 'url', {}, nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "a session with a response" do
|
||||||
|
|
||||||
|
setup do
|
||||||
|
@session = Webrat::Session.new
|
||||||
|
@response = OpenStruct.new
|
||||||
|
@response.status = 200
|
||||||
|
@response.body = 'test response'
|
||||||
|
@session.instance_variable_set(:@response, @response)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return body of a request as a response_body" do
|
||||||
|
@session.response_body.should == @response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return status of a request as a response_code" do
|
||||||
|
@session.response_code.should == @response.status
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user