Sha256: f048b9a2ae1d7e5ed55565b854e7e5b826d7580f9feb3d6a7f1ae4b5896de9fa

Contents?: true

Size: 1.17 KB

Versions: 47

Compression:

Stored size: 1.17 KB

Contents

module MatchHelpers
  class MatchMatcher
    def initialize(expected)
      fail "Expected #{expected} to be a Regexp!" unless expected.is_a?(Regexp)
      @expected = expected
    end

    def matches?(actual)
      @actual = actual
      @expected.match(@actual)
    end

    def failure_message
      ["Expected #{@actual.inspect} (#{@actual.class})",
       "to match #{@expected}"]
    end

    def negative_failure_message
      ["Expected #{@actual.inspect} (#{@actual.class})",
       "not to match #{@expected}"]
    end
  end

  class EndWithHelper
    def initialize(expected)
      @expected = expected
    end

    def matches?(actual)
      @actual = actual
      @actual.end_with?(@expected)
    end

    def failure_message
      ["Expected #{@actual.inspect} (#{@actual.class})",
       "to end with #{@expected}"]
    end

    def negative_failure_message
      ["Expected #{@actual.inspect} (#{@actual.class})",
       "not to end with #{@expected}"]
    end
  end
end

if !defined? RSpec
  class Object
    def match(expected)
      MatchHelpers::MatchMatcher.new(expected)
    end

    def end_with(expected)
      MatchHelpers::EndWithHelper.new(expected)
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 spec/support/match_helpers.rb
opal-1.8.2 spec/support/match_helpers.rb
opal-1.8.1 spec/support/match_helpers.rb
opal-1.8.0 spec/support/match_helpers.rb
opal-1.8.0.beta1 spec/support/match_helpers.rb
opal-1.7.4 spec/support/match_helpers.rb
opal-1.8.0.alpha1 spec/support/match_helpers.rb
opal-1.7.3 spec/support/match_helpers.rb
opal-1.7.2 spec/support/match_helpers.rb
opal-1.7.1 spec/support/match_helpers.rb
opal-1.7.0 spec/support/match_helpers.rb
opal-1.7.0.rc1 spec/support/match_helpers.rb
opal-1.6.1 spec/support/match_helpers.rb
opal-1.6.0 spec/support/match_helpers.rb
opal-1.6.0.rc1 spec/support/match_helpers.rb
opal-1.6.0.alpha1 spec/support/match_helpers.rb
opal-1.5.1 spec/support/match_helpers.rb
opal-1.5.0 spec/support/match_helpers.rb
opal-1.5.0.rc1 spec/support/match_helpers.rb
opal-1.4.1 spec/support/match_helpers.rb