Class: RSpec::Formatters::YARD

Inherits:
Object
  • Object
show all
Includes:
RSpec::Formatters
Defined in:
lib/rspec/formatters/yard.rb

Overview

An RSpec output formatter that writes in a specific HTML format that can be imported by the YARD template. The output can also be viewed as a stand-alone test report.

Constant Summary

CSS_FILE =

Returns the path to the CSS file in the YARD-template, which will be imported into the header so the output HTML can be viewed as a stand-alone document.

Returns:

  • (String)

    the path to the CSS file in the YARD-template, which will be imported into the header so the output HTML can be viewed as a stand-alone document.

File.join(File.dirname(__FILE__), '..','..','..',
'yard-template', 'default', 'fulldoc', 'html', 'css', 'rspec.css')

Instance Method Summary (collapse)

Methods included from RSpec::Formatters

filter, illustrations_of

Constructor Details

- (YARD) initialize(output)

Returns a new instance of YARD



26
27
28
29
30
31
32
33
34
# File 'lib/rspec/formatters/yard.rb', line 26

def initialize(output)
  @output = output
  @document = REXML::Document.new("<!DOCTYPE html>")

  html = @document.add_element("html")
  head = html.add_element("head")
  head.add_element("style").text = IO.read(CSS_FILE)
  @body = html.add_element("body")
end

Instance Method Details

- (Object) example_failed(failure)

Called by RSpec for each example that failes.

Parameters:

  • failure (RSpec::Core::Notifications::FailedExampleNotification)


52
53
54
55
56
57
# File 'lib/rspec/formatters/yard.rb', line 52

def example_failed(failure)
  node = xml_node_for_notification(failure, :show_when_pending)
  node.attributes["class"] = "rspec_example_failed"
  node.add_element("exception").text = failure.exception.message
  node.add_element("backtrace").text = failure.formatted_backtrace.join("\n")
end

- (Object) example_passed(passed)

Called by RSpec for each example that passes.

Parameters:

  • passed (RSpec::Core::Notifications::ExampleNotification)


38
39
40
41
# File 'lib/rspec/formatters/yard.rb', line 38

def example_passed(passed)
  node = xml_node_for_notification(passed, :show_when_passed)
  node.attributes["class"] = "rspec_example_passed"
end

- (Object) example_pending(pending)

Called by RSpec for each example that is pending.

Parameters:

  • pending (RSpec::Core::Notifications::ExampleNotification)


45
46
47
48
# File 'lib/rspec/formatters/yard.rb', line 45

def example_pending(pending)
  node = xml_node_for_notification(pending, :show_when_pending)
  node.attributes["class"] = "rspec_example_pending"
end

- (Object) stop(notification)

Called by RSpec when the test suite is complete.

Parameters:

  • notification (RSpec::Core::Notifications::ExamplesNotification)


61
62
63
64
65
# File 'lib/rspec/formatters/yard.rb', line 61

def stop(notification)
  @document.elements["html/head"].add_element("title").text =
    RSpec.configuration.title
  @document.write @output
end