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

Version Path
radiantcms-couchrest_model-0.2.4 spec/matchers/render_form_errors_matcher.rb
radiantcms-couchrest_model-0.2.2 spec/matchers/render_form_errors_matcher.rb
radiantcms-couchrest_model-0.2.1 spec/matchers/render_form_errors_matcher.rb
radiantcms-couchrest_model-0.2 spec/matchers/render_form_errors_matcher.rb
radiantcms-couchrest_model-0.1.9 spec/matchers/render_form_errors_matcher.rb
radiantcms-couchrest_model-0.1.8 spec/matchers/render_form_errors_matcher.rb
radiantcms-couchrest_model-0.1.7 spec/matchers/render_form_errors_matcher.rb
radiantcms-couchrest_model-0.1.6 spec/matchers/render_form_errors_matcher.rb
radiantcms-couchrest_model-0.1.5 spec/matchers/render_form_errors_matcher.rb
radiant-0.7.2 spec/matchers/render_form_errors_matcher.rb
radiant-0.8.2 spec/matchers/render_form_errors_matcher.rb
radiant-0.8.1 spec/matchers/render_form_errors_matcher.rb
radiant-0.7.0 spec/matchers/render_form_errors_matcher.rb
radiant-0.7.1 spec/matchers/render_form_errors_matcher.rb
radiant-0.8.0 spec/matchers/render_form_errors_matcher.rb