Class: RSpec::RubyContentMatchers::MatchLines

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*lines) ⇒ MatchLines

Returns a new instance of MatchLines.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/code_spec/matchers/match_lines.rb', line 5

def initialize *lines       
  lines = lines.flatten
  last_arg = lines.last
  separator = case last_arg
  when Hash 
    self.lines = lines[0..-2].flatten                
    last_arg[:separator]        
  else 
    self.lines = lines        
    "\n"
  end      
  self.separator = separator
end

Instance Attribute Details

#linesObject

Returns the value of attribute lines.



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

def lines
  @lines
end

#separatorObject

Returns the value of attribute separator.



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

def separator
  @separator
end

Instance Method Details

#failure_messageObject



28
29
30
# File 'lib/code_spec/matchers/match_lines.rb', line 28

def failure_message
  "Expected the string to match the lines" 
end

#matches?(content, &block) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
# File 'lib/code_spec/matchers/match_lines.rb', line 19

def matches?(content, &block)
  lines.each do |txt|  
    txt.split(separator).each do |line|
      return nil if !(content =~ /#{Regexp.escape(line)}/)
    end
  end
  true
end

#negative_failure_messageObject



32
33
34
35
# File 'lib/code_spec/matchers/match_lines.rb', line 32

def negative_failure_message
  super
  "Did not expect string to match the lines" 
end