Sha256: 0bc53c9daee029caa47a1fcc61656254399ecddd70433811fb938d892558c968

Contents?: true

Size: 847 Bytes

Versions: 13

Compression:

Stored size: 847 Bytes

Contents

require 'rspec/expectations'

RSpec::Matchers.define :request_for do |h|
  match do |actual|
    begin
      !h.key?(:uri) || actual.uri == h[:uri] &&
        !h.key?(:method) || actual.method == h[:method] &&
          !h.key?(:headers) || actual.to_hash == h[:headers]
    end
  end
end

RSpec::Matchers.define :be_time do |expected|

  def to_string(time)
    time.is_a?(Time) ? time.utc.round(2).iso8601(2) : time.to_s
  end

  match do |actual|
    if expected
      fail "Expected value #{expected} is not a Time" unless expected.is_a?(Time)
      actual.is_a?(Time) && (to_string(expected) == to_string(actual))
    else
      return actual.nil?
    end
  end

  failure_message do |actual|
    expected_str = to_string(expected)
    actual_str = to_string(actual)
    "expected time:\n#{expected_str}\n\nbut was:\n#{actual_str}"
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
resync-client-0.4.5 spec/rspec_custom_matchers.rb
resync-client-0.4.4 spec/rspec_custom_matchers.rb
resync-client-0.4.3 spec/rspec_custom_matchers.rb
resync-client-0.4.2 spec/rspec_custom_matchers.rb
resync-client-0.4.1 spec/rspec_custom_matchers.rb
resync-client-0.4.0 spec/rspec_custom_matchers.rb
resync-client-0.3.5 spec/rspec_custom_matchers.rb
resync-client-0.3.4 spec/rspec_custom_matchers.rb
resync-client-0.3.3 spec/rspec_custom_matchers.rb
resync-client-0.3.2 spec/rspec_custom_matchers.rb
resync-client-0.3.1 spec/rspec_custom_matchers.rb
resync-client-0.3.0 spec/rspec_custom_matchers.rb
resync-client-0.2.5 spec/rspec_custom_matchers.rb