Sha256: e652b99dcb1a45fa3ce46229770c058d80041dea7789380809261f388d653b73

Contents?: true

Size: 1 KB

Versions: 5

Compression:

Stored size: 1 KB

Contents

module Spec
  module Rails
    module Matchers
    
      class ArBeValid  #:nodoc:
        
        def initialize
          @matcher = Spec::Matchers::Be.new :be_valid
          @matcher.__send__ :handling_predicate!
        end

        def matches?(actual)
          @actual = actual
          @matcher.matches? @actual
        end
      
        def failure_message
          if @actual.respond_to?(:errors) &&
              ActiveRecord::Errors === @actual.errors
            "Expected #{@actual.inspect} to be valid, but it was not\nErrors: " + @actual.errors.full_messages.join(", ")            
          else
            @matcher.failure_message
          end
        end
        
        def negative_failure_message
          @matcher.negative_failure_message
        end
        
        def description
          "be valid"
        end
      end

      # :call-seq:
      #   response.should be_valid
      #   response.should_not be_valid
      def be_valid
        ArBeValid.new
      end
    
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
dchelimsky-rspec-rails-1.1.99.6 lib/spec/rails/matchers/ar_be_valid.rb
dchelimsky-rspec-rails-1.1.99.7 lib/spec/rails/matchers/ar_be_valid.rb
dchelimsky-rspec-rails-1.1.99.8 lib/spec/rails/matchers/ar_be_valid.rb
dchelimsky-rspec-rails-1.1.99.9 lib/spec/rails/matchers/ar_be_valid.rb
mcmire-rspec-rails-1.1.99.9 lib/spec/rails/matchers/ar_be_valid.rb