Sha256: 052d168996837583fad8df03e4e39de56a7e4fa437cea917be4a640ae238c975

Contents?: true

Size: 1.96 KB

Versions: 25

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 => 'span',
                    :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

25 entries across 25 versions & 5 rubygems

Version Path
radiant-1.1.4 spec/matchers/render_form_errors_matcher.rb
radiant-1.1.3 spec/matchers/render_form_errors_matcher.rb
radiant-1.1.2 spec/matchers/render_form_errors_matcher.rb
radiant-1.1.1 spec/matchers/render_form_errors_matcher.rb
radiant-1.1.0 spec/matchers/render_form_errors_matcher.rb
radiant-1.1.0.rc1 spec/matchers/render_form_errors_matcher.rb
radiant-1.1.0.beta spec/matchers/render_form_errors_matcher.rb
radiant-1.0.1 spec/matchers/render_form_errors_matcher.rb
radiant-1.1.0.alpha spec/matchers/render_form_errors_matcher.rb
radiant-1.0.0 spec/matchers/render_form_errors_matcher.rb
radiant-1.0.0.rc5 spec/matchers/render_form_errors_matcher.rb
radiant-1.0.0.rc4 spec/matchers/render_form_errors_matcher.rb
radiant-1.0.0.rc3 spec/matchers/render_form_errors_matcher.rb
kajam-1.0.3.rc2 spec/matchers/render_form_errors_matcher.rb
radiant-1.0.0.rc2 spec/matchers/render_form_errors_matcher.rb
radiant-1.0.0.rc1 spec/matchers/render_form_errors_matcher.rb
radiant-rails3-0.1 spec/support/render_form_errors_matcher.rb
radiantcms-couchrest_model-0.1.4 spec/matchers/render_form_errors_matcher.rb
radiantcms-couchrest_model-0.1.3 spec/matchers/render_form_errors_matcher.rb
radiantcms-couchrest_model-0.1.2 spec/matchers/render_form_errors_matcher.rb