Sha256: d158111c129eb2ca5bcee893629c5512b2ca793a93f0af77fe7c938f370e3f49

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module DataMapper
  module Matchers
    class ValidationMatcher

      class << self
	def set_validation_subject(subject)
	  @validation_subject = subject
	end

	def set_default_msg_reg(msg_reg)
	  @default_msg_reg = msg_reg
	end
      end



      def initialize(property)
        @property = property.to_sym
	@validation_subject = self.class.instance_eval { @validation_subject }
	@msg_reg = self.class.instance_eval { @default_msg_reg }
      end

      def with_message(msg)
        @msg = msg
        @msg_reg = /^#{Regexp.escape(@msg)}$/
        self
      end

      def failure_message
        msg = "expected to validate #{@validation_subject} of #{@property}"
        msg = %Q'#{msg} with message "#{@msg}"' if @msg
        msg
      end

      def failure_message_when_negated
        msg = "expected to not validate #{@validation_subject} of #{@property}"
        msg = %Q'#{msg} with message "#{@msg}"' if @msg
        msg
      end

      def description
        "validate #{@validation_subject} of #{@property}"
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dm-rspec-0.3.0 lib/dm/matchers/validation_matcher.rb