Class: RSpec::RubyContentMatchers::HaveContent

Inherits:
Object
  • Object
show all
Defined in:
lib/code_spec/matchers/have_content.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHaveContent

Returns a new instance of HaveContent.



5
6
# File 'lib/code_spec/matchers/have_content.rb', line 5

def initialize
end

Instance Attribute Details

#file_pathObject

Returns the value of attribute file_path.



3
4
5
# File 'lib/code_spec/matchers/have_content.rb', line 3

def file_path
  @file_path
end

Instance Method Details

#failure_messageObject



16
17
18
# File 'lib/code_spec/matchers/have_content.rb', line 16

def failure_message
  display "Expected the file #{file_path} to have content" 
end

#matches?(file_path) {|file.read| ... } ⇒ Boolean

Yields:

  • (file.read)

Returns:

  • (Boolean)


8
9
10
11
12
13
14
# File 'lib/code_spec/matchers/have_content.rb', line 8

def matches?(file_path, &block)      
  self.file_path = file_path
  return nil if File.blank? file_path
  file = File.new(file_path)
  yield file.read if block
  true
end

#negative_failure_messageObject



20
21
22
# File 'lib/code_spec/matchers/have_content.rb', line 20

def negative_failure_message
  display "Did not expect the file #{file_path} to have content" 
end