Class: HaveDataMatcher
- Defined in:
- lib/extensions/mspec/mspec/matchers/have_data.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(data, mode = "rb:binary") ⇒ HaveDataMatcher
constructor
A new instance of HaveDataMatcher.
- #matches?(name) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(data, mode = "rb:binary") ⇒ HaveDataMatcher
Returns a new instance of HaveDataMatcher.
5 6 7 8 |
# File 'lib/extensions/mspec/mspec/matchers/have_data.rb', line 5 def initialize(data, mode="rb:binary") @data = data @mode = mode end |
Instance Method Details
#failure_message ⇒ Object
24 25 26 27 |
# File 'lib/extensions/mspec/mspec/matchers/have_data.rb', line 24 def ["Expected #{@name}", "to have data #{@data.pretty_inspect}"] end |
#matches?(name) ⇒ Boolean
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/extensions/mspec/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 ⇒ Object
29 30 31 32 |
# File 'lib/extensions/mspec/mspec/matchers/have_data.rb', line 29 def ["Expected #{@name}", "not to have data #{@data.pretty_inspect}"] end |