Class: RspecApiDocs::Formatter

Inherits:
RSpec::Core::Formatters::BaseFormatter
  • Object
show all
Defined in:
lib/rspec_api_docs/formatter.rb

Overview

The RSpec formatter.

Usage:

rspec --format=RspecApiDocs::Formatter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Formatter



23
24
25
26
# File 'lib/rspec_api_docs/formatter.rb', line 23

def initialize(*args)
  @resources = {}
  super args
end

Instance Attribute Details

#resourcesObject (readonly)

Returns the value of attribute resources.



21
22
23
# File 'lib/rspec_api_docs/formatter.rb', line 21

def resources
  @resources
end

Instance Method Details

#close(null_notification) ⇒ void

This method returns an undefined value.

Calls the configured renderer with the stored Resources.



42
43
44
# File 'lib/rspec_api_docs/formatter.rb', line 42

def close(null_notification)
  renderer.new(resources.values.sort_by { |resource| [resource.precedence, resource.name].join }).render
end

#example_passed(example_notification) ⇒ void

This method returns an undefined value.

Initializes and stores Resources.



31
32
33
34
35
36
37
# File 'lib/rspec_api_docs/formatter.rb', line 31

def example_passed(example_notification)
  rspec_example = example_notification.example
  return unless rspec_example.[]
  resource = Resource.new(rspec_example)
  resources[resource.name] ||= resource
  resources[resource.name].add_example Resource::Example.new(rspec_example)
end