Class: Opal::RSpec::BrowserFormatter
- Inherits:
-
RSpec::Core::Formatters::BaseFormatter
- Object
- RSpec::Core::Formatters::BaseFormatter
- Opal::RSpec::BrowserFormatter
- Includes:
- ERB::Util
- Defined in:
- opal/opal/rspec/browser_formatter.rb
Defined Under Namespace
Classes: Element
Constant Summary collapse
- CSS_STYLES =
::RSpec::Core::Formatters::HtmlPrinter::GLOBAL_STYLES
- REPORT_TEMPLATE =
"<div class=\"rspec-report\">\n\n <div id=\"rspec-header\">\n <div id=\"label\">\n <h1>RSpec Code Examples</h1>\n </div>\n\n <div id=\"display-filters\">\n <input id=\"passed_checkbox\" name=\"passed_checkbox\" type=\"checkbox\" checked=\"checked\" onchange=\"apply_filters()\" value=\"1\" /> <label for=\"passed_checkbox\">Passed</label>\n <input id=\"failed_checkbox\" name=\"failed_checkbox\" type=\"checkbox\" checked=\"checked\" onchange=\"apply_filters()\" value=\"2\" /> <label for=\"failed_checkbox\">Failed</label>\n <input id=\"pending_checkbox\" name=\"pending_checkbox\" type=\"checkbox\" checked=\"checked\" onchange=\"apply_filters()\" value=\"3\" /> <label for=\"pending_checkbox\">Pending</label>\n </div>\n\n <div id=\"summary\">\n <p id=\"totals\"> </p>\n <p id=\"duration\"> </p>\n </div>\n </div>\n\n <div id=\"rspec-results\" class=\"results\">\n </div>\n</div>\n"
Instance Method Summary collapse
- #add_scripts ⇒ Object
- #dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object
- #example_failed(example) ⇒ Object
- #example_group_finished(example_group) ⇒ Object
- #example_group_started(example_group) ⇒ Object
- #example_passed(example) ⇒ Object
- #long_padding ⇒ Object
- #short_padding ⇒ Object
- #start(example_count) ⇒ Object
Instance Method Details
#add_scripts ⇒ Object
90 91 92 93 |
# File 'opal/opal/rspec/browser_formatter.rb', line 90 def add_scripts content = ::RSpec::Core::Formatters::HtmlPrinter::GLOBAL_SCRIPTS `window.eval(#{content})` end |
#dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'opal/opal/rspec/browser_formatter.rb', line 78 def dump_summary(duration, example_count, failure_count, pending_count) super totals = "#{example_count} examples, #{failure_count} failures" Element.id('totals').html = totals duration = "Finished in <strong>#{sprintf("%.5f", duration)} seconds</strong>" Element.id('duration').html = duration add_scripts end |
#example_failed(example) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'opal/opal/rspec/browser_formatter.rb', line 48 def example_failed(example) super duration = sprintf("%0.5f", example.execution_result[:run_time]) error = example.execution_result[:exception] error_name = error.class.name.to_s output = "#{short_padding}#{error_name}:\n" error..to_s.split("\n").each { |line| output += "#{long_padding} #{line}\n" } @example_group_failed = true @rspec_dl << Element.new(:dd, class_name: "example failed", html: " <span class=\"failed_spec_name\">\#{h example.description}</span>\n <span class=\"duration\">\#{duration}s</span>\n <div class=\"failure\">\n <div class=\"message\"><pre>\#{h output}</pre></div>\n </div>\n HTML\nend\n") |
#example_group_finished(example_group) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'opal/opal/rspec/browser_formatter.rb', line 38 def example_group_finished(example_group) super if @example_group_failed @rspec_group.class_name = "example_group failed" @rspec_dt.class_name = "failed" Element.id('rspec-header').class_name = 'failed' end end |
#example_group_started(example_group) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'opal/opal/rspec/browser_formatter.rb', line 21 def example_group_started(example_group) super @example_group_failed = false parents = example_group.parent_groups.size @rspec_group = Element.new(:div, class_name: "example_group passed") @rspec_dl = Element.new(:dl) @rspec_dt = Element.new(:dt, class_name: "passed", text: example_group.description) @rspec_group << @rspec_dl @rspec_dl << @rspec_dt @rspec_dl.style 'margin-left', "#{(parents - 2) * 15}px" @rspec_results << @rspec_group end |
#example_passed(example) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'opal/opal/rspec/browser_formatter.rb', line 68 def example_passed(example) super duration = sprintf("%0.5f", example.execution_result[:run_time]) @rspec_dl << Element.new(:dd, class_name: "example passed", html: " <span class=\"passed_spec_name\">\#{h example.description}</span>\n <span class=\"duration\">\#{duration}s</span>\n HTML\nend\n") |
#long_padding ⇒ Object
99 100 101 |
# File 'opal/opal/rspec/browser_formatter.rb', line 99 def long_padding ' ' end |
#short_padding ⇒ Object
95 96 97 |
# File 'opal/opal/rspec/browser_formatter.rb', line 95 def short_padding ' ' end |
#start(example_count) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'opal/opal/rspec/browser_formatter.rb', line 10 def start(example_count) super target = Element.new(`document.body`) target << Element.new(:div, html: REPORT_TEMPLATE) @rspec_results = Element.id('rspec-results') css_text = CSS_STYLES + "\n body { padding: 0; margin: 0 }" styles = Element.new(:style, type: 'text/css', css_text: css_text) styles.append_to_head end |