Sha256: 230f54ca80dabec0a7c781dc30645c0fe9594856063f194b1c3b81da63e10437
Contents?: true
Size: 1.96 KB
Versions: 15
Compression:
Stored size: 1.96 KB
Contents
module Spec module Rails module Matchers class RenderFormErrors def initialize(error_fields, example) @error_fields, @example = error_fields, example end def matches?(response) begin response.should @example.have_tag('#error') rescue @display_failure_message = 'Expected to display form errors but did not' end unless @display_failure_message @error_fields.to_fields.each do |field_name, error_message| begin @example.assert_tag( :tag => 'div', :attributes => {:class => 'error-with-field'}, :child => { :tag => /input|select|textarea/, :attributes => {:name => field_name} }, :child => { :tag => 'small', :attributes => {:class => 'error'}, :content => error_message } ) rescue @error_field_failure_message = "Expected field #{field_name} to have error message '#{error_message}' but did not" break end end end @display_failure_message.nil? && @error_field_failure_message.nil? end def failure_message @display_failure_message ? @display_failure_message : @error_field_failure_message end def negative_failure_message 'Expected not to display form errors but did' end end # Used to ensure that there are model errors shown on the page. # # Looks to see if the response includes content according to the # application's technique for displaying form errors. def render_form_errors(error_fields = {}) RenderFormErrors.new(error_fields, self) end end end end
Version data entries
15 entries across 15 versions & 2 rubygems