Sha256: 3b8f1aafd27c797a3d263756e90a12139794a212e879578d40fc47d5285b6074

Contents?: true

Size: 1.03 KB

Versions: 10

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 negative_failure_message
        msg = "expected to not validate #{@validation_subject} of #{@property}"
        msg = %Q'#{msg} with message "#{@msg}"' if @msg
        msg
      end

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

    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
dm-rspec2-0.3.0 lib/dm/matchers/validation_matcher.rb
dm-rspec-0.2.2 lib/dm/matchers/validation_matcher.rb
dm-rspec2-0.2.4 lib/dm/matchers/validation_matcher.rb
dm-rspec2-0.2.3 lib/dm/matchers/validation_matcher.rb
dm-rspec2-0.2.2 lib/dm/matchers/validation_matcher.rb
dm-rspec2-0.2.1 lib/dm/matchers/validation_matcher.rb
dm-rspec-0.2.1 lib/dm/matchers/validation_matcher.rb
dm-rspec-0.2.0 lib/dm/matchers/validation_matcher.rb
dm-rspec-0.1.2 lib/dm/matchers/validation_matcher.rb
dm-rspec-0.1.1 lib/dm/matchers/validation_matcher.rb