Sha256: b2c5b530d70820ea29389c26fda7911215e30ae5230fce8e5a1882519c1fa4ae

Contents?: true

Size: 915 Bytes

Versions: 15

Compression:

Stored size: 915 Bytes

Contents

module RSpec::RubyContentMatchers
  class MatchLines
    attr_accessor :lines, :separator

    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

    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
  
    def failure_message
      "Expected the string to match the lines" 
    end 
    
    def negative_failure_message
      super
      "Did not expect string to match the lines" 
    end
  end
  
  def match_lines *lines
    MatchLines.new lines
  end  
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
code-spec-0.4.0 lib/code_spec/matchers/match_lines.rb
code-spec-0.3.0 lib/code_spec/matchers/match_lines.rb
code-spec-0.2.11 lib/code_spec/matchers/match_lines.rb
code-spec-0.2.9 lib/code_spec/matchers/match_lines.rb
code-spec-0.2.8 lib/code_spec/matchers/match_lines.rb
code-spec-0.2.7 lib/code_spec/matchers/match_lines.rb
code-spec-0.2.6 lib/code_spec/matchers/match_lines.rb
code-spec-0.2.5 lib/code_spec/matchers/match_lines.rb
code-spec-0.2.4 lib/code_spec/matchers/match_lines.rb
code-spec-0.2.3 lib/code_spec/matchers/match_lines.rb
code-spec-0.2.2 lib/code_spec/matchers/match_lines.rb
code-spec-0.2.1 lib/code_spec/matchers/match_lines.rb
code-spec-0.2.0 lib/code_spec/matchers/match_lines.rb
code-spec-0.1.3 lib/code_spec/matchers/match_lines.rb
code-spec-0.1.2 lib/code_spec/matchers/match_lines.rb