On Tue, Apr 9, 2013 at 3:50 PM, Ervin Weber <weber...@gmail.com> wrote:
> 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. I don't think there's any good way to do this. There is no concept of "the current formatter" and I don't think this one case would be sufficient to introduce one. Custom formatters won't work because the formatters don't have access to the matcher to get its description (that happens in a different part of the system). Also, even if there were such a mechanism, it would only work with the one liner (e.g. it { should be_json(expected_json) }) form - another reason why it wouldn't be general enough to add to RSpec IMO. If you have different ideas about how it might work, feel free to submit a feature request to https://github.com/rspec/rspec-core/issues. Cheers, David
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users