class RSpec::Formatters::IllustratedHtmlFormatter

An extension to the {RSpec::Core::Formatters::HtmlFormatter} that renders the illustrations after each example. A title/label for each illustration can be set by setting the label option (@see RSpec::Illustrate#illustrate). If you want to filter the illustrations based on the test result, you can use the options show_when_passed, show_when_failed and show_when_pending.

Public Class Methods

new(output) click to toggle source
Calls superclass method
# File lib/rspec/formatters/illustrated_html_formatter.rb, line 42
def initialize(output)
  super(output)
end

Public Instance Methods

example_failed(failure) click to toggle source

@see RSpec::Core::Formatters::HtmlFormatter#example_failed

Calls superclass method
# File lib/rspec/formatters/illustrated_html_formatter.rb, line 53
def example_failed(failure)
  super(failure)
  write_illustrations(failure, :show_when_failed)
end
example_passed(passed) click to toggle source

@see RSpec::Core::Formatters::HtmlFormatter#example_passed

Calls superclass method
# File lib/rspec/formatters/illustrated_html_formatter.rb, line 47
def example_passed(passed)
  super(passed)
  write_illustrations(passed, :show_when_passed)
end
example_pending(pending) click to toggle source

@see RSpec::Core::Formatters::HtmlFormatter#example_pending

Calls superclass method
# File lib/rspec/formatters/illustrated_html_formatter.rb, line 59
def example_pending(pending)
  super(pending)
  write_illustrations(pending, :show_when_pending)
end
formatted(illustrations) click to toggle source

@private Convert the illustrations to a string using the configurable illustration html formatter {RSpec::Configuration#illustration_html_formatter}. @param illustrations [Array<Hash>] The illustrations @return [String] a html concatenation of the illustrations

# File lib/rspec/formatters/illustrated_html_formatter.rb, line 85
def formatted(illustrations)
  formatter_proc = RSpec.configuration.illustration_html_formatter

  illustrations.collect{|illustration|
    formatter_proc.call(illustration)
  }.join("\n")
end
write_illustrations(notification, filter_key) click to toggle source

@private Writes the filtered illustrations of an example to the output stream.

@param notification [RSpec::Core::Notifications::ExampleNotification]

The example notificiation that contains the
illustrations.

@param filter_key [Symbol]

The option that each illustration should have a truthy
value of if they are to be written
# File lib/rspec/formatters/illustrated_html_formatter.rb, line 73
def write_illustrations(notification, filter_key)
  illustrations = filter(illustrations_of(notification), filter_key)
  return if illustrations.empty?

  output.puts formatted(illustrations)
end