Sha256: dd97007b1dea660604ec67639c0dcff78316d1d4498daf8bf29bdbc3b2ff1841

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 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

7 entries across 7 versions & 1 rubygems

Version Path
remarkable-3.0.2 spec/matchers/single_contain_matcher.rb
remarkable-3.0.4 spec/matchers/single_contain_matcher.rb
remarkable-3.0.5 spec/matchers/single_contain_matcher.rb
remarkable-3.0.6 spec/matchers/single_contain_matcher.rb
remarkable-3.0.7 spec/matchers/single_contain_matcher.rb
remarkable-3.0.8 spec/matchers/single_contain_matcher.rb
remarkable-3.0.3 spec/matchers/single_contain_matcher.rb