Updating usages of "selects" methods to "select"

This commit is contained in:
Bryan Helmkamp 2008-11-23 14:02:51 -05:00
parent f03905e6b6
commit db0488c0e2
6 changed files with 60 additions and 58 deletions

View File

@ -90,10 +90,10 @@ module Webrat
# a label. Stores the option's value to be sent when the form is submitted.
#
# Examples:
# selects "January"
# selects "February", :from => "event_month"
# selects "February", :from => "Event Month"
def selects(option_text, options = {})
# select "January"
# select "February", :from => "event_month"
# select "February", :from => "Event Month"
def select(option_text, options = {})
if option = find_select_option(option_text, options[:from])
option.choose
else
@ -102,7 +102,7 @@ module Webrat
end
end
alias_method :select, :selects
alias_method :selects, :select
DATE_TIME_SUFFIXES = {
:year => '1i',
@ -123,11 +123,11 @@ module Webrat
# by assigning <tt>options[:id_prefix]</tt>.
#
# Examples:
# selects_date "January 23, 2004"
# selects_date "April 26, 1982", :from => "Birthday"
# selects_date Date.parse("December 25, 2000"), :from => "Event"
# selects_date "April 26, 1982", :id_prefix => 'birthday'
def selects_date(date_to_select, options ={})
# select_date "January 23, 2004"
# select_date "April 26, 1982", :from => "Birthday"
# select_date Date.parse("December 25, 2000"), :from => "Event"
# select_date "April 26, 1982", :id_prefix => 'birthday'
def select_date(date_to_select, options ={})
date = date_to_select.is_a?(Date) || date_to_select.is_a?(Time) ?
date_to_select : Date.parse(date_to_select)
@ -137,12 +137,12 @@ module Webrat
$1
end
selects date.year, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:year]}"
selects date.strftime('%B'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:month]}"
selects date.day, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:day]}"
select date.year, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:year]}"
select date.strftime('%B'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:month]}"
select date.day, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:day]}"
end
alias_method :select_date, :selects_date
alias_method :selects_date, :select_date
# Verifies that time elements (hour, minute) exist on the current page
# with the specified values. You can optionally restrict the search to a specific
@ -158,11 +158,11 @@ module Webrat
# 24 hour select boxes, and not 12 hours with AM/PM.
#
# Examples:
# selects_time "9:30"
# selects_date "3:30PM", :from => "Party Time"
# selects_date Time.parse("10:00PM"), :from => "Event"
# selects_date "10:30AM", :id_prefix => 'meeting'
def selects_time(time_to_select, options ={})
# select_time "9:30"
# select_date "3:30PM", :from => "Party Time"
# select_date Time.parse("10:00PM"), :from => "Event"
# select_date "10:30AM", :id_prefix => 'meeting'
def select_time(time_to_select, options ={})
time = time_to_select.is_a?(Time) ? time_to_select : Time.parse(time_to_select)
id_prefix = locate_id_prefix(options) do
@ -171,31 +171,31 @@ module Webrat
$1
end
selects time.hour.to_s.rjust(2,'0'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:hour]}"
selects time.min.to_s.rjust(2,'0'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:minute]}"
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]}"
end
alias_method :select_time, :selects_time
alias_method :selects_time, :select_time
# Verifies and selects all the date and time elements on the current page.
# See #selects_time and #selects_date for more details and available options.
# See #select_time and #select_date for more details and available options.
#
# Examples:
# selects_datetime "January 23, 2004 10:30AM"
# selects_datetime "April 26, 1982 7:00PM", :from => "Birthday"
# selects_datetime Time.parse("December 25, 2000 15:30"), :from => "Event"
# selects_datetime "April 26, 1982 5:50PM", :id_prefix => 'birthday'
def selects_datetime(time_to_select, options ={})
# select_datetime "January 23, 2004 10:30AM"
# select_datetime "April 26, 1982 7:00PM", :from => "Birthday"
# select_datetime Time.parse("December 25, 2000 15:30"), :from => "Event"
# select_datetime "April 26, 1982 5:50PM", :id_prefix => 'birthday'
def select_datetime(time_to_select, options ={})
time = time_to_select.is_a?(Time) ? time_to_select : Time.parse(time_to_select)
options[:id_prefix] ||= (options[:from] ? find_field_with_id(options[:from]) : nil)
selects_date time, options
selects_time time, options
select_date time, options
select_time time, options
end
alias_method :select_datetime, :selects_datetime
alias_method :selects_datetime, :select_datetime
# 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

View File

@ -79,7 +79,7 @@ module Webrat
wait_for_effects
end
def selects(option_text, options = {})
def select(option_text, options = {})
id_or_name_or_label = options[:from]
if id_or_name_or_label
@ -90,6 +90,8 @@ module Webrat
@selenium.select(select_locator, option_text)
end
alias_method :selects, :select
def choose(label_text)
@selenium.click("webrat=#{label_text}")
end

View File

@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "selects_date" do
describe "select_date" do
it "should send the values for each individual date component" do
with_html <<-HTML
<form action="/appointments" method="post">
@ -19,7 +19,7 @@ describe "selects_date" do
HTML
webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"})
selects_date "December 25, 2003", :from => "Date"
select_date "December 25, 2003", :from => "Date"
click_button
end
@ -41,7 +41,7 @@ describe "selects_date" do
HTML
webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"})
selects_date Date.parse("December 25, 2003"), :from => "date"
select_date Date.parse("December 25, 2003"), :from => "date"
click_button
end
@ -62,7 +62,7 @@ describe "selects_date" do
HTML
webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"})
selects_date "December 25, 2003"
select_date "December 25, 2003"
click_button
end
@ -74,7 +74,7 @@ describe "selects_date" do
</form>
HTML
lambda { selects_date "December 25, 2003", :from => "date" }.should raise_error
lambda { select_date "December 25, 2003", :from => "date" }.should raise_error
end
end

View File

@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "selects_datetime" do
describe "select_datetime" do
it "should send the values for each individual date and time components" do
with_html <<-HTML
<form action="/appointments" method="post">
@ -25,7 +25,7 @@ describe "selects_datetime" do
HTML
webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"time(1i)" => '2003', "time(2i)" => "12", "time(3i)" => "25", "time(4i)" => "09", "time(5i)" => "30"})
selects_datetime "December 25, 2003 9:30", :from => "Time"
select_datetime "December 25, 2003 9:30", :from => "Time"
click_button
end
@ -80,7 +80,7 @@ describe "selects_datetime" do
HTML
webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"time(1i)" => '2003', "time(2i)" => "12", "time(3i)" => "25", "time(4i)" => "09", "time(5i)" => "30"})
selects_datetime "December 25, 2003 9:30"
select_datetime "December 25, 2003 9:30"
click_button
end
@ -92,7 +92,7 @@ describe "selects_datetime" do
</form>
HTML
lambda { selects_datetime "December 25, 2003 9:30", :from => "Time" }.should raise_error
lambda { select_datetime "December 25, 2003 9:30", :from => "Time" }.should raise_error
end
end

View File

@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "selects" do
describe "select" do
it "should fail with a helpful message when option not found" do
with_html <<-HTML
<form method="get" action="/login">
@ -8,8 +8,8 @@ describe "selects" do
</form>
HTML
lambda { selects "February", :from => "month" }.should raise_error(
Exception, "The 'February' option was not found in the 'month' select box")
lambda { select "February", :from => "month" }.should raise_error(Webrat::NotFoundError,
"The 'February' option was not found in the 'month' select box")
end
it "should fail if option not found in list specified by element name" do
@ -20,7 +20,7 @@ describe "selects" do
</form>
HTML
lambda { selects "February", :from => "year" }.should raise_error
lambda { select "February", :from => "year" }.should raise_error(Webrat::NotFoundError)
end
it "should fail if specified list not found" do
@ -30,7 +30,7 @@ describe "selects" do
</form>
HTML
lambda { selects "February", :from => "year" }.should raise_error
lambda { select "February", :from => "year" }.should raise_error
end
@ -42,7 +42,7 @@ describe "selects" do
</form>
HTML
lambda { selects "January", :from => "month" }.should raise_error
lambda { select "January", :from => "month" }.should raise_error
end
it "should send value from option" do
@ -53,7 +53,7 @@ describe "selects" do
</form>
HTML
webrat_session.should_receive(:post).with("/login", "month" => "1")
selects "January", :from => "month"
select "January", :from => "month"
click_button
end
@ -65,7 +65,7 @@ describe "selects" do
</form>
HTML
webrat_session.should_receive(:post).with("/login", "encoded" => "A & B")
selects "Encoded", :from => "encoded"
select "Encoded", :from => "encoded"
click_button
end
@ -88,7 +88,7 @@ describe "selects" do
</form>
HTML
webrat_session.should_receive(:post).with("/login", "month" => "1")
selects "January"
select "January"
click_button
end
@ -101,7 +101,7 @@ describe "selects" do
</form>
HTML
webrat_session.should_receive(:post).with("/login", "start_month" => "s1", "end_month" => "e1")
selects "January", :from => "end_month"
select "January", :from => "end_month"
click_button
end
@ -116,7 +116,7 @@ describe "selects" do
</form>
HTML
webrat_session.should_receive(:post).with("/login", "start_month" => "s1", "end_month" => "e1")
selects "January", :from => "End Month"
select "January", :from => "End Month"
click_button
end
@ -128,7 +128,7 @@ describe "selects" do
</form>
HTML
webrat_session.should_receive(:post).with("/login", "month" => "January")
selects "January", :from => "month"
select "January", :from => "month"
click_button
end
@ -140,7 +140,7 @@ describe "selects" do
</form>
HTML
webrat_session.should_receive(:post).with("/login", "month" => "January")
selects(/jan/i)
select /jan/i
click_button
end
@ -153,8 +153,8 @@ describe "selects" do
HTML
lambda {
selects(/feb/i)
}.should raise_error
select /feb/i
}.should raise_error(Webrat::NotFoundError)
end
it "should find option by regexp in list specified by label" do
@ -168,7 +168,7 @@ describe "selects" do
</form>
HTML
webrat_session.should_receive(:post).with("/login", "start_month" => "s1", "end_month" => "e1")
selects(/jan/i, :from => "End Month")
select /jan/i, :from => "End Month"
click_button
end
end

View File

@ -16,7 +16,7 @@ describe "select_time" do
HTML
webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"time(4i)" => "09", "time(5i)" => "30"})
selects_time "9:30AM", :from => "Time"
select_time "9:30AM", :from => "Time"
click_button
end