Class: Spec::Matchers::FormMatcher::HaveForm
- Inherits:
-
Object
- Object
- Spec::Matchers::FormMatcher::HaveForm
- Defined in:
- lib/rspec_form_matcher.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#submit_button ⇒ Object
readonly
Returns the value of attribute submit_button.
Instance Method Summary collapse
- #checkbox(field_name, *values) ⇒ Object
- #failure_message ⇒ Object
- #hidden(field_name, value = nil) ⇒ Object
-
#initialize(action = nil) ⇒ HaveForm
constructor
A new instance of HaveForm.
- #input(type, field_name, value = nil) ⇒ Object
- #matches?(stringlike) ⇒ Boolean
- #negative_failure_message ⇒ Object
- #password(field_name, value = nil) ⇒ Object
- #radio(field_name, *values) ⇒ Object
- #tag(tag, attributes = {}) ⇒ Object
- #text(field_name, value = nil) ⇒ Object
- #with(method, *args) ⇒ Object (also: #and_with)
Constructor Details
#initialize(action = nil) ⇒ HaveForm
Returns a new instance of HaveForm.
7 8 9 10 11 12 13 14 15 |
# File 'lib/rspec_form_matcher.rb', line 7 def initialize(action = nil) case action when Hash then action.each { |m, a| @method, @action = m, a } when String, Regexp then @action = action end @tags = [] @checks = [] end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
5 6 7 |
# File 'lib/rspec_form_matcher.rb', line 5 def action @action end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
5 6 7 |
# File 'lib/rspec_form_matcher.rb', line 5 def field @field end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
5 6 7 |
# File 'lib/rspec_form_matcher.rb', line 5 def method @method end |
#submit_button ⇒ Object (readonly)
Returns the value of attribute submit_button.
5 6 7 |
# File 'lib/rspec_form_matcher.rb', line 5 def @submit_button end |
Instance Method Details
#checkbox(field_name, *values) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/rspec_form_matcher.rb', line 63 def checkbox(field_name, *values) if values.empty? input(:checkbox, field_name) else values.each { |v| input(:checkbox, field_name, v) } end return self end |
#failure_message ⇒ Object
78 79 80 |
# File 'lib/rspec_form_matcher.rb', line 78 def "Specified form (XPath: << #{@xpath} >>) not found in document: \n#{@document.to_s}" end |
#hidden(field_name, value = nil) ⇒ Object
34 35 36 |
# File 'lib/rspec_form_matcher.rb', line 34 def hidden(field_name, value = nil) input(:hidden, field_name, value) end |
#input(type, field_name, value = nil) ⇒ Object
23 24 25 26 27 |
# File 'lib/rspec_form_matcher.rb', line 23 def input(type, field_name, value = nil) attributes = { :type => type, :name => field_name } attributes[:value] = value if value tag('input', attributes) end |
#matches?(stringlike) ⇒ Boolean
72 73 74 75 76 |
# File 'lib/rspec_form_matcher.rb', line 72 def matches?(stringlike) @document = document(stringlike) @xpath = build_xpath_query check_xpath! end |
#negative_failure_message ⇒ Object
82 83 84 |
# File 'lib/rspec_form_matcher.rb', line 82 def "Unexpectedly found specified form (XPath: << #{@xpath} >>) in document: \n#{@document.to_s}" end |
#password(field_name, value = nil) ⇒ Object
59 60 61 |
# File 'lib/rspec_form_matcher.rb', line 59 def password(field_name, value = nil) input(:password, field_name, value) end |
#radio(field_name, *values) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/rspec_form_matcher.rb', line 50 def radio(field_name, *values) if values.empty? input(:radio, field_name) else values.each { |v| input(:radio, field_name, v) } end return self end |
#tag(tag, attributes = {}) ⇒ Object
29 30 31 32 |
# File 'lib/rspec_form_matcher.rb', line 29 def tag(tag, attributes = {}) @checks << tag_xpath(tag, attributes) return self end |
#text(field_name, value = nil) ⇒ Object
46 47 48 |
# File 'lib/rspec_form_matcher.rb', line 46 def text(field_name, value = nil) input(:text, field_name, value) end |
#with(method, *args) ⇒ Object Also known as: and_with
17 18 19 |
# File 'lib/rspec_form_matcher.rb', line 17 def with(method, *args) self.send(method, *args) end |