[rspec-users] Different description in custom RSpec::Matcher depending on output formater

Ervin Weber webervin at gmail.com
Tue Apr 9 20:50:23 UTC 2013


Hello is it possible to make something like following:

RSpec::Matchers.define :be_json do |expected|
  match do |actual|
    JSON.parse(actual) == expected
  end

  description do
    if html? # to html formatter output this
       "return JSON:\n#{JSON.pretty_generate(expected)}"
    else # for other formats condensed output
      "return JSON:\n#{expected}"
    end
  end
end

I plan to use this running two formatters at same time  -f doc and -f
html at same time to produce pretty HTML file,  and relatively
condensed doc in console.

Big thanks, forward,
Ervin.


More information about the rspec-users mailing list