turnip_formatter 0.0.1 → 0.0.2

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 (35) hide show
  1. data/lib/turnip_formatter/ext/turnip/rspec.rb +10 -11
  2. data/lib/turnip_formatter/scenario/failure.rb +3 -13
  3. data/lib/turnip_formatter/scenario/pending.rb +8 -5
  4. data/lib/turnip_formatter/scenario.rb +33 -22
  5. data/lib/turnip_formatter/step/dsl.rb +18 -0
  6. data/lib/turnip_formatter/step/failure.rb +15 -9
  7. data/lib/turnip_formatter/step/pending.rb +13 -8
  8. data/lib/turnip_formatter/step.rb +29 -7
  9. data/lib/turnip_formatter/template/step_exception.rb +28 -0
  10. data/lib/turnip_formatter/template/step_multiline.rb +11 -0
  11. data/lib/turnip_formatter/template/step_outline.rb +27 -0
  12. data/lib/turnip_formatter/template/step_source.rb +12 -0
  13. data/lib/turnip_formatter/template.rb +19 -56
  14. data/lib/turnip_formatter/version.rb +1 -1
  15. data/spec/examples/README.md +3 -1
  16. data/spec/examples/images/background.png +0 -0
  17. data/spec/examples/images/basic_step.png +0 -0
  18. data/spec/examples/images/failed_step.png +0 -0
  19. data/spec/examples/images/multiline.png +0 -0
  20. data/spec/examples/images/outline.png +0 -0
  21. data/spec/examples/images/pending_step.png +0 -0
  22. data/spec/examples/images/tag_step.png +0 -0
  23. data/spec/rspec/core/formatters/turnip_formatter_spec.rb +18 -17
  24. data/spec/support/shared_context_examples.rb +10 -1
  25. data/spec/turnip_formatter/scenario/pass_spec.rb +5 -19
  26. data/spec/turnip_formatter/step/failure_spec.rb +14 -26
  27. data/spec/turnip_formatter/step/pending_spec.rb +12 -13
  28. data/spec/turnip_formatter/step_spec.rb +4 -11
  29. data/spec/turnip_formatter/template/step_exception_spec.rb +24 -0
  30. data/spec/turnip_formatter/template/step_multiline_spec.rb +16 -0
  31. data/spec/turnip_formatter/template/step_outline_spec.rb +29 -0
  32. data/spec/turnip_formatter/template/step_source_spec.rb +19 -0
  33. data/spec/turnip_formatter/template_spec.rb +21 -60
  34. metadata +21 -6
  35. data/spec/examples/images/pending_and_tagged_step.png +0 -0
@@ -17,21 +17,20 @@ module Turnip
17
17
  end
18
18
 
19
19
  def initialize_scenario_metadata
20
- example.metadata[:steps] = {
21
- descriptions: [],
22
- docstrings: [],
23
- keywords: [],
24
- tags: [],
25
- }
20
+ example.metadata[:turnip] = { steps: [] }
26
21
  end
27
22
 
28
23
  def push_scenario_metadata(scenario)
29
24
  steps = scenario.steps
30
- example.metadata[:steps].tap do |meta|
31
- meta[:descriptions] += steps.map(&:description)
32
- meta[:docstrings] += steps.map(&:extra_args)
33
- meta[:keywords] += steps.map(&:keyword)
34
- meta[:tags] = scenario.tags if scenario.respond_to?(:tags)
25
+ example.metadata[:turnip].tap do |turnip|
26
+ steps.each do |step|
27
+ turnip[:steps] << {
28
+ name: step.description,
29
+ extra_args: step.extra_args,
30
+ keyword: step.keyword
31
+ }
32
+ end
33
+ turnip[:tags] = scenario.tags if scenario.respond_to?(:tags)
35
34
  end
36
35
  end
37
36
  end
@@ -11,19 +11,15 @@ module TurnipFormatter
11
11
 
12
12
  class Failure
13
13
  include TurnipFormatter::Scenario
14
- include RSpec::Core::BacktraceFormatter
15
14
 
16
15
  def steps
17
16
  steps = super
18
- steps[offending_line].tap do |step|
19
- step.extend TurnipFormatter::Step::Failure
20
- step.attention(exception, backtrace)
21
- end
17
+ steps[offending_line].extend TurnipFormatter::Step::Failure
22
18
  steps
23
19
  end
24
20
 
25
21
  def validation
26
- raise NotFailedScenarioError if (status != 'failed')
22
+ raise NotFailedScenarioError if status != 'failed'
27
23
  offending_line
28
24
  super
29
25
  end
@@ -31,17 +27,11 @@ module TurnipFormatter
31
27
  private
32
28
 
33
29
  def offending_line
34
- unless backtrace.last =~ /:in step:(?<stepno>\d+) `/
30
+ unless example.exception.backtrace.last =~ /:in step:(?<stepno>\d+) `/
35
31
  raise NoExistFailedStepInformationError
36
32
  end
37
33
  $~[:stepno].to_i
38
34
  end
39
-
40
- def backtrace
41
- @backtrace ||= format_backtrace(exception.backtrace, scenario.metadata).map do |b|
42
- backtrace_line(b)
43
- end.compact
44
- end
45
35
  end
46
36
  end
47
37
  end
@@ -13,10 +13,7 @@ module TurnipFormatter
13
13
 
14
14
  def steps
15
15
  steps = super
16
- steps[offending_line].tap do |step|
17
- step.extend TurnipFormatter::Step::Pending
18
- step.attention(pending_message, scenario.location)
19
- end
16
+ steps[offending_line].extend TurnipFormatter::Step::Pending
20
17
  steps
21
18
  end
22
19
 
@@ -29,9 +26,15 @@ module TurnipFormatter
29
26
  private
30
27
 
31
28
  def offending_line
32
- raise NoExistPendingStepInformationError unless pending_message =~ /^No such step\((?<stepno>\d+)\): /
29
+ unless pending_message =~ /^No such step\((?<stepno>\d+)\): /
30
+ raise NoExistPendingStepInformationError
31
+ end
33
32
  $~[:stepno].to_i
34
33
  end
34
+
35
+ def pending_message
36
+ example.execution_result[:pending_message]
37
+ end
35
38
  end
36
39
  end
37
40
  end
@@ -4,6 +4,8 @@ require 'turnip_formatter/step'
4
4
 
5
5
  module TurnipFormatter
6
6
  module Scenario
7
+ include RSpec::Core::BacktraceFormatter
8
+
7
9
  class NotExistStepsInformationError < ::StandardError; end
8
10
  class NoFeatureFileError < ::StandardError; end
9
11
 
@@ -11,53 +13,62 @@ module TurnipFormatter
11
13
  # @param [RSpec::Core::Example] example
12
14
  #
13
15
  def initialize(example)
14
- @scenario = example
16
+ @example = example
17
+ clean_backtrace
15
18
  end
16
19
 
17
20
  def validation
18
- raise NotExistStepsInformationError unless scenario.metadata.member?(:steps)
21
+ raise NotExistStepsInformationError unless example.metadata.member?(:turnip)
19
22
  raise NoFeatureFileError unless feature_file_path.end_with?('.feature')
20
23
  end
21
24
 
22
25
  def steps
23
- descriptions.map { |desc| TurnipFormatter::Step.new(desc) }
24
- end
25
-
26
- def method_missing(name, *args, &block)
27
- if scenario.execution_result.member?(name.to_sym)
28
- scenario.execution_result[name.to_sym]
29
- else
30
- super
26
+ @steps ||= descriptions.map do |desc|
27
+ TurnipFormatter::Step.new(example, desc)
31
28
  end
32
29
  end
33
-
30
+
31
+ #
32
+ # @return [String] scenario name
33
+ #
34
34
  def name
35
- scenario.example_group.description
35
+ example.example_group.description
36
+ end
37
+
38
+ #
39
+ # @return [String] scenario status ('passed', 'failed' or 'pending')
40
+ #
41
+ def status
42
+ example.execution_result[:status]
36
43
  end
37
44
 
38
45
  def feature_name
39
- @scenario.example_group.metadata[:example_group][:example_group][:description]
46
+ example.example_group.metadata[:example_group][:example_group][:description]
40
47
  end
41
48
 
42
49
  def feature_file_path
43
- scenario.metadata[:file_path]
50
+ example.metadata[:file_path]
44
51
  end
45
52
 
46
53
  def tags
47
- scenario.metadata[:steps][:tags]
54
+ example.metadata[:turnip][:tags]
55
+ end
56
+
57
+ def example
58
+ @example
48
59
  end
49
60
 
50
61
  private
51
62
 
52
- def scenario
53
- @scenario
63
+ def descriptions
64
+ example.metadata[:turnip][:steps]
54
65
  end
55
66
 
56
- def descriptions
57
- descriptions = scenario.metadata[:steps][:descriptions]
58
- keywords = scenario.metadata[:steps][:keywords]
59
- docstrings = scenario.metadata[:steps][:docstrings]
60
- descriptions.zip(keywords, docstrings)
67
+ def clean_backtrace
68
+ return if example.exception.nil?
69
+ formatted = format_backtrace(example.exception.backtrace, example.metadata)
70
+ new_backtrace = formatted.map { |b| backtrace_line(b) }.compact
71
+ example.exception.set_backtrace(new_backtrace)
61
72
  end
62
73
  end
63
74
  end
@@ -0,0 +1,18 @@
1
+ module TurnipFormatter
2
+ class Step
3
+ module DSL
4
+ #
5
+ # @param [TurnipFormatter::Step] step
6
+ #
7
+ def extended(step)
8
+ ::TurnipFormatter::Step.templates[status].each do |style, block|
9
+ step.docs[style] = step.instance_eval(&block)
10
+ end
11
+ end
12
+
13
+ def add_template(style, &block)
14
+ ::TurnipFormatter::Step.add_template(status, style, &block)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,21 +1,27 @@
1
1
  # -*- coding: utf-8 -*-
2
+ require 'turnip_formatter/step'
3
+ require 'turnip_formatter/step/dsl'
2
4
 
3
5
  module TurnipFormatter
4
6
  class Step
5
7
  module Failure
6
- def attention?
7
- true
8
- end
9
-
10
- def attention(exception, backtrace)
11
- exception.set_backtrace(backtrace)
12
- docs[:source] = backtrace.first
13
- docs[:exception] = exception
8
+ extend DSL
9
+
10
+ def self.status
11
+ :failure
14
12
  end
15
13
 
16
14
  def status
17
- 'failure'
15
+ Failure.status
18
16
  end
19
17
  end
20
18
  end
21
19
  end
20
+
21
+ TurnipFormatter::Step::Failure.add_template :source do
22
+ example.exception.backtrace.first
23
+ end
24
+
25
+ TurnipFormatter::Step::Failure.add_template :exception do
26
+ example.exception
27
+ end
@@ -1,21 +1,26 @@
1
1
  # -*- coding: utf-8 -*-
2
+ require 'turnip_formatter/step'
3
+ require 'turnip_formatter/step/dsl'
2
4
 
3
5
  module TurnipFormatter
4
6
  class Step
5
7
  module Pending
6
- def attention?
7
- true
8
- end
8
+ extend DSL
9
9
 
10
- def attention(message, location)
11
- exception = RSpec::Core::Pending::PendingDeclaredInExample.new(message)
12
- exception.set_backtrace(location)
13
- docs[:exception] = exception
10
+ def self.status
11
+ :pending
14
12
  end
15
13
 
16
14
  def status
17
- 'pending'
15
+ Pending.status
18
16
  end
19
17
  end
20
18
  end
21
19
  end
20
+
21
+ TurnipFormatter::Step::Pending.add_template :exception do
22
+ message = example.execution_result[:pending_message]
23
+ exception = RSpec::Core::Pending::PendingDeclaredInExample.new(message)
24
+ exception.set_backtrace(example.location)
25
+ exception
26
+ end
@@ -2,17 +2,39 @@
2
2
 
3
3
  module TurnipFormatter
4
4
  class Step
5
- attr_reader :name, :docs
5
+ attr_reader :name, :docs, :example
6
6
 
7
- def initialize(description)
8
- step_name, keyword, docstring = description
9
- @name = keyword + step_name
10
- @docs = {}
11
- @docs[:extra_args] = docstring unless docstring.empty?
7
+ class << self
8
+ def templates
9
+ @templates ||= {}
10
+ end
11
+
12
+ def add_template(status, style, &block)
13
+ templates[status] ||= {}
14
+ templates[status][style] = block
15
+ end
16
+
17
+ def status
18
+ ''
19
+ end
20
+ end
21
+
22
+ #
23
+ # @param [RSpec::Core::Example] example
24
+ # @param [Hash] description
25
+ #
26
+ def initialize(example, description)
27
+ @example = example
28
+ @name = description[:keyword] + description[:name]
29
+ @docs = { extra_args: description[:extra_args] }
12
30
  end
13
31
 
14
32
  def attention?
15
- false
33
+ !status.empty?
34
+ end
35
+
36
+ def status
37
+ self.class.status
16
38
  end
17
39
  end
18
40
  end
@@ -0,0 +1,28 @@
1
+ require 'erb'
2
+
3
+ module TurnipFormatter
4
+ class Template
5
+ module StepException
6
+ def self.build(exception)
7
+ template_step_exception.result(binding)
8
+ end
9
+
10
+ private
11
+
12
+ def self.template_step_exception
13
+ @template_step_exception ||= ERB.new(<<-EOS)
14
+ <div class="step_exception">
15
+ <span>Failure:</span>
16
+ <pre><%= ERB::Util.h(exception.to_s) %></pre>
17
+ <span>Backtrace:</span>
18
+ <ol>
19
+ <% exception.backtrace.each do |line| %>
20
+ <li><%= ERB::Util.h(line) %></li>
21
+ <% end %>
22
+ </ol>
23
+ </div>
24
+ EOS
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ require 'erb'
2
+
3
+ module TurnipFormatter
4
+ class Template
5
+ module StepMultiline
6
+ def self.build(lines)
7
+ '<pre class="multiline">' + ERB::Util.h(lines) + '</pre>'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ require 'erb'
2
+
3
+ module TurnipFormatter
4
+ class Template
5
+ module StepOutline
6
+ def self.build(table)
7
+ template_step_outline.result(binding)
8
+ end
9
+
10
+ private
11
+
12
+ def self.template_step_outline
13
+ @template_step_outline ||= ERB.new(<<-EOS)
14
+ <table class="step_outline">
15
+ <% table.each do |tr| %>
16
+ <tr>
17
+ <% tr.each do |td| %>
18
+ <td><%= ERB::Util.h(td) %></td>
19
+ <% end %>
20
+ </tr>
21
+ <% end %>
22
+ </table>
23
+ EOS
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ require 'erb'
2
+
3
+ module TurnipFormatter
4
+ class Template
5
+ module StepSource
6
+ def self.build(location)
7
+ @snippet_extractor ||= ::RSpec::Core::Formatters::SnippetExtractor.new
8
+ '<pre class="source"><code class="ruby">' + @snippet_extractor.snippet([location]) + '</code></pre>'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -8,6 +8,11 @@ module TurnipFormatter
8
8
  include ERB::Util
9
9
  include RSpec::Core::BacktraceFormatter
10
10
 
11
+ autoload :StepOutline, 'turnip_formatter/template/step_outline'
12
+ autoload :StepMultiline, 'turnip_formatter/template/step_multiline'
13
+ autoload :StepSource, 'turnip_formatter/template/step_source'
14
+ autoload :StepException, 'turnip_formatter/template/step_exception'
15
+
11
16
  def print_header
12
17
  <<-EOS
13
18
  <!DOCTYPE html>
@@ -59,7 +64,6 @@ module TurnipFormatter
59
64
  end
60
65
 
61
66
  def print_runtime_error(example, exception)
62
-
63
67
  if example.exception
64
68
  example_backtrace = format_backtrace(example.exception.backtrace[0..14], example.metadata).map do |l|
65
69
  RSpec::Core::Metadata::relative_path(l)
@@ -89,38 +93,26 @@ module TurnipFormatter
89
93
  end
90
94
 
91
95
  def step_args(step)
92
- args = []
93
- [:extra_args, :source, :exception].each do |k|
94
- args << send("step_#{k}", step.docs[k]) unless step.docs[k].nil?
95
- end
96
- args.join("\n")
97
- end
96
+ output = []
98
97
 
99
- def step_extra_args(extra_args)
100
- extra_args.map do |arg|
101
- if arg.instance_of?(Turnip::Table)
102
- step_outline(arg)
98
+ step.docs.each do |style, value|
99
+ if style == :extra_args
100
+ output << step_extra_args(value)
103
101
  else
104
- step_multiline(arg)
102
+ # call StepException, StepSource, etc...
103
+ klass = ['step', style.to_s].map(&:capitalize).join
104
+ output << self.class.const_get(klass).build(value)
105
105
  end
106
- end.join("\n")
107
- end
108
-
109
- def step_outline(table)
110
- template_step_outline.result(binding)
111
- end
112
-
113
- def step_multiline(lines)
114
- '<pre class="multiline">' + h(lines) + '</pre>'
115
- end
106
+ end
116
107
 
117
- def step_source(location)
118
- @snippet_extractor ||= ::RSpec::Core::Formatters::SnippetExtractor.new
119
- '<pre class="source"><code class="ruby">' + @snippet_extractor.snippet([location]) + '</code></pre>'
108
+ output.join("\n")
120
109
  end
121
110
 
122
- def step_exception(exception)
123
- template_step_exception.result(binding)
111
+ def step_extra_args(extra_args)
112
+ extra_args.map do |arg|
113
+ klass = arg.instance_of?(Turnip::Table) ? StepOutline : StepMultiline
114
+ klass.build(arg)
115
+ end.join("\n")
124
116
  end
125
117
 
126
118
  def report_area
@@ -177,35 +169,6 @@ module TurnipFormatter
177
169
  EOS
178
170
  end
179
171
 
180
- def template_step_outline
181
- @template_step_outline ||= ERB.new(<<-EOS)
182
- <table class="step_outline">
183
- <% table.each do |tr| %>
184
- <tr>
185
- <% tr.each do |td| %>
186
- <td><%= h(td) %></td>
187
- <% end %>
188
- </tr>
189
- <% end %>
190
- </table>
191
- EOS
192
- end
193
-
194
- def template_step_exception
195
- @template_step_exception ||= ERB.new(<<-EOS)
196
- <div class="step_exception">
197
- <span>Failure:</span>
198
- <pre><%= h(exception.to_s) %></pre>
199
- <span>Backtrace:</span>
200
- <ol>
201
- <% exception.backtrace.each do |line| %>
202
- <li><%= h(line) %></li>
203
- <% end %>
204
- </ol>
205
- </div>
206
- EOS
207
- end
208
-
209
172
  def template_exception
210
173
  @template_exception ||= ERB.new(<<-EOS)
211
174
  <section class="exception">
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module TurnipFormatter
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
@@ -60,7 +60,9 @@ Scenario: strong monster
60
60
  And Fanfare
61
61
  ```
62
62
 
63
- ![Pending step](https://github.com/gongo/turnip_formatter/raw/master/spec/examples/images/pending_and_tagged_step.png)
63
+ ![Pending step](https://github.com/gongo/turnip_formatter/raw/master/spec/examples/images/pending_step.png)
64
+
65
+ ![Tag step](https://github.com/gongo/turnip_formatter/raw/master/spec/examples/images/tag_step.png)
64
66
 
65
67
  ### Background
66
68
 
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -3,16 +3,10 @@ require 'stringio'
3
3
 
4
4
  module RSpec::Core::Formatters
5
5
  describe TurnipFormatter do
6
+ include_context 'turnip_formatter passed scenario metadata'
7
+
6
8
  let(:feature) { RSpec::Core::ExampleGroup.describe('Feature') }
7
9
  let(:scenario) { feature.describe('Scenario') }
8
-
9
- let(:scenario_metadata) do
10
- {
11
- steps: { descriptions: [], docstrings: [[]], keywords: ['When'], tags: [] },
12
- file_path: '/path/to/hoge.feature'
13
- }
14
- end
15
-
16
10
  let(:output) { StringIO.new }
17
11
  let(:formatter) { TurnipFormatter.new(output) }
18
12
 
@@ -26,7 +20,7 @@ module RSpec::Core::Formatters
26
20
 
27
21
  describe '#example_passed' do
28
22
  it 'should be output passed scenario section' do
29
- scenario.example('passed', scenario_metadata) { expect(true).to be_true }
23
+ scenario.example('passed', metadata) { expect(true).to be_true }
30
24
  feature.run(formatter)
31
25
 
32
26
  string = output.string
@@ -36,11 +30,14 @@ module RSpec::Core::Formatters
36
30
 
37
31
  describe '#example_failed' do
38
32
  let(:failed_metadata) do
39
- scenario_metadata.dup.tap do |metadata|
40
- metadata[:steps][:descriptions] << 'this step is error'
41
- metadata[:steps][:docstrings] << []
42
- metadata[:steps][:keywords] << 'Given'
33
+ metadata[:turnip][:steps].tap do |steps|
34
+ steps << {
35
+ name: 'this step is error',
36
+ extra_args: [],
37
+ keyword: 'Given'
38
+ }
43
39
  end
40
+ metadata
44
41
  end
45
42
 
46
43
  it 'should be output failed scenario section' do
@@ -52,6 +49,7 @@ module RSpec::Core::Formatters
52
49
  raise e
53
50
  end
54
51
  end
52
+
55
53
  feature.run(formatter)
56
54
  expect(output.string).to match 'class="scenario failed"'
57
55
  end
@@ -59,11 +57,14 @@ module RSpec::Core::Formatters
59
57
 
60
58
  describe '#example_pending' do
61
59
  let(:pending_metadata) do
62
- scenario_metadata.dup.tap do |metadata|
63
- metadata[:steps][:descriptions] << 'this step is unimplement'
64
- metadata[:steps][:docstrings] << []
65
- metadata[:steps][:keywords] << 'Given'
60
+ metadata[:turnip][:steps].tap do |steps|
61
+ steps << {
62
+ name: 'this step is unimplement',
63
+ extra_args: [],
64
+ keyword: 'Given'
65
+ }
66
66
  end
67
+ metadata
67
68
  end
68
69
 
69
70
  it 'should be output pending scenario section' do
@@ -10,8 +10,17 @@ end
10
10
  shared_context 'turnip_formatter passed scenario metadata' do
11
11
  let(:metadata) do
12
12
  {
13
- steps: { descriptions: ['Step 1'], docstrings: [[]], keywords: ['When'], tags: [] },
13
+ turnip: {
14
+ steps: [ { name: 'Step 1', extra_args: [], keyword: 'When' } ],
15
+ tags: []
16
+ },
14
17
  file_path: '/path/to/hoge.feature'
15
18
  }
16
19
  end
17
20
  end
21
+
22
+ shared_context 'turnip_formatter standard step parameters' do
23
+ let(:description) do
24
+ { name: 'StepName', keyword: 'Keyword', extra_args: ['Docstring'] }
25
+ end
26
+ end
@@ -8,31 +8,18 @@ module TurnipFormatter::Scenario
8
8
  expect(true).to be_true
9
9
  }
10
10
 
11
- context 'Turnip example' do
12
- let(:metadata) do
13
- {
14
- steps: { descriptions: ['Step 1'], docstrings: [[]], keywords: ['When'], tags: [] },
15
- file_path: '/path/to/hoge.feature'
16
- }
17
- end
11
+ include_context 'turnip_formatter passed scenario metadata'
18
12
 
13
+ context 'Turnip example' do
19
14
  describe '#validation' do
20
15
  it 'should not raise exception' do
21
16
  expect { scenario.validation }.not_to raise_error
22
17
  end
23
18
  end
24
-
25
19
  end
26
20
 
27
21
  context 'Not Turnip example' do
28
22
  context 'Not passed example' do
29
- let(:metadata) do
30
- {
31
- steps: { descriptions: ['Step 1'], docstrings: [[]], keywords: ['When'], tags: [] },
32
- file_path: '/path/to/hoge.feature'
33
- }
34
- end
35
-
36
23
  include_context 'turnip_formatter scenario setup', proc {
37
24
  expect(true).to be_false
38
25
  }
@@ -46,10 +33,9 @@ module TurnipFormatter::Scenario
46
33
 
47
34
  context 'not exist feature file' do
48
35
  let(:metadata) do
49
- {
50
- steps: { descriptions: ['Step 1'], docstrings: [[]], keywords: ['When'], tags: [] },
51
- file_path: '/path/to/hoge.rb'
52
- }
36
+ metadata = super()
37
+ metadata[:file_path] = '/path/to/hoge.rb'
38
+ metadata
53
39
  end
54
40
 
55
41
  describe '#validation' do
@@ -3,38 +3,26 @@ require 'spec_helper'
3
3
  module TurnipFormatter
4
4
  class Step
5
5
  describe Failure do
6
- let(:description) { ['StepName', 'Keyword', ['Docstring']] }
7
- let(:step) { ::TurnipFormatter::Step.new(description) }
8
- let(:failure_step) { step.dup.extend TurnipFormatter::Step::Failure }
6
+ include_context 'turnip_formatter standard step parameters'
7
+ include_context 'turnip_formatter scenario setup', proc {
8
+ expect(true).to be_false
9
+ }
10
+ include_context 'turnip_formatter passed scenario metadata'
11
+
12
+ let(:step) do
13
+ step = ::TurnipFormatter::Step.new(example, description)
14
+ step.extend TurnipFormatter::Step::Failure
15
+ step
16
+ end
9
17
 
10
18
  describe '#attention?' do
11
- subject { failure_step.attention? }
19
+ subject { step.attention? }
12
20
  it { should be_true }
13
21
  end
14
22
 
15
23
  describe '#status' do
16
- subject { failure_step.status }
17
- it { should eq 'failure' }
18
- end
19
-
20
- describe '#attention' do
21
- it 'should have been implemented' do
22
- expect(step).not_to respond_to(:attention)
23
- expect(failure_step).to respond_to(:attention)
24
- end
25
-
26
- it 'should set exception informaton' do
27
- exception = StandardError.new
28
- expect(exception.backtrace).to be_nil
29
-
30
- failure_step.attention(exception, ['/path/to/error.rb: 10'])
31
-
32
- expect(failure_step.docs[:source]).to eq '/path/to/error.rb: 10'
33
- failure_step.docs[:exception].tap do |e|
34
- expect(e).to eql(exception)
35
- expect(e.backtrace.first).to eq '/path/to/error.rb: 10'
36
- end
37
- end
24
+ subject { step.status }
25
+ it { should eq :failure }
38
26
  end
39
27
  end
40
28
  end
@@ -3,25 +3,24 @@ require 'spec_helper'
3
3
  module TurnipFormatter
4
4
  class Step
5
5
  describe Failure do
6
- let(:description) { ['StepName', 'Keyword', ['Docstring']] }
7
- let(:step) { ::TurnipFormatter::Step.new(description) }
8
- let(:pending_step) { step.dup.extend TurnipFormatter::Step::Pending }
6
+ include_context 'turnip_formatter standard step parameters'
7
+ include_context 'turnip_formatter scenario setup'
8
+ include_context 'turnip_formatter passed scenario metadata'
9
+
10
+ let(:step) do
11
+ step = ::TurnipFormatter::Step.new(example, description)
12
+ step.extend TurnipFormatter::Step::Pending
13
+ step
14
+ end
9
15
 
10
16
  describe '#attention?' do
11
- subject { pending_step.attention? }
17
+ subject { step.attention? }
12
18
  it { should be_true }
13
19
  end
14
20
 
15
21
  describe '#status' do
16
- subject { pending_step.status }
17
- it { should eq 'pending' }
18
- end
19
-
20
- describe '#attention' do
21
- it 'should have been implemented' do
22
- expect(step).not_to respond_to(:attention)
23
- expect(pending_step).to respond_to(:attention)
24
- end
22
+ subject { step.status }
23
+ it { should eq :pending }
25
24
  end
26
25
  end
27
26
  end
@@ -2,8 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  module TurnipFormatter
4
4
  describe Step do
5
- let(:step) { ::TurnipFormatter::Step.new(description) }
6
- let(:description) { ['StepName', 'Keyword', ['Docstring']] }
5
+ include_context 'turnip_formatter standard step parameters'
6
+ include_context 'turnip_formatter scenario setup'
7
+ include_context 'turnip_formatter passed scenario metadata'
8
+ let(:step) { ::TurnipFormatter::Step.new(example, description) }
7
9
 
8
10
  describe '#attention?' do
9
11
  subject { step.attention? }
@@ -19,14 +21,5 @@ module TurnipFormatter
19
21
  subject { step.docs }
20
22
  it { should include :extra_args }
21
23
  end
22
-
23
- context 'No docstring' do
24
- let(:description) { ['StepName', 'Keyword', []] }
25
-
26
- describe '#docs' do
27
- subject { step.docs }
28
- it { should_not include :extra_args }
29
- end
30
- end
31
24
  end
32
25
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'turnip_formatter/template/step_exception'
3
+
4
+ module TurnipFormatter
5
+ class Template
6
+ describe StepException do
7
+ let(:template) { ::TurnipFormatter::Template::StepException }
8
+ let(:exception) do
9
+ StandardError.new('StepExceptionError').tap do |e|
10
+ e.set_backtrace('/path/to/error.rb: 10')
11
+ end
12
+ end
13
+
14
+ describe '.build' do
15
+ subject { template.build(exception) }
16
+ it do
17
+ should match %r{div class="step_exception"}
18
+ should match %r{<pre>.*#{exception.message}.*</pre>}
19
+ should match %r{<li>/path/to/error.rb: 10</li>}
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ require 'turnip_formatter/template/step_multiline'
3
+
4
+ module TurnipFormatter
5
+ class Template
6
+ describe StepMultiline do
7
+ let(:template) { ::TurnipFormatter::Template::StepMultiline }
8
+ let(:string) { 'a<a>a' }
9
+
10
+ describe '.build' do
11
+ subject { template.build(string) }
12
+ it { should eq '<pre class="multiline">a&lt;a&gt;a</pre>' }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'turnip/table'
3
+ require 'turnip_formatter/template/step_outline'
4
+
5
+ module TurnipFormatter
6
+ class Template
7
+ describe StepOutline do
8
+ let(:template) { ::TurnipFormatter::Template::StepOutline }
9
+
10
+ let(:string) do
11
+ ::Turnip::Table.new([
12
+ ["State", "Money"],
13
+ ["<Tokushima>", "555"],
14
+ ["<Okinawa>", "368"]
15
+ ])
16
+ end
17
+
18
+ describe '.build' do
19
+ subject { template.build(string) }
20
+
21
+ it do
22
+ should match %r{<td>State</td>[[:space:]]+<td>Money</td>}
23
+ should match %r{<td>&lt;Tokushima&gt;</td>[[:space:]]+<td>555</td>}
24
+ should match %r{<td>&lt;Okinawa&gt;</td>[[:space:]]+<td>368</td>}
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'turnip_formatter/template/step_source'
3
+
4
+ module TurnipFormatter
5
+ class Template
6
+ describe StepSource do
7
+ let(:template) { ::TurnipFormatter::Template::StepSource }
8
+ let(:source) { __FILE__ + ':1' }
9
+
10
+ describe '.build' do
11
+ subject { template.build(source) }
12
+ it do
13
+ should match '<pre class="source"><code class="ruby">'
14
+ should match "require 'turnip_formatter/template/step_source'"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -57,34 +57,29 @@ module TurnipFormatter
57
57
 
58
58
  context 'Step has arguments' do
59
59
  describe '#step_args' do
60
- let(:template_stub) do
61
- template.stub(:step_extra_args).and_return('extra_args')
62
- template.stub(:step_source).and_return('source')
63
- template.stub(:step_exception).and_return('exception')
64
- template
65
- end
60
+ let(:table) { Turnip::Table.new [] }
66
61
 
67
62
  let(:step) do
68
63
  step = double
69
- step.stub(:docs).and_return(extra_args: 'a', source: 'b', exception: 'c')
64
+ step.stub(:docs).and_return(
65
+ extra_args: ['a', table], source: 'b', exception: 'c'
66
+ )
70
67
  step
71
68
  end
72
69
 
73
70
  it 'should call corresponding method in step' do
74
- expect(template_stub.send(:step_args, step)).to eq("extra_args\nsource\nexception")
71
+ Template::StepMultiline.should_receive(:build).with('a').and_return('extra_args1')
72
+ Template::StepOutline.should_receive(:build).with(table).and_return('extra_args2')
73
+ Template::StepSource.should_receive(:build).with('b').and_return('source')
74
+ Template::StepException.should_receive(:build).with('c').and_return('exception')
75
+
76
+ expect(template.send(:step_args, step)).to eq("extra_args1\nextra_args2\nsource\nexception")
75
77
  end
76
78
  end
77
79
  end
78
80
 
79
81
  context 'Step has no argument' do
80
82
  describe '#step_args' do
81
- let(:template_stub) do
82
- template.should_not_receive(:step_extra_args)
83
- template.should_not_receive(:step_source)
84
- template.should_not_receive(:step_exception)
85
- template
86
- end
87
-
88
83
  let(:step) do
89
84
  step = double
90
85
  step.stub(:docs).and_return({})
@@ -92,7 +87,12 @@ module TurnipFormatter
92
87
  end
93
88
 
94
89
  it 'should get null string' do
95
- expect(template_stub.send(:step_args, step)).to be_empty
90
+ Template::StepOutline.should_not_receive(:build)
91
+ Template::StepMultiline.should_not_receive(:build)
92
+ Template::StepSource.should_not_receive(:build)
93
+ Template::StepException.should_not_receive(:build)
94
+
95
+ expect(template.send(:step_args, step)).to be_empty
96
96
  end
97
97
  end
98
98
  end
@@ -105,56 +105,17 @@ module TurnipFormatter
105
105
  end
106
106
  end
107
107
 
108
- let(:extra_args_1) do
108
+ let(:extra_args) do
109
109
  [::Turnip::Table.new([['a']]), 'b']
110
110
  end
111
111
 
112
- let(:extra_args_2) do
113
- []
112
+ before do
113
+ Template::StepOutline.should_receive(:build).and_return('outline')
114
+ Template::StepMultiline.should_receive(:build).and_return('multiline')
114
115
  end
115
116
 
116
117
  it 'should get string converted from extra_args' do
117
- expect(template_stub.send(:step_extra_args, extra_args_1)).to eq("outline\nmultiline")
118
- expect(template_stub.send(:step_extra_args, extra_args_2)).to be_empty
119
- end
120
- end
121
-
122
- describe '#step_outline' do
123
- let(:outline) {
124
- ::Turnip::Table.new([
125
- ["State", "Money"],
126
- ["<Tokushima>", "555"],
127
- ["<Okinawa>", "368"]
128
- ])
129
- }
130
-
131
- it 'should get string converted to <table>' do
132
- html = template.send(:step_outline, outline)
133
- expect(html).to match %r{<td>State</td>[[:space:]]+<td>Money</td>}
134
- expect(html).to match %r{<td>&lt;Tokushima&gt;</td>[[:space:]]+<td>555</td>}
135
- expect(html).to match %r{<td>&lt;Okinawa&gt;</td>[[:space:]]+<td>368</td>}
136
- end
137
- end
138
-
139
- describe '#step_multiline' do
140
- it 'should get escaped string enclosed in <pre>' do
141
- html = template.send(:step_multiline, 'a<a>a')
142
- expect(html).to eq('<pre class="multiline">a&lt;a&gt;a</pre>')
143
- end
144
- end
145
-
146
- describe '#step_exception' do
147
- let(:exception) do
148
- StandardError.new('StepExceptionError').tap do |e|
149
- e.set_backtrace('/path/to/error.rb: 10')
150
- end
151
- end
152
-
153
- it 'should get string Exception class name and backtrace' do
154
- html = template.send(:step_exception, exception)
155
- expect(html).to match %r{div class="step_exception"}
156
- expect(html).to match %r{<pre>.*#{exception.message}.*</pre>}
157
- expect(html).to match %r{<li>/path/to/error.rb: 10</li>}
118
+ expect(template_stub.send(:step_extra_args, extra_args)).to eq("outline\nmultiline")
158
119
  end
159
120
  end
160
121
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turnip_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-18 00:00:00.000000000 Z
12
+ date: 2013-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: turnip
@@ -117,9 +117,14 @@ files:
117
117
  - lib/turnip_formatter/scenario/pass.rb
118
118
  - lib/turnip_formatter/scenario/pending.rb
119
119
  - lib/turnip_formatter/step.rb
120
+ - lib/turnip_formatter/step/dsl.rb
120
121
  - lib/turnip_formatter/step/failure.rb
121
122
  - lib/turnip_formatter/step/pending.rb
122
123
  - lib/turnip_formatter/template.rb
124
+ - lib/turnip_formatter/template/step_exception.rb
125
+ - lib/turnip_formatter/template/step_multiline.rb
126
+ - lib/turnip_formatter/template/step_outline.rb
127
+ - lib/turnip_formatter/template/step_source.rb
123
128
  - lib/turnip_formatter/version.rb
124
129
  - spec/examples/README.md
125
130
  - spec/examples/features/battle.feature
@@ -131,7 +136,8 @@ files:
131
136
  - spec/examples/images/failed_step.png
132
137
  - spec/examples/images/multiline.png
133
138
  - spec/examples/images/outline.png
134
- - spec/examples/images/pending_and_tagged_step.png
139
+ - spec/examples/images/pending_step.png
140
+ - spec/examples/images/tag_step.png
135
141
  - spec/examples/spec_helper.rb
136
142
  - spec/examples/steps/spell_steps.rb
137
143
  - spec/examples/steps/steps.rb
@@ -145,6 +151,10 @@ files:
145
151
  - spec/turnip_formatter/step/failure_spec.rb
146
152
  - spec/turnip_formatter/step/pending_spec.rb
147
153
  - spec/turnip_formatter/step_spec.rb
154
+ - spec/turnip_formatter/template/step_exception_spec.rb
155
+ - spec/turnip_formatter/template/step_multiline_spec.rb
156
+ - spec/turnip_formatter/template/step_outline_spec.rb
157
+ - spec/turnip_formatter/template/step_source_spec.rb
148
158
  - spec/turnip_formatter/template_spec.rb
149
159
  - turnip_formatter.gemspec
150
160
  homepage: https://github.com/gongo/turnip_formatter
@@ -162,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
172
  version: '0'
163
173
  segments:
164
174
  - 0
165
- hash: 420008365
175
+ hash: -3424310081992899473
166
176
  required_rubygems_version: !ruby/object:Gem::Requirement
167
177
  none: false
168
178
  requirements:
@@ -171,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
181
  version: '0'
172
182
  segments:
173
183
  - 0
174
- hash: 420008365
184
+ hash: -3424310081992899473
175
185
  requirements: []
176
186
  rubyforge_project:
177
187
  rubygems_version: 1.8.23
@@ -189,7 +199,8 @@ test_files:
189
199
  - spec/examples/images/failed_step.png
190
200
  - spec/examples/images/multiline.png
191
201
  - spec/examples/images/outline.png
192
- - spec/examples/images/pending_and_tagged_step.png
202
+ - spec/examples/images/pending_step.png
203
+ - spec/examples/images/tag_step.png
193
204
  - spec/examples/spec_helper.rb
194
205
  - spec/examples/steps/spell_steps.rb
195
206
  - spec/examples/steps/steps.rb
@@ -203,4 +214,8 @@ test_files:
203
214
  - spec/turnip_formatter/step/failure_spec.rb
204
215
  - spec/turnip_formatter/step/pending_spec.rb
205
216
  - spec/turnip_formatter/step_spec.rb
217
+ - spec/turnip_formatter/template/step_exception_spec.rb
218
+ - spec/turnip_formatter/template/step_multiline_spec.rb
219
+ - spec/turnip_formatter/template/step_outline_spec.rb
220
+ - spec/turnip_formatter/template/step_source_spec.rb
206
221
  - spec/turnip_formatter/template_spec.rb