Sha256: 40d585864bbd1a19737dd03eb5a082fc7cea8e051ebd79fab4d7e3f4fc926077

Contents?: true

Size: 1.04 KB

Versions: 12

Compression:

Stored size: 1.04 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_for_should
          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_for_should
          end
        end
        
        def failure_message_for_should_not
          @matcher.failure_message_for_should_not
        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

12 entries across 12 versions & 3 rubygems

Version Path
cavalle-rspec-rails-1.2.2.0.1 lib/spec/rails/matchers/ar_be_valid.rb
cavalle-rspec-rails-1.2.2.0.2 lib/spec/rails/matchers/ar_be_valid.rb
cavalle-rspec-rails-1.2.3.1 lib/spec/rails/matchers/ar_be_valid.rb
cavalle-rspec-rails-1.2.4.0.1 lib/spec/rails/matchers/ar_be_valid.rb
dchelimsky-rspec-rails-1.1.99.13 lib/spec/rails/matchers/ar_be_valid.rb
rspec-rails-1.2.0 lib/spec/rails/matchers/ar_be_valid.rb
rspec-rails-1.2.4 lib/spec/rails/matchers/ar_be_valid.rb
rspec-rails-1.2.5 lib/spec/rails/matchers/ar_be_valid.rb
rspec-rails-1.2.1 lib/spec/rails/matchers/ar_be_valid.rb
rspec-rails-1.2.6 lib/spec/rails/matchers/ar_be_valid.rb
rspec-rails-1.2.2 lib/spec/rails/matchers/ar_be_valid.rb
rspec-rails-1.2.3 lib/spec/rails/matchers/ar_be_valid.rb