Class: HaveDataMatcher

Inherits:
Object show all
Defined in:
lib/mspec/matchers/have_data.rb

Instance Method Summary collapse

Constructor Details

#initialize(data, mode = "rb:binary") ⇒ HaveDataMatcher

Returns a new instance of HaveDataMatcher


5
6
7
8
# File 'lib/mspec/matchers/have_data.rb', line 5

def initialize(data, mode="rb:binary")
  @data = data
  @mode = mode
end

Instance Method Details

#failure_messageObject


24
25
26
27
# File 'lib/mspec/matchers/have_data.rb', line 24

def failure_message
  ["Expected #{@name}",
   "to have data #{@data.pretty_inspect}"]
end

#matches?(name) ⇒ Boolean

Returns:

  • (Boolean)

10
11
12
13
14
15
16
17
18
19
20
21
22
# 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_messageObject


29
30
31
32
# File 'lib/mspec/matchers/have_data.rb', line 29

def negative_failure_message
  ["Expected #{@name}",
   "not to have data #{@data.pretty_inspect}"]
end