Sha256: 08f4b8a7c7afa4a14063b61895ff029047c228a6863e9d4ac3017083e93b92ec

Contents?: true

Size: 1.24 KB

Versions: 9

Compression:

Stored size: 1.24 KB

Contents

RSpec::Matchers.define :include_method do |expected|
  match do |actual|
    actual.map { |m| m.to_s }.include?(expected.to_s)
  end
end

RSpec::Matchers.define :custom_include do |*args|
  match { |actual| expect(actual).to include(*args) }
end

RSpec::Matchers.define :be_a_clone_of do |expected|
  match do |actual|
    !actual.equal?(expected) &&
        actual.class.equal?(expected.class) &&
        state_of(actual) == state_of(expected)
  end

  def state_of(object)
    ivar_names = object.instance_variables
    Hash[ ivar_names.map { |n| [n, object.instance_variable_get(n)] } ]
  end
end

RSpec::Matchers.define :have_string_length do |expected|
  match do |actual|
    @actual = actual
    string_length == expected
  end

  def string_length
    @string_length ||= @actual.length
  end
end

module RSpec
  module Matchers
    def fail
      raise_error(RSpec::Expectations::ExpectationNotMetError)
    end

    def fail_with(message)
      raise_error(RSpec::Expectations::ExpectationNotMetError, message)
    end

    def fail_matching(message)
      if String === message
        regexp = /#{Regexp.escape(message)}/
      else
        regexp = message
      end
      raise_error(RSpec::Expectations::ExpectationNotMetError, regexp)
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
opal-rspec-0.6.2 rspec-expectations/spec/support/matchers.rb
opal-rspec-0.6.1 rspec-expectations/spec/support/matchers.rb
opal-rspec-0.6.0 rspec-expectations/spec/support/matchers.rb
opal-rspec-0.6.0.beta1 rspec-expectations/spec/support/matchers.rb
opal-connect-rspec-0.5.0 rspec-expectations/spec/support/matchers.rb
opal-rspec-0.5.0 rspec-expectations/spec/support/matchers.rb
opal-rspec-0.5.0.beta3 rspec-expectations/spec/support/matchers.rb
opal-rspec-0.5.0.beta2 rspec-expectations/spec/support/matchers.rb
opal-rspec-0.5.0.beta1 rspec-expectations/spec/support/matchers.rb