Sha256: 485192d343b9788e27963d4afa70eb4642ab0b3043cb125bd9dd94c8892385d6

Contents?: true

Size: 771 Bytes

Versions: 182

Compression:

Stored size: 771 Bytes

Contents

class MatchYAMLMatcher

  def initialize(expected)
    if valid_yaml?(expected)
      @expected = expected
    else
      @expected = expected.to_yaml
    end
  end

  def matches?(actual)
    @actual = actual    
    clean_yaml(@actual) == @expected
  end

  def failure_message
    ["Expected #{@actual.inspect}", " to match #{@expected.inspect}"]
  end

  def negative_failure_message
    ["Expected #{@actual.inspect}", " to match #{@expected.inspect}"]
  end
  
  protected
  
  def clean_yaml(yaml)
    yaml.gsub(/([^-])\s+\n/, "\\1\n")
  end

  def valid_yaml?(obj)
    require 'yaml'
    begin
      YAML.load(obj)
    rescue
      false
    else
      true
    end
  end
end

class Object
  def match_yaml(expected)
    MatchYAMLMatcher.new(expected)
  end
end

Version data entries

182 entries across 158 versions & 4 rubygems

Version Path
rhodes-5.5.18 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-5.5.17 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-5.5.15 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-5.5.0.22 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-5.5.2 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-5.5.0.7 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-5.5.0.3 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-5.5.0 lib/extensions/mspec/mspec/matchers/match_yaml.rb
tauplatform-1.0.3 lib/extensions/mspec/mspec/matchers/match_yaml.rb
tauplatform-1.0.2 lib/extensions/mspec/mspec/matchers/match_yaml.rb
tauplatform-1.0.1 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-3.5.1.12 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-3.3.5 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-3.4.2 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-3.3.4 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-3.3.3 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-3.3.3.beta.4 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-3.3.3.beta.3 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-3.3.3.beta.2 lib/extensions/mspec/mspec/matchers/match_yaml.rb
rhodes-3.3.3.beta.1 lib/extensions/mspec/mspec/matchers/match_yaml.rb