Class ActionController::Integration::Session
In: lib/webrat/rails_extensions.rb
lib/webrat/session.rb
Parent: Object

Methods

Public Instance methods

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.

Example:

  checks 'Remember Me'

[Source]

    # File lib/webrat/session.rb, line 86
86:       def checks(field)
87:         checkbox = find_field_by_name_or_label(field)
88:         return flunk("Could not find checkbox #{field.inspect}") if checkbox.nil?
89:         return flunk("Input #{checkbox.inspect} is not a checkbox") unless checkbox.attributes['type'] == 'checkbox'
90:         add_form_data(checkbox, checkbox.attributes["value"] || "on")
91:       end

Verifies that a submit button exists for the form, then submits the form, follows any redirects, and verifies the final page was successful.

Example:

  clicks_button "Login"
  clicks_button

The URL and HTTP method for the form submission are automatically read from the action and method attributes of the <form> element.

[Source]

     # File lib/webrat/session.rb, line 114
114:       def clicks_button(value = nil)
115:         button = value ? find_button(value) : submit_buttons.first
116:         return flunk("Could not find button #{value.inspect}") if button.nil?
117:         add_form_data(button, button.attributes["value"]) unless button.attributes["name"].blank?
118:         submit_form(form_for_node(button))
119:       end

Works like clicks_link, but issues a DELETE request instead of a GET

Example:

  clicks_delete_link "Log out"

[Source]

    # File lib/webrat/session.rb, line 29
29:       def clicks_delete_link(link_text)
30:         clicks_link_with_method(link_text, :delete)
31:       end

Issues a GET request for the URL pointed to by a link on the current page, follows any redirects, and verifies the final page load was successful.

Example:

  clicks_link "Sign up"

[Source]

    # File lib/webrat/session.rb, line 21
21:       def clicks_link(link_text)
22:         clicks_link_with_method(link_text, :get)
23:       end

Works like clicks_link, but issues a POST request instead of a GET

Example:

  clicks_post_link "Vote"

[Source]

    # File lib/webrat/session.rb, line 37
37:       def clicks_post_link(link_text)
38:         clicks_link_with_method(link_text, :post)
39:       end

Works like clicks_link, but issues a PUT request instead of a GET

Example:

  clicks_put_link "Update profile"

[Source]

    # File lib/webrat/session.rb, line 45
45:       def clicks_put_link(link_text)
46:         clicks_link_with_method(link_text, :put)
47:       end

Waiting for dev.rubyonrails.org/ticket/10497 to be committed.

[Source]

    # File lib/webrat/rails_extensions.rb, line 13
13:       def delete_via_redirect(path, parameters = {}, headers = {})
14:         delete path, parameters, headers
15:         follow_redirect! while redirect?
16:         status
17:       end

Verifies an input field or textarea exists on the current page, and stores a value for 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"

The field value is required, and must be specified in options[:with]. field can be either the value of a name attribute (i.e. user[email]) or the text inside a <label> element that points at the <input> field.

[Source]

    # File lib/webrat/session.rb, line 59
59:       def fills_in(field, options = {})
60:         value = options[:with]
61:         return flunk("No value was provided") if value.nil?
62:         input = find_field_by_name_or_label(field)
63:         return flunk("Could not find input #{field.inspect}") if input.nil?
64:         add_form_data(input, value)
65:         # TODO - Set current form
66:       end

Waiting for dev.rubyonrails.org/ticket/10497 to be committed.

[Source]

    # File lib/webrat/rails_extensions.rb, line 6
 6:       def put_via_redirect(path, parameters = {}, headers = {})
 7:         put path, parameters, headers
 8:         follow_redirect! while redirect?
 9:         status
10:       end

Verifies that a an option element exists on the current page with the specified text. Stores the option‘s value to be sent when the form is submitted.

Example:

  selects "January"

[Source]

    # File lib/webrat/session.rb, line 73
73:       def selects(option_text)
74:         option = find_option_by_value(option_text)
75:         return flunk("Could not find option #{option_text.inspect}") if option.nil?
76:         select = option.parent
77:         add_form_data(select, option.attributes["value"] || option.innerHTML)
78:         # TODO - Set current form
79:       end

Verifies that an input checkbox exists on the current page and marks it as unchecked, so that the value will not be submitted with the form.

Example:

  unchecks 'Remember Me'

[Source]

     # File lib/webrat/session.rb, line 98
 98:       def unchecks(field)
 99:         checkbox = find_field_by_name_or_label(field)
100:         return flunk("Could not find checkbox #{field.inspect}") if checkbox.nil?
101:         return flunk("Input #{checkbox.inspect} is not a checkbox") unless checkbox.attributes['type'] == 'checkbox'
102:         remove_form_data(checkbox)
103:       end

Issues a GET request for a page, follows any redirects, and verifies the final page load was successful.

Example:

  visits "/"

[Source]

    # File lib/webrat/session.rb, line 12
12:       def visits(path)
13:         request_page(:get, path)
14:       end

Protected Instance methods

[Source]

     # File lib/webrat/session.rb, line 126
126:       def clicks_link_with_method(link_text, http_method)
127:         link = links.detect { |el| el.innerHTML =~ /#{link_text}/i }
128:         return flunk("No link with text #{link_text.inspect} was found") if link.nil?
129:         request_page(http_method, link.attributes["href"])
130:       end

[Source]

     # File lib/webrat/session.rb, line 305
305:       def textarea_fields # :nodoc
306:         (dom / "textarea")
307:       end

[Validate]