Class: RSpecDocumentation::Formatters::Json
- Inherits:
-
Object
- Object
- RSpecDocumentation::Formatters::Json
- Defined in:
- lib/rspec_documentation/formatters/json.rb
Overview
Produces prettified JSON to from an RSpec ‘subject` value.
Instance Method Summary collapse
-
#initialize(subject:) ⇒ Json
constructor
A new instance of Json.
- #prettified_output ⇒ Object
- #render_raw? ⇒ Boolean
- #rendered_output ⇒ Object
Constructor Details
#initialize(subject:) ⇒ Json
Returns a new instance of Json.
7 8 9 |
# File 'lib/rspec_documentation/formatters/json.rb', line 7 def initialize(subject:) @subject = subject end |
Instance Method Details
#prettified_output ⇒ Object
11 12 13 |
# File 'lib/rspec_documentation/formatters/json.rb', line 11 def prettified_output nil end |
#render_raw? ⇒ Boolean
23 24 25 |
# File 'lib/rspec_documentation/formatters/json.rb', line 23 def render_raw? false end |
#rendered_output ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/rspec_documentation/formatters/json.rb', line 15 def rendered_output formatter = Rouge::Formatters::HTML.new lexer = Rouge::Lexers::JSON.new formatter.format(lexer.lex(JSON.pretty_generate(JSON.parse(subject)))) rescue JSON::ParserError => e raise Error, "Expected JSON for:\n#{subject}\n\nParser Error: #{e}" end |