class HaveDataMatcher

Public Class Methods

new(data, mode="rb:binary") click to toggle source
# File lib/mspec/matchers/have_data.rb, line 5
def initialize(data, mode="rb:binary")
  @data = data
  @mode = mode
end

Public Instance Methods

failure_message() click to toggle source
# File lib/mspec/matchers/have_data.rb, line 24
def failure_message
  ["Expected #{@name}",
   "to have data #{@data.pretty_inspect}"]
end
matches?(name) click to toggle source
# File lib/mspec/matchers/have_data.rb, line 10
def matches?(name)
  @name = name

  if FeatureGuard.enabled? :encoding
    size = @data.bytesize
  else
    size = @data.size
  end

  File.open @name, fmode(@mode) do |f|
    return f.read(size) == @data
  end
end
negative_failure_message() click to toggle source
# File lib/mspec/matchers/have_data.rb, line 29
def negative_failure_message
  ["Expected #{@name}",
   "not to have data #{@data.pretty_inspect}"]
end