Class: RSpec::RubyContentMatchers::MatchLines
- Inherits:
-
Object
- Object
- RSpec::RubyContentMatchers::MatchLines
- Defined in:
- lib/code_spec/matchers/match_lines.rb
Instance Attribute Summary collapse
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#separator ⇒ Object
Returns the value of attribute separator.
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(*lines) ⇒ MatchLines
constructor
A new instance of MatchLines.
- #matches?(content, &block) ⇒ Boolean
- #negative_failure_message ⇒ Object
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
#lines ⇒ Object
Returns the value of attribute lines.
3 4 5 |
# File 'lib/code_spec/matchers/match_lines.rb', line 3 def lines @lines end |
#separator ⇒ Object
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_message ⇒ Object
28 29 30 |
# File 'lib/code_spec/matchers/match_lines.rb', line 28 def "Expected the string to match the lines" end |
#matches?(content, &block) ⇒ 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_message ⇒ Object
32 33 34 35 |
# File 'lib/code_spec/matchers/match_lines.rb', line 32 def super "Did not expect string to match the lines" end |