Skip to content

Commit

Permalink
Renaming fills_in to fill_in
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Nov 5, 2008
1 parent 7b5da74 commit eabc7b6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 35 deletions.
8 changes: 4 additions & 4 deletions lib/webrat/core/scope.rb
Expand Up @@ -18,19 +18,19 @@ def initialize(session, html, selector = nil)
# 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.
Expand Down
2 changes: 1 addition & 1 deletion lib/webrat/rails.rb
Expand Up @@ -25,7 +25,7 @@ def post(url, data, headers = nil)
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)
Expand Down
9 changes: 6 additions & 3 deletions lib/webrat/selenium/selenium_session.rb
Expand Up @@ -13,16 +13,18 @@ def visits(url)

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
Expand All @@ -32,7 +34,8 @@ def clicks_button(button_text_or_regexp = nil, options = {})
@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)
Expand Down
30 changes: 15 additions & 15 deletions spec/api/fills_in_spec.rb → spec/api/fill_in_spec.rb
@@ -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
Expand All @@ -14,7 +14,7 @@
</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

Expand All @@ -26,7 +26,7 @@
</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

Expand All @@ -36,7 +36,7 @@
</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
Expand All @@ -48,7 +48,7 @@
</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
Expand All @@ -60,7 +60,7 @@
</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

Expand All @@ -76,7 +76,7 @@
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

Expand All @@ -92,7 +92,7 @@
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

Expand All @@ -104,7 +104,7 @@
</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
Expand All @@ -115,7 +115,7 @@
</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
Expand All @@ -129,7 +129,7 @@
</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

Expand All @@ -141,7 +141,7 @@
</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

Expand All @@ -153,7 +153,7 @@
</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

Expand All @@ -166,7 +166,7 @@
</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

Expand All @@ -179,7 +179,7 @@
</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
2 changes: 1 addition & 1 deletion spec/api/visits_spec.rb
Expand Up @@ -24,7 +24,7 @@
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

Expand Down
22 changes: 11 additions & 11 deletions spec/webrat/rails/rails_session_spec.rb
Expand Up @@ -19,46 +19,46 @@
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

context "the URL is a full path" 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")
Expand All @@ -67,7 +67,7 @@

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")
Expand Down

0 comments on commit eabc7b6

Please sign in to comment.