Class: HaveDataMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ HaveDataMatcher

Returns a new instance of HaveDataMatcher.



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

def initialize(data)
  @data = data
end

Instance Method Details

#failure_messageObject



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

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

#matches?(name) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mspec/matchers/have_data.rb', line 9

def matches?(name)
  @name = name

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

  File.open @name, fmode("rb:binary") do |f|
    return f.read(size) == @data
  end
end

#negative_failure_messageObject



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

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