Sha256: b7f6fe151dca9522cc9643192a89d020a16f36feede20014dd54c281b24aee1d

Contents?: true

Size: 967 Bytes

Versions: 11

Compression:

Stored size: 967 Bytes

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
        
      end

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

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
dchelimsky-rspec-rails-1.1.11.4 lib/spec/rails/matchers/ar_be_valid.rb
dchelimsky-rspec-rails-1.1.11.5 lib/spec/rails/matchers/ar_be_valid.rb
dchelimsky-rspec-rails-1.1.11.6 lib/spec/rails/matchers/ar_be_valid.rb
dchelimsky-rspec-rails-1.1.11.7 lib/spec/rails/matchers/ar_be_valid.rb
dchelimsky-rspec-rails-1.1.12 lib/spec/rails/matchers/ar_be_valid.rb
rspec-rails-1.1.12 lib/spec/rails/matchers/ar_be_valid.rb
spree-0.6.0 vendor/plugins/rspec-rails/lib/spec/rails/matchers/ar_be_valid.rb
spree-0.7.1 vendor/plugins/rspec-rails/lib/spec/rails/matchers/ar_be_valid.rb
spree-0.7.0 vendor/plugins/rspec-rails/lib/spec/rails/matchers/ar_be_valid.rb
spree-0.8.0 vendor/plugins/rspec-rails/lib/spec/rails/matchers/ar_be_valid.rb
spree-0.8.1 vendor/plugins/rspec-rails/lib/spec/rails/matchers/ar_be_valid.rb