Sha256: aa9d594ced7cb40d695d1bdc3e472f5c506aef71d0f68f9e3591813d1f2fef9c

Contents?: true

Size: 930 Bytes

Versions: 12

Compression:

Stored size: 930 Bytes

Contents

module RSpec
  module Matchers
    # :call-seq:
    #   should cover(expected)
    #   should_not cover(expected)
    #
    # Passes if actual covers expected. This works for
    # Ranges. You can also pass in multiple args
    # and it will only pass if all args are found in Range.
    #
    # == Examples
    #   (1..10).should cover(5)
    #   (1..10).should cover(4, 6)
    #   (1..10).should cover(4, 6, 11) # will fail
    #   (1..10).should_not cover(11)
    #   (1..10).should_not cover(5)    # will fail
    #
    # == Warning: Ruby >= 1.9 only
    def cover(*values)
      Matcher.new :cover, *values do |*_values|
        match_for_should do |range|
          _values.all? &covered_by(range)
        end

        match_for_should_not do |range|
          _values.none? &covered_by(range)
        end

        def covered_by(range)
          lambda {|value| range.cover?(value)}
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
horseman-0.0.4 vendor/ruby/1.9.1/gems/rspec-expectations-2.7.0/lib/rspec/matchers/cover.rb
horseman-0.0.3 vendor/ruby/1.9.1/gems/rspec-expectations-2.7.0/lib/rspec/matchers/cover.rb
horseman-0.0.2 vendor/ruby/1.9.1/gems/rspec-expectations-2.7.0/lib/rspec/matchers/cover.rb
nutshell-crm-0.0.6.alpha vendor/bundle/gems/rspec-expectations-2.7.0/lib/rspec/matchers/cover.rb
nutshell-crm-0.0.5 vendor/bundle/gems/rspec-expectations-2.7.0/lib/rspec/matchers/cover.rb
nutshell-crm-0.0.4 vendor/bundle/gems/rspec-expectations-2.7.0/lib/rspec/matchers/cover.rb
nutshell-crm-0.0.3 vendor/bundle/gems/rspec-expectations-2.7.0/lib/rspec/matchers/cover.rb
nutshell-crm-0.0.2 vendor/bundle/gems/rspec-expectations-2.7.0/lib/rspec/matchers/cover.rb
nutshell-crm-0.0.1 vendor/bundle/gems/rspec-expectations-2.7.0/lib/rspec/matchers/cover.rb
rspec-expectations-2.7.0 lib/rspec/matchers/cover.rb
rspec-expectations-2.7.0.rc1 lib/rspec/matchers/cover.rb
rspec-expectations-2.6.0 lib/rspec/matchers/cover.rb