turnip_formatter 0.2.11 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/README.md +18 -22
  4. data/example/README.md +6 -8
  5. data/example/images/background.png +0 -0
  6. data/example/images/basic_step.png +0 -0
  7. data/example/images/failed_step.png +0 -0
  8. data/example/images/multiline.png +0 -0
  9. data/example/images/outline.png +0 -0
  10. data/example/images/pending_step.png +0 -0
  11. data/example/spec/bar.js +1 -0
  12. data/example/spec/foo.css +3 -0
  13. data/example/spec/spec_helper.rb +7 -2
  14. data/lib/rspec/core/formatters/turnip_formatter.rb +32 -19
  15. data/lib/turnip_formatter/printer/index.rb +6 -9
  16. data/lib/turnip_formatter/printer/scenario.rb +4 -2
  17. data/lib/turnip_formatter/printer/step.rb +16 -14
  18. data/lib/turnip_formatter/printer/step_extra_args.rb +2 -0
  19. data/lib/turnip_formatter/printer/tab_speed_statistics.rb +2 -1
  20. data/lib/turnip_formatter/printer/tab_tag_statistics.rb +5 -6
  21. data/lib/turnip_formatter/printer.rb +6 -11
  22. data/lib/turnip_formatter/scenario/base.rb +98 -0
  23. data/lib/turnip_formatter/scenario/failure.rb +19 -21
  24. data/lib/turnip_formatter/scenario/pass.rb +2 -13
  25. data/lib/turnip_formatter/scenario/pending.rb +19 -25
  26. data/lib/turnip_formatter/step.rb +8 -38
  27. data/lib/turnip_formatter/step_template/base.rb +34 -0
  28. data/lib/turnip_formatter/step_template/exception.rb +59 -50
  29. data/lib/turnip_formatter/step_template/source.rb +36 -34
  30. data/lib/turnip_formatter/template/exception.haml +8 -0
  31. data/lib/turnip_formatter/template/index.haml +88 -0
  32. data/lib/turnip_formatter/template/runtime_exception.haml +13 -0
  33. data/lib/turnip_formatter/template/scenario.haml +14 -0
  34. data/lib/turnip_formatter/template/step.haml +6 -0
  35. data/lib/turnip_formatter/template/step_multiline.haml +1 -0
  36. data/lib/turnip_formatter/template/step_outline.haml +6 -0
  37. data/lib/turnip_formatter/template/tab_feature_statistics.haml +18 -0
  38. data/lib/turnip_formatter/template/tab_speed_statistics.haml +16 -0
  39. data/lib/turnip_formatter/template/tab_tag_statistics.haml +18 -0
  40. data/lib/turnip_formatter/template/turnip_formatter.js +8 -25
  41. data/lib/turnip_formatter/template/turnip_formatter.scss +102 -174
  42. data/lib/turnip_formatter/template.rb +65 -39
  43. data/lib/turnip_formatter/version.rb +1 -1
  44. data/lib/turnip_formatter.rb +45 -7
  45. data/spec/spec_helper.rb +6 -1
  46. data/spec/support/example_helper.rb +36 -0
  47. data/spec/support/step_helper.rb +27 -0
  48. data/spec/turnip_formatter/printer/index_spec.rb +10 -10
  49. data/spec/turnip_formatter/printer/scenario_spec.rb +29 -23
  50. data/spec/turnip_formatter/printer/step_extra_args_spec.rb +6 -6
  51. data/spec/turnip_formatter/printer/step_spec.rb +36 -69
  52. data/spec/turnip_formatter/printer/tab_feature_statistics_spec.rb +1 -4
  53. data/spec/turnip_formatter/printer/tab_speed_statistics_spec.rb +1 -4
  54. data/spec/turnip_formatter/printer/tab_tag_statistics_spec.rb +1 -4
  55. data/spec/turnip_formatter/scenario/base_spec.rb +67 -0
  56. data/spec/turnip_formatter/scenario/failure_spec.rb +16 -38
  57. data/spec/turnip_formatter/scenario/pending_spec.rb +16 -39
  58. data/spec/turnip_formatter/step_template/base_spec.rb +82 -0
  59. data/spec/turnip_formatter/step_template/exception_spec.rb +25 -17
  60. data/spec/turnip_formatter/step_template/source_spec.rb +10 -13
  61. data/turnip_formatter.gemspec +15 -11
  62. metadata +83 -41
  63. data/example/images/tag_step.png +0 -0
  64. data/images/tab_feature_statistics.png +0 -0
  65. data/images/tab_speed_statistics.png +0 -0
  66. data/images/tab_steps.png +0 -0
  67. data/images/tab_steps_expanding.png +0 -0
  68. data/images/tab_tag_statistics.png +0 -0
  69. data/lib/turnip_formatter/ext/turnip/builder.rb +0 -47
  70. data/lib/turnip_formatter/scenario.rb +0 -89
  71. data/lib/turnip_formatter/step/dsl.rb +0 -33
  72. data/lib/turnip_formatter/step/failure.rb +0 -19
  73. data/lib/turnip_formatter/step/pending.rb +0 -19
  74. data/lib/turnip_formatter/step_template.rb +0 -8
  75. data/lib/turnip_formatter/template/exception.erb +0 -10
  76. data/lib/turnip_formatter/template/exception_backtrace.erb +0 -7
  77. data/lib/turnip_formatter/template/index.erb +0 -70
  78. data/lib/turnip_formatter/template/runtime_exception.erb +0 -16
  79. data/lib/turnip_formatter/template/scenario.erb +0 -25
  80. data/lib/turnip_formatter/template/section_report.erb +0 -15
  81. data/lib/turnip_formatter/template/step.erb +0 -4
  82. data/lib/turnip_formatter/template/step_multiline.erb +0 -1
  83. data/lib/turnip_formatter/template/step_outline.erb +0 -9
  84. data/lib/turnip_formatter/template/tab_feature_statistics.erb +0 -24
  85. data/lib/turnip_formatter/template/tab_speed_statistics.erb +0 -18
  86. data/lib/turnip_formatter/template/tab_tag_statistics.erb +0 -24
  87. data/spec/rspec/core/formatters/turnip_formatter_spec.rb +0 -78
  88. data/spec/support/shared_context_examples.rb +0 -39
  89. data/spec/turnip_formatter/scenario/pass_spec.rb +0 -54
  90. data/spec/turnip_formatter/step/failure_spec.rb +0 -64
  91. data/spec/turnip_formatter/step/pending_spec.rb +0 -63
  92. data/spec/turnip_formatter/step_spec.rb +0 -86
@@ -1,47 +1,17 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  module TurnipFormatter
4
2
  class Step
5
- attr_reader :name, :docs, :example
6
-
7
- class << self
8
- def templates
9
- @templates ||= {}
10
- end
11
-
12
- def add_template(status, klass = nil, &block)
13
- templates[status] ||= {}
14
- templates[status][klass] = { klass: klass, block: block }
15
- end
16
-
17
- def remove_template(status, klass)
18
- key = status.to_sym
19
- return unless templates.key?(key)
20
- templates[key].delete(klass)
21
- templates.delete(key) if templates[key].empty?
22
- end
23
-
24
- def status
25
- ''
26
- end
27
- end
3
+ attr_reader :name, :example, :extra_args
4
+ attr_accessor :status
28
5
 
29
6
  #
30
7
  # @param [RSpec::Core::Example] example
31
- # @param [Hash] description
8
+ # @param [Hash] raw
32
9
  #
33
- def initialize(example, description)
34
- @example = example
35
- @name = description[:keyword] + description[:name]
36
- @docs = { extra_args: { klass: nil, value: description[:extra_args] } }
37
- end
38
-
39
- def attention?
40
- !status.empty?
41
- end
42
-
43
- def status
44
- self.class.status
10
+ def initialize(example, raw)
11
+ @example = example
12
+ @name = raw[:keyword].strip + ' ' + raw[:name]
13
+ @extra_args = raw[:extra_args]
14
+ @status = :passed
45
15
  end
46
16
  end
47
17
  end
@@ -0,0 +1,34 @@
1
+ module TurnipFormatter
2
+ module StepTemplate
3
+ class Base
4
+ class << self
5
+ def inherited(child)
6
+ TurnipFormatter.step_templates << child.new
7
+ end
8
+
9
+ def on_passed(template)
10
+ hooks[:passed] << template
11
+ end
12
+
13
+ def on_failed(template)
14
+ hooks[:failed] << template
15
+ end
16
+
17
+ def on_pending(template)
18
+ hooks[:pending] << template
19
+ end
20
+
21
+ def hooks
22
+ @hooks ||= { passed: [], failed: [], pending: [] }
23
+ end
24
+
25
+ #
26
+ # Return SCSS string that be used in this class
27
+ #
28
+ def scss
29
+ ''
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,61 +1,70 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'turnip_formatter/step/failure'
4
- require 'turnip_formatter/step/pending'
5
- require 'erb'
1
+ require 'turnip_formatter/step_template/base'
2
+ require 'haml'
6
3
 
7
4
  module TurnipFormatter
8
5
  module StepTemplate
9
- module Exception
10
- def self.build(exception)
11
- template_step_exception.result(binding)
12
- end
6
+ class Exception < Base
7
+ on_failed :build_failed
8
+ on_pending :build_pending
13
9
 
14
- private
10
+ def self.scss
11
+ <<-EOS
12
+ div#steps-statistics section.scenario {
13
+ div.steps {
14
+ div.step_exception {
15
+ margin: 1em 0em;
16
+ padding: 1em;
17
+ border: 1px solid #999999;
18
+ background-color: #eee8d5;
19
+ color: #586e75;
15
20
 
16
- def self.template_step_exception
17
- @template_step_exception ||= ERB.new(<<-EOS)
18
- <div class="step_exception">
19
- <span>Failure:</span>
20
- <pre><%= ERB::Util.h(exception.to_s) %></pre>
21
- <span>Backtrace:</span>
22
- <ol>
23
- <% exception.backtrace.each do |line| %>
24
- <li><%= ERB::Util.h(line) %></li>
25
- <% end %>
26
- </ol>
27
- </div>
21
+ dd {
22
+ margin-top: 1em;
23
+ margin-left: 1em;
24
+ }
25
+ }
26
+ }
27
+ }
28
28
  EOS
29
29
  end
30
- end
31
- end
32
30
 
33
- Template.add_scss(<<-EOS)
34
- div#steps-statistics section.scenario {
35
- ul.steps {
36
- div.step_exception {
37
- margin: 1em 0em;
38
- padding: 1em 0em 1em 1em;
39
- border: 1px solid #999999;
40
- background-color: #eee8d5;
41
- color: #586e75;
42
-
43
- > pre {
44
- margin-left: 1em;
45
- }
46
- }
47
- }
48
- }
49
- EOS
50
-
51
- Step::Failure.add_template StepTemplate::Exception do
52
- example.exception
53
- end
31
+ #
32
+ # @param [RSpec::Core::Example] example
33
+ #
34
+ def build_failed(example)
35
+ build(example.exception)
36
+ end
54
37
 
55
- Step::Pending.add_template StepTemplate::Exception do
56
- message = example.execution_result[:pending_message]
57
- exception = RSpec::Core::Pending::PendingDeclaredInExample.new(message)
58
- exception.set_backtrace(example.location)
59
- exception
38
+ #
39
+ # @param [RSpec::Core::Example] example
40
+ #
41
+ def build_pending(example)
42
+ message = example.execution_result[:pending_message]
43
+ exception = RSpec::Core::Pending::PendingDeclaredInExample.new(message)
44
+ exception.set_backtrace([example.location])
45
+ build(exception)
46
+ end
47
+
48
+ private
49
+
50
+ def build(exception)
51
+ template_step_exception.render(exception)
52
+ end
53
+
54
+ def template_step_exception
55
+ @template_step_exception ||= Haml::Engine.new(<<-EOS)
56
+ %div.step_exception
57
+ %dl
58
+ %dt Failure:
59
+ %dd
60
+ %pre&= exception.to_s
61
+ %dt Backtrace:
62
+ %dd
63
+ %ol
64
+ - exception.backtrace.each do |line|
65
+ %li&= line
66
+ EOS
67
+ end
68
+ end
60
69
  end
61
70
  end
@@ -1,46 +1,48 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'turnip_formatter/step/failure'
1
+ require 'turnip_formatter/step_template/base'
4
2
  require 'rspec/core/formatters/snippet_extractor'
5
3
 
6
4
  module TurnipFormatter
7
5
  module StepTemplate
8
- module Source
9
- def self.build(location)
10
- code = extractor.snippet([location])
6
+ class Source < Base
7
+ on_failed :build
8
+
9
+ def self.scss
10
+ <<-EOS
11
+ pre.source {
12
+ font-size: 12px;
13
+ font-family: monospace;
14
+ background-color: #073642;
15
+ color: #dddddd;
16
+
17
+ code.ruby {
18
+ padding: 0.1em 0 0.2em 0;
19
+
20
+ .linenum {
21
+ width: 75px;
22
+ color: #fffbd3;
23
+ padding-right: 1em;
24
+ }
25
+
26
+ .offending { background-color: gray; }
27
+ }
28
+ }
29
+ EOS
30
+ end
31
+
32
+ def build(example)
33
+ code = extractor.snippet([location(example)])
11
34
  '<pre class="source"><code class="ruby">' + code + '</code></pre>'
12
35
  end
13
36
 
14
37
  private
15
38
 
16
- def self.extractor
17
- @extractor ||= ::RSpec::Core::Formatters::SnippetExtractor.new
18
- end
19
- end
20
- end
39
+ def location(example)
40
+ example.exception.backtrace.first
41
+ end
21
42
 
22
- Template.add_scss(<<-EOS)
23
- pre.source {
24
- font-size: 12px;
25
- font-family: monospace;
26
- background-color: #073642;
27
- color: #dddddd;
28
-
29
- code.ruby {
30
- padding: 0.1em 0 0.2em 0;
31
-
32
- .linenum {
33
- width: 75px;
34
- color: #fffbd3;
35
- padding-right: 1em;
36
- }
37
-
38
- .offending { background-color: gray; }
39
- }
40
- }
41
- EOS
42
-
43
- Step::Failure.add_template(StepTemplate::Source) do
44
- example.exception.backtrace.first
43
+ def extractor
44
+ @extractor ||= ::RSpec::Core::Formatters::SnippetExtractor.new
45
+ end
46
+ end
45
47
  end
46
48
  end
@@ -0,0 +1,8 @@
1
+ %dt&= title + ' Exception'
2
+ %dd
3
+ %pre&= exception.to_s
4
+ %dt&= title + ' Exception Backtrace'
5
+ %dd
6
+ %ol
7
+ - exception.backtrace.each do |line|
8
+ %li&= line
@@ -0,0 +1,88 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %meta{ :charset => "UTF-8" }
5
+ %title= TurnipFormatter::Template.project_name + ' report'
6
+
7
+ = TurnipFormatter::Template.render_stylesheet_links
8
+ %style= TurnipFormatter::Template.render_stylesheet_codes
9
+
10
+ %script{ src: 'http://code.jquery.com/jquery-1.11.0.min.js' }
11
+ %script{ src: 'http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js' }
12
+ %script{ src: 'http://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.17.0/jquery.tablesorter.min.js' }
13
+
14
+ = TurnipFormatter::Template.render_javascript_links
15
+ %script= TurnipFormatter::Template.render_javascript_codes
16
+
17
+ %body
18
+ %header#report
19
+ .container
20
+ .page-header
21
+ %h1= TurnipFormatter::Template.project_name + ' Report'
22
+
23
+ %section#status_display_switch
24
+ %label{ for: 'passed_check' }
25
+ %input#passed_check{ type: 'checkbox' }
26
+ Passed
27
+ %label{ for: 'failed_check' }
28
+ %input#failed_check{ type: 'checkbox', checked: 'checked' }
29
+ Failed
30
+ %label{ for: 'pending_check' }
31
+ %input#pending_check{ type: 'checkbox' }
32
+ Pending
33
+
34
+ %section.result
35
+ %p
36
+ %span#total_count&= scenarios.size
37
+ Scenario (
38
+ %span#failed_count&= failed_count
39
+ failed
40
+ %span#pending_count&= pending_count
41
+ pending).
42
+ %p
43
+ Finished in
44
+ %span#total_time&= total_time.to_s + ' sec'
45
+
46
+ #main.container{ role: 'main' }
47
+ %ul#statistics{ class: 'nav nav-tabs' }
48
+ %li.active
49
+ %a{ href: '#steps-statistics', data: { toggle: 'tab' } } Steps
50
+ %li
51
+ %a{ href: '#speed-statistics', data: { toggle: 'tab' } } Speed Statistics
52
+ %li
53
+ %a{ href: '#feature-statistics', data: { toggle: 'tab' } } Feature Statistics
54
+ %li
55
+ %a{ href: '#tag-statistics', data: { toggle: 'tab' } } Tag Statistics
56
+
57
+ .tab-content
58
+ #steps-statistics{ class: 'tab-pane active' }
59
+ .checkbox
60
+ %label
61
+ %input#scenario_display_check{ type: 'checkbox', checked: 'checked' }
62
+ Folding
63
+ #scenarios.panel-group
64
+ - scenario_files.each do |f|
65
+ = File.read(f)
66
+
67
+ #feature-statistics.tab-pane
68
+ %h4 The results for the feature:
69
+ = TurnipFormatter::Printer::TabFeatureStatistics.print_out(scenarios)
70
+
71
+ #tag-statistics.tab-pane
72
+ %h4 The results for the tab:
73
+ = TurnipFormatter::Printer::TabTagStatistics.print_out(scenarios)
74
+
75
+ #speed-statistics.tab-pane
76
+ %h4 Ranking of running time of each <strong>successfully</strong> scenario:
77
+ = TurnipFormatter::Printer::TabSpeedStatistics.print_out(scenarios)
78
+
79
+ %footer
80
+ %p
81
+ Generated by
82
+ %a{ href: 'https://rubygems.org/gems/turnip_formatter'} turnip_formatter
83
+ = TurnipFormatter::VERSION
84
+ %p
85
+ Powered by
86
+ %a{ href: 'http://jquery.com/' } jQuery 1.11.0
87
+ and
88
+ %a{ href: 'http://mottie.github.io/tablesorter/' } tablesorter 2.17.0
@@ -0,0 +1,13 @@
1
+ %section.exception
2
+ %h1 TurnipFormatter RuntimeError
3
+ %dl
4
+ = runtime_exception
5
+
6
+ %dt Example Full Description
7
+ %dd&= example.metadata[:full_description]
8
+
9
+ = example_exception
10
+
11
+ - if example.pending
12
+ %dt Example Pending description
13
+ %dd&= example.metadata[:description]
@@ -0,0 +1,14 @@
1
+ %section{ class: "scenario #{scenario.status}", id: scenario.id }
2
+ %div.scenario-title
3
+ %span.permalink
4
+ %a{ href: "##{scenario.id}"} &para;
5
+ %span{ data: { toggle: "collapse", target: "##{scenario.id}_body" } }
6
+ &= "Scenario: #{scenario.name} Feature #{scenario.feature_info} at #{scenario.run_time} sec"
7
+ %div{ class: "panel-collapse collapse", id: "#{scenario.id}_body" }
8
+ %div.panel-body
9
+ %ul.tags
10
+ - scenario.tags.each do |tag|
11
+ %li @#{tag}
12
+ %div.steps
13
+ - scenario.steps.each do |step|
14
+ = TurnipFormatter::Printer::Step.print_out(step)
@@ -0,0 +1,6 @@
1
+ %div{ class: "step #{step.status}" }
2
+ %div.step-title&= step.name
3
+ - if has_args_or_documents
4
+ %div.step-body
5
+ = TurnipFormatter::Printer::StepExtraArgs.print_out(step.extra_args)
6
+ ~ step_docs
@@ -0,0 +1 @@
1
+ %pre.multiline&= lines
@@ -0,0 +1,6 @@
1
+ %table.step_outline
2
+ - table.each do |tr|
3
+ %tr
4
+ - tr.each do |td|
5
+ %td
6
+ &= td
@@ -0,0 +1,18 @@
1
+ %table
2
+ %thead
3
+ %tr
4
+ %th Feature
5
+ %th Scearios
6
+ %th passed
7
+ %th failed
8
+ %th pending
9
+ %th status
10
+ %tbody
11
+ - analysis_results.each do |info|
12
+ %tr
13
+ %td= info.name
14
+ %td= info.scenario_count
15
+ %td= info.passed_count
16
+ %td= info.failed_count
17
+ %td= info.pending_count
18
+ %td{ class: info.status }= info.status
@@ -0,0 +1,16 @@
1
+ %table
2
+ %thead
3
+ %tr
4
+ %th Feature
5
+ %th Scenario
6
+ %th Duration
7
+ %tbody
8
+ - analysis_results.each do |info|
9
+ %tr
10
+ %td
11
+ %span&= info.feature_name
12
+ %td
13
+ %a{ href: '#' + info.id}&= info.name
14
+ %td
15
+ %span&= info.run_time
16
+ sec
@@ -0,0 +1,18 @@
1
+ %table
2
+ %thead
3
+ %tr
4
+ %th Tag
5
+ %th Scearios
6
+ %th passed
7
+ %th failed
8
+ %th pending
9
+ %th status
10
+ %tbody
11
+ - analysis_results.each do |info|
12
+ %tr
13
+ %td&= info.name
14
+ %td&= info.scenario_count
15
+ %td&= info.passed_count
16
+ %td&= info.failed_count
17
+ %td&= info.pending_count
18
+ %td{ class: info.status }&= info.status
@@ -1,25 +1,16 @@
1
1
  $(function() {
2
- var scenarioHeader = 'section.scenario header';
3
- $(scenarioHeader).siblings().hide();
2
+ $('#statistics ul li a').click(function (e) {
3
+ e.preventDefault()
4
+ $(this).tab('show')
5
+ })
4
6
 
5
- /**
6
- * Step folding/expanding
7
- */
8
- $(scenarioHeader).click(function() {
9
- $(this).siblings().slideToggle();
7
+ $('#speed-statistics a').click(function(e) {
8
+ $('#statistics a[href="#steps-statistics"]').tab('show');
10
9
  });
11
10
 
12
- /**
13
- * All step folding/expanding action
14
- */
15
11
  $('#scenario_display_check').change(function() {
16
- var steps = $(scenarioHeader).siblings();
17
-
18
- if (this.checked) {
19
- steps.slideUp();
20
- } else {
21
- steps.slideDown();
22
- }
12
+ var action = $(this).prop("checked") ? 'show' : 'hide';
13
+ $('.panel-collapse').collapse(action);
23
14
  });
24
15
 
25
16
  ["passed", "failed", "pending"].forEach(function(status) {
@@ -35,14 +26,6 @@ $(function() {
35
26
  $(".scenario.passed").hide();
36
27
  $(".scenario.pending").hide();
37
28
 
38
- /**
39
- * Tabs
40
- */
41
- $('div#main').tabs();
42
- $('div#speed-statistics a').click(function() {
43
- $('div#main').tabs("option", "active", 0);
44
- });
45
-
46
29
  $("div#speed-statistics table").tablesorter({
47
30
  headers: {
48
31
  1: { sorter: false }