Sha256: 50fc46f86b1e89340d5933d7edfc4327286c68e5b15bb62370620f91737e3efb

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

module Remarkable
  module Specs
    module Matchers
      class SingleContainMatcher < Remarkable::Base
        arguments :value, :block => :iterator

        assertions :is_array?, :included?

        optional :allow_nil
        optional :allow_blank

        after_initialize :set_after_initialize

        before_assert do
          @before_assert = true
          @iterator.call(@subject) if @iterator
        end

        protected

          def included?
            return true if @subject.include?(@value)

            @expectation = "#{@value} is not included in #{@subject.inspect}"
            false
          end

          def is_array?
            return true if @subject.is_a?(Array)

            @expectation = "subject is a #{subject_name}"
            false
          end

          def default_options
            { :working => true }
          end

          def set_after_initialize
            @after_initialize = true
          end

      end

      def single_contain(*args, &block)
        SingleContainMatcher.new(*args, &block).spec(self)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
remarkable-3.0.0 spec/matchers/single_contain_matcher.rb
remarkable-3.0.1 spec/matchers/single_contain_matcher.rb