Class: RSpec::TagMatchers::HasForm

Inherits:
HasTag
  • Object
show all
Defined in:
lib/rspec/tag_matchers/has_form.rb

Overview

A matcher that matches <form> tags.

Instance Method Summary collapse

Methods inherited from HasTag

#description, #failure_message, #matches?, #negative_failure_message, #test_attribute, #with_attribute, #with_content, #with_count, #with_criteria

Methods included from RSpec::TagMatchers::Helpers::SentenceHelper

#make_sentence

Constructor Details

#initializeHasForm

Initializes a HasForm matcher that matches form elements.



28
29
30
# File 'lib/rspec/tag_matchers/has_form.rb', line 28

def initialize
  super(:form)
end

Instance Method Details

#with_action(action) ⇒ HasForm

Specifies that the form must target the given URL as its action. It compares the action attribute on the form tag to the action argument passed to with_action.

Parameters:

  • action (String, Regexp)

    The URL that the form should target.

Returns:



53
54
55
# File 'lib/rspec/tag_matchers/has_form.rb', line 53

def with_action(action)
  with_attribute(:action => action)
end

#with_verb(verb) ⇒ HasForm Also known as: with_method

Specifies that the form will use the given HTTP verb, following Rails conventions. It first looks for a method override value (a hidden input named _method). If the method override value doesn’t exist, then it looks for the method attribute on the form tag. Whichever value it finds will be compared to the value passed in as the verb argument to with_verb.

Parameters:

  • verb (Symbol)

    An HTTP verb, e.g., :get, :post, :put, or :delete.

Returns:



40
41
42
43
44
# File 'lib/rspec/tag_matchers/has_form.rb', line 40

def with_verb(verb)
  with_criteria do |element|
    matches_verb?(element, verb)
  end
end