Renaming fills_in to fill_in
This commit is contained in:
parent
7b5da74cf1
commit
eabc7b6c9e
@ -18,19 +18,19 @@ module Webrat
|
|||||||
# it which will be sent when the form is submitted.
|
# it which will be sent when the form is submitted.
|
||||||
#
|
#
|
||||||
# Examples:
|
# Examples:
|
||||||
# fills_in "Email", :with => "user@example.com"
|
# fill_in "Email", :with => "user@example.com"
|
||||||
# fills_in "user[email]", :with => "user@example.com"
|
# fill_in "user[email]", :with => "user@example.com"
|
||||||
#
|
#
|
||||||
# The field value is required, and must be specified in <tt>options[:with]</tt>.
|
# The field value is required, and must be specified in <tt>options[:with]</tt>.
|
||||||
# <tt>field</tt> can be either the value of a name attribute (i.e. <tt>user[email]</tt>)
|
# <tt>field</tt> can be either the value of a name attribute (i.e. <tt>user[email]</tt>)
|
||||||
# or the text inside a <tt><label></tt> element that points at the <tt><input></tt> field.
|
# or the text inside a <tt><label></tt> element that points at the <tt><input></tt> field.
|
||||||
def fills_in(id_or_name_or_label, options = {})
|
def fill_in(id_or_name_or_label, options = {})
|
||||||
field = find_field(id_or_name_or_label, TextField, TextareaField, PasswordField)
|
field = find_field(id_or_name_or_label, TextField, TextareaField, PasswordField)
|
||||||
field.raise_error_if_disabled
|
field.raise_error_if_disabled
|
||||||
field.set(options[:with])
|
field.set(options[:with])
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :fill_in, :fills_in
|
alias_method :fills_in, :fill_in
|
||||||
|
|
||||||
# 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.
|
||||||
|
@ -25,7 +25,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def put(url, data, headers = nil)
|
def put(url, data, headers = nil)
|
||||||
do_request(:delete, url, data, headers)
|
do_request(:put, url, data, headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(url, data, headers = nil)
|
def delete(url, data, headers = nil)
|
||||||
|
@ -13,16 +13,18 @@ module Webrat
|
|||||||
|
|
||||||
alias_method :visit, :visits
|
alias_method :visit, :visits
|
||||||
|
|
||||||
def fills_in(field_identifier, options)
|
def fill_in(field_identifier, options)
|
||||||
locator = "webrat=#{Regexp.escape(field_identifier)}"
|
locator = "webrat=#{Regexp.escape(field_identifier)}"
|
||||||
@selenium.type(locator, "#{options[:with]}")
|
@selenium.type(locator, "#{options[:with]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
alias_method :fills_in, :fill_in
|
||||||
|
|
||||||
def response_body
|
def response_body
|
||||||
@selenium.get_html_source
|
@selenium.get_html_source
|
||||||
end
|
end
|
||||||
|
|
||||||
def clicks_button(button_text_or_regexp = nil, options = {})
|
def click_button(button_text_or_regexp = nil, options = {})
|
||||||
if button_text_or_regexp.is_a?(Hash) && options == {}
|
if button_text_or_regexp.is_a?(Hash) && options == {}
|
||||||
pattern, options = nil, button_text_or_regexp
|
pattern, options = nil, button_text_or_regexp
|
||||||
else
|
else
|
||||||
@ -32,7 +34,8 @@ module Webrat
|
|||||||
@selenium.click("button=#{pattern}")
|
@selenium.click("button=#{pattern}")
|
||||||
wait_for_result(options[:wait])
|
wait_for_result(options[:wait])
|
||||||
end
|
end
|
||||||
alias_method :click_button, :clicks_button
|
|
||||||
|
alias_method :clicks_button, :click_button
|
||||||
|
|
||||||
def clicks_link(link_text_or_regexp, options = {})
|
def clicks_link(link_text_or_regexp, options = {})
|
||||||
pattern = adjust_if_regexp(link_text_or_regexp)
|
pattern = adjust_if_regexp(link_text_or_regexp)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
||||||
|
|
||||||
describe "fills_in" do
|
describe "fill_in" do
|
||||||
before do
|
before do
|
||||||
@session = Webrat::TestSession.new
|
@session = Webrat::TestSession.new
|
||||||
end
|
end
|
||||||
@ -14,7 +14,7 @@ describe "fills_in" do
|
|||||||
</form>
|
</form>
|
||||||
EOS
|
EOS
|
||||||
@session.should_receive(:post).with("/login", "user" => {"text" => "filling text area"})
|
@session.should_receive(:post).with("/login", "user" => {"text" => "filling text area"})
|
||||||
@session.fills_in "User Text", :with => "filling text area"
|
@session.fill_in "User Text", :with => "filling text area"
|
||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ describe "fills_in" do
|
|||||||
</form>
|
</form>
|
||||||
EOS
|
EOS
|
||||||
@session.should_receive(:post).with("/login", "user" => {"text" => "pass"})
|
@session.should_receive(:post).with("/login", "user" => {"text" => "pass"})
|
||||||
@session.fills_in "user_text", :with => "pass"
|
@session.fill_in "user_text", :with => "pass"
|
||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ describe "fills_in" do
|
|||||||
</form>
|
</form>
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
lambda { @session.fills_in "Email", :with => "foo@example.com" }.should raise_error
|
lambda { @session.fill_in "Email", :with => "foo@example.com" }.should raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should fail if input is disabled" do
|
it "should fail if input is disabled" do
|
||||||
@ -48,7 +48,7 @@ describe "fills_in" do
|
|||||||
</form>
|
</form>
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
lambda { @session.fills_in "Email", :with => "foo@example.com" }.should raise_error
|
lambda { @session.fill_in "Email", :with => "foo@example.com" }.should raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should allow overriding default form values" do
|
it "should allow overriding default form values" do
|
||||||
@ -60,7 +60,7 @@ describe "fills_in" do
|
|||||||
</form>
|
</form>
|
||||||
EOS
|
EOS
|
||||||
@session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
@session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
||||||
@session.fills_in "user[email]", :with => "foo@example.com"
|
@session.fill_in "user[email]", :with => "foo@example.com"
|
||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ describe "fills_in" do
|
|||||||
EOS
|
EOS
|
||||||
|
|
||||||
@session.should_receive(:post).with("/login", "user" => {"mail1" => "", "mail2" => "value"})
|
@session.should_receive(:post).with("/login", "user" => {"mail1" => "", "mail2" => "value"})
|
||||||
@session.fills_in "Some", :with => "value"
|
@session.fill_in "Some", :with => "value"
|
||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ describe "fills_in" do
|
|||||||
EOS
|
EOS
|
||||||
|
|
||||||
@session.should_receive(:post).with("/login", "user" => {"mail1" => "value", "mail2" => ""})
|
@session.should_receive(:post).with("/login", "user" => {"mail1" => "value", "mail2" => ""})
|
||||||
@session.fills_in "Some mail", :with => "value"
|
@session.fill_in "Some mail", :with => "value"
|
||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ describe "fills_in" do
|
|||||||
</form>
|
</form>
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
lambda { @session.fills_in "mail", :with => "value" }.should raise_error
|
lambda { @session.fill_in "mail", :with => "value" }.should raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should anchor label matches to word boundaries" do
|
it "should anchor label matches to word boundaries" do
|
||||||
@ -115,7 +115,7 @@ describe "fills_in" do
|
|||||||
</form>
|
</form>
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
lambda { @session.fills_in "Email", :with => "value" }.should raise_error
|
lambda { @session.fill_in "Email", :with => "value" }.should raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should work with inputs nested in labels" do
|
it "should work with inputs nested in labels" do
|
||||||
@ -129,7 +129,7 @@ describe "fills_in" do
|
|||||||
</form>
|
</form>
|
||||||
EOS
|
EOS
|
||||||
@session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
@session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
||||||
@session.fills_in "Email", :with => "foo@example.com"
|
@session.fill_in "Email", :with => "foo@example.com"
|
||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ describe "fills_in" do
|
|||||||
</form>
|
</form>
|
||||||
EOS
|
EOS
|
||||||
@session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
@session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
||||||
@session.fills_in "user[email]", :with => "foo@example.com"
|
@session.fill_in "user[email]", :with => "foo@example.com"
|
||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ describe "fills_in" do
|
|||||||
</form>
|
</form>
|
||||||
EOS
|
EOS
|
||||||
@session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
@session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
||||||
@session.fills_in "user[email]", :with => "foo@example.com"
|
@session.fill_in "user[email]", :with => "foo@example.com"
|
||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ describe "fills_in" do
|
|||||||
</form>
|
</form>
|
||||||
EOS
|
EOS
|
||||||
@session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
@session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
||||||
@session.fills_in :email, :with => "foo@example.com"
|
@session.fill_in :email, :with => "foo@example.com"
|
||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ describe "fills_in" do
|
|||||||
</form>
|
</form>
|
||||||
EOS
|
EOS
|
||||||
@session.should_receive(:post).with("/users", "user" => {"phone" => "+1 22 33"})
|
@session.should_receive(:post).with("/users", "user" => {"phone" => "+1 22 33"})
|
||||||
@session.fills_in 'Phone', :with => "+1 22 33"
|
@session.fill_in 'Phone', :with => "+1 22 33"
|
||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -24,7 +24,7 @@ describe "visits" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should require a visit before manipulating page" do
|
it "should require a visit before manipulating page" do
|
||||||
lambda { @session.fills_in "foo", :with => "blah" }.should raise_error
|
lambda { @session.fill_in "foo", :with => "blah" }.should raise_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,31 +19,31 @@ describe Webrat::RailsSession do
|
|||||||
Webrat::RailsSession.new(integration_session).response_code.should == 42
|
Webrat::RailsSession.new(integration_session).response_code.should == 42
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should delegate get to get_via_redirect on the integration session" do
|
it "should delegate get to request_via_redirect on the integration session" do
|
||||||
integration_session = mock("integration session")
|
integration_session = mock("integration session")
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
rails_session = Webrat::RailsSession.new(integration_session)
|
||||||
integration_session.should_receive(:get_via_redirect).with("url", "data", "headers")
|
integration_session.should_receive(:request_via_redirect).with(:get, "url", "data", "headers")
|
||||||
rails_session.get("url", "data", "headers")
|
rails_session.get("url", "data", "headers")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should delegate post to post_via_redirect on the integration session" do
|
it "should delegate post to request_via_redirect on the integration session" do
|
||||||
integration_session = mock("integration session")
|
integration_session = mock("integration session")
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
rails_session = Webrat::RailsSession.new(integration_session)
|
||||||
integration_session.should_receive(:post_via_redirect).with("url", "data", "headers")
|
integration_session.should_receive(:request_via_redirect).with(:post, "url", "data", "headers")
|
||||||
rails_session.post("url", "data", "headers")
|
rails_session.post("url", "data", "headers")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should delegate put to put_via_redirect on the integration session" do
|
it "should delegate put to request_via_redirect on the integration session" do
|
||||||
integration_session = mock("integration session")
|
integration_session = mock("integration session")
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
rails_session = Webrat::RailsSession.new(integration_session)
|
||||||
integration_session.should_receive(:put_via_redirect).with("url", "data", "headers")
|
integration_session.should_receive(:request_via_redirect).with(:put, "url", "data", "headers")
|
||||||
rails_session.put("url", "data", "headers")
|
rails_session.put("url", "data", "headers")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should delegate delete to delete_via_redirect on the integration session" do
|
it "should delegate delete to request_via_redirect on the integration session" do
|
||||||
integration_session = mock("integration session")
|
integration_session = mock("integration session")
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
rails_session = Webrat::RailsSession.new(integration_session)
|
||||||
integration_session.should_receive(:delete_via_redirect).with("url", "data", "headers")
|
integration_session.should_receive(:request_via_redirect).with(:delete, "url", "data", "headers")
|
||||||
rails_session.delete("url", "data", "headers")
|
rails_session.delete("url", "data", "headers")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -51,14 +51,14 @@ describe Webrat::RailsSession do
|
|||||||
it "should just pass on the path" do
|
it "should just pass on the path" do
|
||||||
integration_session = mock("integration session", :https! => nil)
|
integration_session = mock("integration session", :https! => nil)
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
rails_session = Webrat::RailsSession.new(integration_session)
|
||||||
integration_session.should_receive(:get_via_redirect).with("/url", "data", "headers")
|
integration_session.should_receive(:request_via_redirect).with(:get, "/url", "data", "headers")
|
||||||
rails_session.get("http://www.example.com/url", "data", "headers")
|
rails_session.get("http://www.example.com/url", "data", "headers")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "the URL is https://" do
|
context "the URL is https://" do
|
||||||
it "should call #https! with true before the request" do
|
it "should call #https! with true before the request" do
|
||||||
integration_session = mock("integration session", :get_via_redirect => nil)
|
integration_session = mock("integration session", :request_via_redirect => nil)
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
rails_session = Webrat::RailsSession.new(integration_session)
|
||||||
integration_session.should_receive(:https!).with(true)
|
integration_session.should_receive(:https!).with(true)
|
||||||
rails_session.get("https://www.example.com/url", "data", "headers")
|
rails_session.get("https://www.example.com/url", "data", "headers")
|
||||||
@ -67,7 +67,7 @@ describe Webrat::RailsSession do
|
|||||||
|
|
||||||
context "the URL is http://" do
|
context "the URL is http://" do
|
||||||
it "should call #https! with true before the request" do
|
it "should call #https! with true before the request" do
|
||||||
integration_session = mock("integration session", :get_via_redirect => nil)
|
integration_session = mock("integration session", :request_via_redirect => nil)
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
rails_session = Webrat::RailsSession.new(integration_session)
|
||||||
integration_session.should_receive(:https!).with(false)
|
integration_session.should_receive(:https!).with(false)
|
||||||
rails_session.get("http://www.example.com/url", "data", "headers")
|
rails_session.get("http://www.example.com/url", "data", "headers")
|
||||||
|
Loading…
Reference in New Issue
Block a user