空白空行を無視するrspec-match_fuzzyを作った

なんだかんだで必要になるので、空白空行を無視するrspecのmatcher、rspec-match_fuzzyを作った。

github.com

以下の例は空白空行を無視してマッチする。

it '...' do
  str1 = <<-EOS
    London Bridge
    Is Broken down,
    Dance over my Lady Lee.
    London Bridge
    Is Broken down
    With a gay Lady.
  EOS

  str2 = <<-EOS
    London  Bridge
    Is  Broken  down,

    Dance over my Lady Lee.


    London\tBridge
    Is\tBroken\tdown
    With a gay Lady.
  EOS

  expect(str1).to match_fuzzy str2
end

差異がある場合はdiffが出る。

f:id:winebarrel:20160409220635p:plain

また、ERBのヘルパーメソッドも追加した。

include RSpec::MatchFuzzy

it '...' do
  result = erb("<%= @foo %>, <%= @bar %>", foo: 100, bar: 'zoo')
  expect(result).to eq '100, zoo'
end