Sha256: 736773fa6858e81ea5990011319d7b5c4972913f0503236bad67ae84c5a172f4
Contents?: true
Size: 1.05 KB
Versions: 3
Compression:
Stored size: 1.05 KB
Contents
require 'rspec/expectations' require 'mime/types' 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 def to_mime_type(mime_type) return nil unless mime_type return mime_type if mime_type.is_a?(MIME::Type) mt = MIME::Types[mime_type].first return mt if mt MIME::Type.new(mime_type) end RSpec::Matchers.define :be_mime_type do |expected| expected_mime_type = to_mime_type(expected) match do |actual| actual == expected_mime_type end failure_message do |actual| "expected MIME type:\n#{expected_mime_type}\nbut was:\n#{actual}" end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
xml-mapping_extensions-0.2.0 | spec/rspec_custom_matchers.rb |
xml-mapping_extensions-0.1.1 | spec/rspec_custom_matchers.rb |
xml-mapping_extensions-0.1.0 | spec/rspec_custom_matchers.rb |