Class: Suhyo::ViewMatchers::HaveRestfulForm
- Inherits:
-
Webrat::Matchers::HaveSelector
- Object
- Webrat::Matchers::HaveSelector
- Suhyo::ViewMatchers::HaveRestfulForm
- Defined in:
- lib/suhyo/view_matchers.rb
Instance Method Summary collapse
- #attributes_message ⇒ Object
-
#failure_message ⇒ Object
Messages.
-
#initialize(method, options = {}, &block) ⇒ HaveRestfulForm
constructor
A new instance of HaveRestfulForm.
- #matches(stringlike) ⇒ Object
- #matches?(stringlike, &block) ⇒ Boolean
- #matches_hidden_field?(stringlike) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(method, options = {}, &block) ⇒ HaveRestfulForm
Returns a new instance of HaveRestfulForm.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/suhyo/view_matchers.rb', line 107 def initialize(method, = {}, &block) raise(ArgumentError, "Expected options to be a Hash, but got #{.inspect}") unless .is_a?(Hash) @options = @method = method.to_s.downcase unless @method == 'get' or @method == 'post' or @method == 'put' or @method == 'delete' raise(ArgumentError, "Expected method to be 'get', 'post', 'put', or 'delete', but got #{method.inspect}") end # browser_method is the method the browser actually uses, either GET or POST @browser_method = (method == 'get') ? 'get' : 'post' if ancestors = @options.delete(:ancestors) @expected = ancestors + ' form' else @expected = 'form' end @options.merge!(:method => @browser_method) @block = block end |
Instance Method Details
#attributes_message ⇒ Object
156 157 158 159 160 |
# File 'lib/suhyo/view_matchers.rb', line 156 def attrs = @options.dup attrs.delete(:method) attrs.empty? ? nil : ' with attributes ' + attrs.inspect end |
#failure_message ⇒ Object
Messages
148 149 150 |
# File 'lib/suhyo/view_matchers.rb', line 148 def "expected following output to contain a #{@method.upcase} form#{}:\n\n#{@document}" end |
#matches(stringlike) ⇒ Object
125 126 127 128 |
# File 'lib/suhyo/view_matchers.rb', line 125 def matches(stringlike) # Cache it, because we're going to use it again in matches_hidden_field? @matches ||= super(stringlike) end |
#matches?(stringlike, &block) ⇒ Boolean
130 131 132 |
# File 'lib/suhyo/view_matchers.rb', line 130 def matches?(stringlike, &block) super(stringlike, &block) and matches_hidden_field?(stringlike) end |
#matches_hidden_field?(stringlike) ⇒ Boolean
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/suhyo/view_matchers.rb', line 134 def matches_hidden_field?(stringlike) form = matches(stringlike) case @method when 'get', 'post' !::Webrat::Matchers::HaveSelector.new('input', :name => '_method').matches?(form) when 'put' ::Webrat::Matchers::HaveSelector.new('input', :name => '_method', :value => 'put').matches?(form) when 'delete' ::Webrat::Matchers::HaveSelector.new('input', :name => '_method', :value => 'delete').matches?(form) end end |
#negative_failure_message ⇒ Object
152 153 154 |
# File 'lib/suhyo/view_matchers.rb', line 152 def "expected following output to omit a #{@method.upcase} form#{}:\n\n#{@document}" end |