Sha256: 5abda1bb17e6a9d36ccedcfe041e8286dc4f850b89007712949705976821ef1a

Contents?: true

Size: 956 Bytes

Versions: 13

Compression:

Stored size: 956 Bytes

Contents

module RSpec
  module Matchers
    class IncludeAStringLike
      def initialize(substring_or_regex)
        case substring_or_regex
        when String
          @regex = Regexp.new(Regexp.escape(substring_or_regex))
        when Regexp
          @regex = substring_or_regex
        else
          raise ArgumentError, "don't know what to do with the #{substring_or_regex.class} you provided"
        end
      end

      def matches?(list_of_strings)
        @list_of_strings = list_of_strings
        @list_of_strings.any? { |s| s =~ @regex }
      end
      def failure_message
        "#{@list_of_strings.inspect} expected to include a string like #{@regex.inspect}"
      end
      def negative_failure_message
        "#{@list_of_strings.inspect} expected to not include a string like #{@regex.inspect}, but did"
      end
    end

    def include_a_string_like(substring_or_regex)
      IncludeAStringLike.new(substring_or_regex)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
spork-1.0.0rc4 spec/support/should_include_a_string_like.rb
spork-1.0.0rc4-x86-mswin32 spec/support/should_include_a_string_like.rb
spork-1.0.0rc4-x86-mingw32 spec/support/should_include_a_string_like.rb
spork-1.0.0rc3 spec/support/should_include_a_string_like.rb
spork-1.0.0rc2 spec/support/should_include_a_string_like.rb
spork-1.0.0rc2-x86-mswin32 spec/support/should_include_a_string_like.rb
spork-1.0.0rc2-x86-mingw32 spec/support/should_include_a_string_like.rb
spork-1.0.0rc1 spec/support/should_include_a_string_like.rb
spork-1.0.0rc1-x86-mswin32 spec/support/should_include_a_string_like.rb
spork-1.0.0rc1-x86-mingw32 spec/support/should_include_a_string_like.rb
spork-1.0.0rc0-x86-mswin32 spec/support/should_include_a_string_like.rb
spork-1.0.0rc0-x86-mingw32 spec/support/should_include_a_string_like.rb
spork-1.0.0rc0 spec/support/should_include_a_string_like.rb