Renaming fills_in to fill_in

This commit is contained in:
Bryan Helmkamp 2008-11-05 18:15:12 -05:00
parent 7b5da74cf1
commit eabc7b6c9e
6 changed files with 38 additions and 35 deletions

View File

@ -18,19 +18,19 @@ module Webrat
# it which will be sent when the form is submitted.
#
# Examples:
# fills_in "Email", :with => "user@example.com"
# fills_in "user[email]", :with => "user@example.com"
# fill_in "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>.
# <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.
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.raise_error_if_disabled
field.set(options[:with])
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
# as checked, so that the value will be submitted with the form.

View File

@ -25,7 +25,7 @@ module Webrat
end
def put(url, data, headers = nil)
do_request(:delete, url, data, headers)
do_request(:put, url, data, headers)
end
def delete(url, data, headers = nil)

View File

@ -13,16 +13,18 @@ module Webrat
alias_method :visit, :visits
def fills_in(field_identifier, options)
def fill_in(field_identifier, options)
locator = "webrat=#{Regexp.escape(field_identifier)}"
@selenium.type(locator, "#{options[:with]}")
end
alias_method :fills_in, :fill_in
def response_body
@selenium.get_html_source
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 == {}
pattern, options = nil, button_text_or_regexp
else
@ -32,7 +34,8 @@ module Webrat
@selenium.click("button=#{pattern}")
wait_for_result(options[:wait])
end
alias_method :click_button, :clicks_button
alias_method :clicks_button, :click_button
def clicks_link(link_text_or_regexp, options = {})
pattern = adjust_if_regexp(link_text_or_regexp)

View File

@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "fills_in" do
describe "fill_in" do
before do
@session = Webrat::TestSession.new
end
@ -14,7 +14,7 @@ describe "fills_in" do
</form>
EOS
@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
end
@ -26,7 +26,7 @@ describe "fills_in" do
</form>
EOS
@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
end
@ -36,7 +36,7 @@ describe "fills_in" do
</form>
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
it "should fail if input is disabled" do
@ -48,7 +48,7 @@ describe "fills_in" do
</form>
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
it "should allow overriding default form values" do
@ -60,7 +60,7 @@ describe "fills_in" do
</form>
EOS
@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
end
@ -76,7 +76,7 @@ describe "fills_in" do
EOS
@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
end
@ -92,7 +92,7 @@ describe "fills_in" do
EOS
@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
end
@ -104,7 +104,7 @@ describe "fills_in" do
</form>
EOS
lambda { @session.fills_in "mail", :with => "value" }.should raise_error
lambda { @session.fill_in "mail", :with => "value" }.should raise_error
end
it "should anchor label matches to word boundaries" do
@ -115,7 +115,7 @@ describe "fills_in" do
</form>
EOS
lambda { @session.fills_in "Email", :with => "value" }.should raise_error
lambda { @session.fill_in "Email", :with => "value" }.should raise_error
end
it "should work with inputs nested in labels" do
@ -129,7 +129,7 @@ describe "fills_in" do
</form>
EOS
@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
end
@ -141,7 +141,7 @@ describe "fills_in" do
</form>
EOS
@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
end
@ -153,7 +153,7 @@ describe "fills_in" do
</form>
EOS
@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
end
@ -166,7 +166,7 @@ describe "fills_in" do
</form>
EOS
@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
end
@ -179,7 +179,7 @@ describe "fills_in" do
</form>
EOS
@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
end
end

View File

@ -24,7 +24,7 @@ describe "visits" do
end
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

View File

@ -19,31 +19,31 @@ describe Webrat::RailsSession do
Webrat::RailsSession.new(integration_session).response_code.should == 42
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")
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")
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")
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")
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")
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")
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")
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")
end
@ -51,14 +51,14 @@ describe Webrat::RailsSession do
it "should just pass on the path" do
integration_session = mock("integration session", :https! => nil)
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")
end
end
context "the URL is https://" 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)
integration_session.should_receive(:https!).with(true)
rails_session.get("https://www.example.com/url", "data", "headers")
@ -67,7 +67,7 @@ describe Webrat::RailsSession do
context "the URL is http://" 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)
integration_session.should_receive(:https!).with(false)
rails_session.get("http://www.example.com/url", "data", "headers")