turnip_formatter 0.2.11 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f797fdd3e324fcc850739157c99e215f89d78768
4
- data.tar.gz: b94ada02b2acbfad137e314c1986adaa075caaab
3
+ metadata.gz: 29acbac39ffbed20aa935ee2325695f68b9348b7
4
+ data.tar.gz: 71a9a4eda76d0420a31bd6dab1dbd142b6a3b039
5
5
  SHA512:
6
- metadata.gz: e6ee2cd266e8d3dd14180b3d11cd4fd0631733236cd92f3833dd43d186ec216d292a16cfce55e281df95a5b95b4526feae511518e57dfc3ab2c209f242cc9166
7
- data.tar.gz: f32b416e146f53f70f5c993a9959ad0a72495845b1b6b68b03710333336856c3bf155c9e9ef4814dd74fd5c2249d9c36835e9b70664df0e5d74702e8933cb74d
6
+ metadata.gz: 561db6c050c5ad0432f528bdaefe8a46af59e5f1e382b7816a81bd0bc10f688eba031072b4799434c1c3ac36e1c02f7a795cfd7bd40f1e8e6335fa4e33c4bfa7
7
+ data.tar.gz: 98b1d901dcb4d3a3f42654d505f50962b7f88d96d4cbe65ae006e4ea7bdeb739b2fce7a3750d4f00d7858c3f024589de3bb9394c0abd2fe2a6205b11d05434fd
data/.travis.yml CHANGED
@@ -3,4 +3,6 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - 2.1.0
6
+ - 2.1.2
7
+ - jruby-1.7.10
6
8
  script: bundle exec rspec
data/README.md CHANGED
@@ -14,6 +14,7 @@ Requirements
14
14
  * Ruby
15
15
  * `~> 1.9.3`
16
16
  * `~> 2.0.0`
17
+ * `~> 2.1.0`
17
18
 
18
19
  Installation
19
20
  --------------------
@@ -44,34 +45,29 @@ Run this command.
44
45
  $ rspec -r turnip_formatter --format RSpecTurnipFormatter --out report.html
45
46
 
46
47
 
47
- Screenshot
48
+ Example
48
49
  --------------------
49
50
 
50
- ### Step overview
51
-
52
- ![Tab steps](https://github.com/gongo/turnip_formatter/raw/master/images/tab_steps.png)
53
-
54
- expand:
55
-
56
- ![Expand tab steps](https://github.com/gongo/turnip_formatter/raw/master/images/tab_steps_expanding.png)
57
-
58
- ### Speed Statistics
59
-
60
- ![Expand tab steps](https://github.com/gongo/turnip_formatter/raw/master/images/tab_speed_statistics.png)
61
-
62
- ### Feature Statistics
63
-
64
- ![Expand tab steps](https://github.com/gongo/turnip_formatter/raw/master/images/tab_feature_statistics.png)
51
+ See:
65
52
 
66
- ### Tag Statistics
53
+ - Feature and Steps
54
+ - https://github.com/gongo/turnip_formatter/tree/master/example
55
+ - Report
56
+ - http://gongo.github.io/turnip_formatter/examples/report.html
67
57
 
68
- ![Expand tab steps](https://github.com/gongo/turnip_formatter/raw/master/images/tab_tag_statistics.png)
69
-
70
-
71
- Example
58
+ Configuration
72
59
  --------------------
73
60
 
74
- see https://github.com/gongo/turnip_formatter/tree/master/example
61
+ ```ruby
62
+ TurnipFormatter.configure do |config|
63
+ config.title = 'My Report' # <h1>My Report</h1>
64
+ config.add_stylesheet File.dirname(__FILE__) + '/foo.css' # <style>..</style>
65
+ config.add_javascript File.dirname(__FILE__) + '/bar.js' # <script>..</script>
66
+
67
+ config.add_stylesheet 'http://cdn.example.com/hoge.css' # <link rel="..">
68
+ config.add_javascript '//cdn.example.com/fuga.js' # <script src="..">
69
+ end
70
+ ```
75
71
 
76
72
  Add-on
77
73
  --------------------
data/example/README.md CHANGED
@@ -20,7 +20,7 @@ Scenario: normal monster
20
20
  And Fanfare
21
21
  ```
22
22
 
23
- ![Basic step](https://github.com/gongo/turnip_formatter/raw/master/example/images/basic_step.png)
23
+ ![Basic step](./images/basic_step.png)
24
24
 
25
25
  ### Failed step
26
26
 
@@ -36,7 +36,7 @@ Scenario: strong monster
36
36
  And Fanfare
37
37
  ```
38
38
 
39
- ![Failed step](https://github.com/gongo/turnip_formatter/raw/master/example/images/failed_step.png)
39
+ ![Failed step](./images/failed_step.png)
40
40
 
41
41
  ### Pending step and specify tag
42
42
 
@@ -61,9 +61,7 @@ Scenario: strong monster
61
61
  And Fanfare
62
62
  ```
63
63
 
64
- ![Pending step](https://github.com/gongo/turnip_formatter/raw/master/example/images/pending_step.png)
65
-
66
- ![Tag step](https://github.com/gongo/turnip_formatter/raw/master/example/images/tag_step.png)
64
+ ![Pending step](./images/pending_step.png)
67
65
 
68
66
  ### Background
69
67
 
@@ -86,7 +84,7 @@ Feature: Battle a monster with weapon
86
84
  And Fanfare
87
85
  ```
88
86
 
89
- ![Background step](https://github.com/gongo/turnip_formatter/raw/master/example/images/background.png)
87
+ ![Background step](./images/background.png)
90
88
 
91
89
  ### Outline
92
90
 
@@ -109,7 +107,7 @@ Feature: Battle monsters
109
107
  Then I could not escape
110
108
  ```
111
109
 
112
- ![outline](https://github.com/gongo/turnip_formatter/raw/master/example/images/outline.png)
110
+ ![outline](./images/outline.png)
113
111
 
114
112
  ### Multiline
115
113
 
@@ -124,4 +122,4 @@ Feature: A feature with multiline strings
124
122
  Then the song should have 2 lines
125
123
  ```
126
124
 
127
- ![Multiline](https://github.com/gongo/turnip_formatter/raw/master/example/images/multiline.png)
125
+ ![Multiline](./images/multiline.png)
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1 @@
1
+ alert('a');
@@ -0,0 +1,3 @@
1
+ h1 {
2
+ color: red;
3
+ }
@@ -1,8 +1,13 @@
1
1
  require 'turnip_formatter'
2
2
 
3
3
  RSpec.configure do |config|
4
- config.project_name = "My project"
5
4
  config.add_formatter RSpecTurnipFormatter, 'report.html'
6
5
  end
7
6
 
8
- Dir.glob(File.dirname(__FILE__) + "/steps/**/*steps.rb") { |f| load f, true }
7
+ Dir.glob(File.dirname(__FILE__) + '/steps/**/*steps.rb') { |f| load f, true }
8
+
9
+ # TurnipFormatter.configure do |config|
10
+ # config.title = 'My Report'
11
+ # config.add_stylesheet File.dirname(__FILE__) + '/foo.css'
12
+ # config.add_javascript File.dirname(__FILE__) + '/bar.js'
13
+ # end
@@ -5,50 +5,63 @@ require 'turnip_formatter/scenario/pass'
5
5
  require 'turnip_formatter/scenario/failure'
6
6
  require 'turnip_formatter/scenario/pending'
7
7
  require 'turnip_formatter/printer/index'
8
+ require 'turnip_formatter/printer/scenario'
8
9
 
9
10
  module RSpec
10
11
  module Core
11
12
  module Formatters
12
13
  class TurnipFormatter < BaseFormatter
13
- attr_reader :passed_scenarios, :failed_scenarios, :pending_scenarios
14
- attr_reader :scenarios
14
+ attr_reader :scenarios, :scenario_output_files
15
+
16
+ SCENARIO_TEMPORARY_OUTPUT_DIR = File.expand_path('./turnip_tmp')
15
17
 
16
18
  def initialize(output)
17
19
  super(output)
18
- @passed_scenarios = []
19
- @failed_scenarios = []
20
- @pending_scenarios = []
21
20
  @scenarios = []
21
+ @scenario_output_files = []
22
+
23
+ FileUtils.mkdir_p(SCENARIO_TEMPORARY_OUTPUT_DIR)
22
24
  end
23
25
 
24
26
  def dump_summary(duration, example_count, failure_count, pending_count)
25
- super(duration, example_count, failure_count, pending_count)
26
- output.puts ::TurnipFormatter::Printer::Index.print_out(self)
27
+ print_params = {
28
+ scenarios: scenarios,
29
+ failed_count: failure_count,
30
+ pending_count: pending_count,
31
+ total_time: duration,
32
+ scenario_files: scenario_output_files
33
+ }
34
+ output.puts ::TurnipFormatter::Printer::Index.print_out(print_params)
35
+ FileUtils.rm_rf(SCENARIO_TEMPORARY_OUTPUT_DIR)
27
36
  end
28
37
 
29
38
  def example_passed(example)
30
- super(example)
31
-
32
39
  scenario = ::TurnipFormatter::Scenario::Pass.new(example)
33
- @passed_scenarios << scenario
34
- @scenarios << scenario
40
+ output_scenario(scenario)
35
41
  end
36
42
 
37
43
  def example_pending(example)
38
- super(example)
39
-
40
44
  scenario = ::TurnipFormatter::Scenario::Pending.new(example)
41
- @pending_scenarios << scenario
42
- @scenarios << scenario
45
+ output_scenario(scenario)
43
46
  end
44
47
 
45
48
  def example_failed(example)
46
- super(example)
47
-
48
49
  scenario = ::TurnipFormatter::Scenario::Failure.new(example)
49
- @failed_scenarios << scenario
50
- @scenarios << scenario
50
+ output_scenario(scenario)
51
51
  end
52
+
53
+ private
54
+
55
+ def output_scenario(scenario)
56
+ filepath = SCENARIO_TEMPORARY_OUTPUT_DIR + "/#{scenario.id}.html"
57
+
58
+ File.open(filepath, 'w') do |io|
59
+ io.puts ::TurnipFormatter::Printer::Scenario.print_out(scenario)
60
+ end
61
+
62
+ @scenario_output_files << filepath
63
+ @scenarios << scenario
64
+ end
52
65
  end
53
66
  end
54
67
  end
@@ -10,16 +10,13 @@ module TurnipFormatter
10
10
  class << self
11
11
  include TurnipFormatter::Printer
12
12
 
13
- #
14
- # @param RSpec::Core::Formatters::TurnipFormatter formatter
15
- #
16
- def print_out(formatter)
13
+ def print_out(params)
17
14
  render_template(:index, {
18
- scenarios: formatter.scenarios,
19
- passed_scenarios: formatter.passed_scenarios,
20
- failed_count: formatter.failure_count,
21
- pending_count: formatter.pending_count,
22
- total_time: formatter.duration,
15
+ scenarios: params[:scenarios],
16
+ failed_count: params[:failed_count],
17
+ pending_count: params[:pending_count],
18
+ total_time: params[:total_time],
19
+ scenario_files: params[:scenario_files]
23
20
  }
24
21
  )
25
22
  end
@@ -9,8 +9,10 @@ module TurnipFormatter
9
9
  include TurnipFormatter::Printer
10
10
 
11
11
  def print_out(scenario)
12
- scenario.validation
13
- render_template(:scenario, scenario: scenario)
12
+ #
13
+ # TODO output for scenario.valid? == false
14
+ #
15
+ render_template(:scenario, scenario: scenario) if scenario.valid?
14
16
  rescue => e
15
17
  TurnipFormatter::Printer::RuntimeError.print_out(scenario.example, e)
16
18
  end
@@ -8,24 +8,26 @@ module TurnipFormatter
8
8
  include TurnipFormatter::Printer
9
9
 
10
10
  def print_out(step)
11
- render_template(:step, { step: step, step_docs: documents(step.docs) })
11
+ step_templates = TurnipFormatter.step_templates_for(step.status)
12
+
13
+ render_template(:step,
14
+ {
15
+ step: step,
16
+ has_args_or_documents: has_args_or_documents?(step, step_templates),
17
+ step_docs: documents(step, step_templates)
18
+ }
19
+ )
12
20
  end
13
21
 
14
22
  private
15
23
 
16
- def documents(docs)
17
- docs.map do |style, template|
18
- if style == :extra_args
19
- TurnipFormatter::Printer::StepExtraArgs.print_out(template[:value])
20
- else
21
- #
22
- # Template class which is registered in
23
- # +Step::Failure.add_template+
24
- # +Step::Pending.add_template+
25
- # be called.
26
- #
27
- template[:klass].build(template[:value])
28
- end
24
+ def has_args_or_documents?(step, templates)
25
+ (step.extra_args.length + templates.length) > 0
26
+ end
27
+
28
+ def documents(step, templates)
29
+ templates.map do |template, method|
30
+ template.send(method, step.example)
29
31
  end.join("\n")
30
32
  end
31
33
  end
@@ -7,6 +7,8 @@ module TurnipFormatter
7
7
  include TurnipFormatter::Printer
8
8
 
9
9
  def print_out(args)
10
+ return '' if args.nil?
11
+
10
12
  args.map do |arg|
11
13
  if arg.instance_of?(Turnip::Table)
12
14
  render_template(:step_outline, { table: arg.to_a })
@@ -9,7 +9,8 @@ module TurnipFormatter
9
9
  class << self
10
10
  include TurnipFormatter::Printer
11
11
 
12
- def print_out(passed_scenarios)
12
+ def print_out(scenarios)
13
+ passed_scenarios = scenarios.select { |s| s.status == 'passed' }
13
14
  results = speed_analysis(passed_scenarios)
14
15
  render_template(:tab_speed_statistics, { analysis_results: results })
15
16
  end
@@ -28,9 +28,9 @@ module TurnipFormatter
28
28
  info = OpenStruct.new(
29
29
  name: name,
30
30
  scenario_count: scenarios.size,
31
- passed_count: status_group["passed"].size,
32
- failed_count: status_group["failed"].size,
33
- pending_count: status_group["pending"].size,
31
+ passed_count: status_group['passed'].size,
32
+ failed_count: status_group['failed'].size,
33
+ pending_count: status_group['pending'].size,
34
34
  status: 'failed'
35
35
  )
36
36
 
@@ -57,8 +57,7 @@ module TurnipFormatter
57
57
  #
58
58
  def group_by_tag(scenarios)
59
59
  scenarios.map do |scenario|
60
- begin
61
- scenario.validation
60
+ if scenario.valid?
62
61
  if scenario.tags.empty?
63
62
  { name: 'turnip', scenario: scenario }
64
63
  else
@@ -66,7 +65,7 @@ module TurnipFormatter
66
65
  { name: '@' + tag, scenario: scenario }
67
66
  end
68
67
  end
69
- rescue
68
+ else
70
69
  { name: 'runtime error', scenario: scenario }
71
70
  end
72
71
  end.flatten.group_by { |s| s[:name] }.sort
@@ -1,32 +1,27 @@
1
+ require 'tilt'
2
+
1
3
  module TurnipFormatter
2
4
  module Printer
3
- include ERB::Util
4
-
5
5
  #
6
6
  # @example
7
7
  # render_template(:main, { name: 'user' })
8
- # # => ERB.new('/path/to/main.erb') render { name: 'user' }
8
+ # # => Tilt.new('/path/to/main.erb') render { name: 'user' }
9
9
  #
10
10
  def render_template(name, params = {})
11
- render_template_list(name).result(template_params_binding(params))
11
+ render_template_list(name).render(self, params)
12
12
  end
13
13
 
14
14
  private
15
15
 
16
16
  def render_template_list(name)
17
17
  if templates[name].nil?
18
- path = File.dirname(__FILE__) + "/template/#{name.to_s}.erb"
19
- templates[name] = ERB.new(File.read(path))
18
+ path = File.dirname(__FILE__) + "/template/#{name}.haml"
19
+ templates[name] = Tilt.new(path)
20
20
  end
21
21
 
22
22
  templates[name]
23
23
  end
24
24
 
25
- def template_params_binding(params)
26
- code = params.keys.map { |k| "#{k} = params[#{k.inspect}];" }.join
27
- eval(code + ";binding")
28
- end
29
-
30
25
  def templates
31
26
  @templates ||= {}
32
27
  end
@@ -0,0 +1,98 @@
1
+ require 'turnip_formatter/step'
2
+
3
+ module TurnipFormatter
4
+ module Scenario
5
+ class Base
6
+ include RSpec::Core::BacktraceFormatter
7
+
8
+ attr_reader :errors
9
+
10
+ #
11
+ # @param [RSpec::Core::Example] example
12
+ #
13
+ def initialize(example)
14
+ @example = example
15
+ @errors = []
16
+
17
+ validation
18
+ clean_backtrace
19
+ end
20
+
21
+ def valid?
22
+ errors.empty?
23
+ end
24
+
25
+ def steps
26
+ @steps ||= raw_steps.map do |step|
27
+ TurnipFormatter::Step.new(example, step)
28
+ end
29
+ end
30
+
31
+ def id
32
+ 'scenario_' + object_id.to_s
33
+ end
34
+
35
+ #
36
+ # @return [String] scenario name
37
+ #
38
+ def name
39
+ example.example_group.description
40
+ end
41
+
42
+ #
43
+ # @return [String] scenario status ('passed', 'failed' or 'pending')
44
+ #
45
+ def status
46
+ example.execution_result[:status]
47
+ end
48
+
49
+ #
50
+ # @return [String] scenario run time
51
+ #
52
+ def run_time
53
+ example.execution_result[:run_time]
54
+ end
55
+
56
+ def feature_info
57
+ path = RSpec::Core::Metadata.relative_path(feature_file_path)
58
+ "\"#{feature_name}\" in #{path}"
59
+ end
60
+
61
+ def feature_name
62
+ example.example_group.metadata[:example_group][:example_group][:description]
63
+ end
64
+
65
+ def tags
66
+ example.metadata[:turnip_formatter][:tags]
67
+ end
68
+
69
+ def example
70
+ @example
71
+ end
72
+
73
+ protected
74
+
75
+ def validation
76
+ unless example.metadata.key?(:turnip_formatter)
77
+ @errors << 'has no steps information'
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def feature_file_path
84
+ example.metadata[:file_path]
85
+ end
86
+
87
+ def raw_steps
88
+ example.metadata[:turnip_formatter][:steps]
89
+ end
90
+
91
+ def clean_backtrace
92
+ return if example.exception.nil?
93
+ formatted = format_backtrace(example.exception.backtrace, example.metadata)
94
+ example.exception.set_backtrace(formatted)
95
+ end
96
+ end
97
+ end
98
+ end
@@ -1,36 +1,34 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'turnip_formatter/scenario'
4
- require 'turnip_formatter/step/failure'
1
+ require 'turnip_formatter/scenario/base'
5
2
 
6
3
  module TurnipFormatter
7
4
  module Scenario
8
- class NotFailedScenarioError < ::StandardError; end
9
- class NoExistFailedStepInformationError < ::StandardError; end
10
-
11
- class Failure
12
- include TurnipFormatter::Scenario
13
-
5
+ class Failure < Base
14
6
  def steps
15
7
  steps = super
16
- steps[offending_line].extend TurnipFormatter::Step::Failure
8
+ steps[@offending_line].status = :failed
9
+ steps[(@offending_line + 1)..-1].each do |step|
10
+ step.status = :unexecuted
11
+ end
17
12
  steps
18
13
  end
19
14
 
20
- def validation
21
- raise NotFailedScenarioError if status != 'failed'
22
- offending_line
23
- super
24
- end
15
+ protected
16
+
17
+ def validation
18
+ if failed_message =~ /:in step:(?<stepno>\d+) `/
19
+ @offending_line = $~[:stepno].to_i
20
+ else
21
+ @errors << 'has no failed step information'
22
+ end
23
+
24
+ super
25
+ end
25
26
 
26
27
  private
27
28
 
28
- def offending_line
29
- unless example.exception.backtrace.last =~ /:in step:(?<stepno>\d+) `/
30
- raise NoExistFailedStepInformationError
29
+ def failed_message
30
+ example.exception.backtrace.last
31
31
  end
32
- $~[:stepno].to_i
33
- end
34
32
  end
35
33
  end
36
34
  end
@@ -1,19 +1,8 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'turnip_formatter/scenario'
4
- require 'turnip_formatter/step/pending'
1
+ require 'turnip_formatter/scenario/base'
5
2
 
6
3
  module TurnipFormatter
7
4
  module Scenario
8
- class NotPassedScenarioError < ::StandardError; end
9
-
10
- class Pass
11
- include TurnipFormatter::Scenario
12
-
13
- def validation
14
- raise NotPassedScenarioError if status != 'passed'
15
- super
16
- end
5
+ class Pass < Base
17
6
  end
18
7
  end
19
8
  end
@@ -1,40 +1,34 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'turnip_formatter/scenario'
4
- require 'turnip_formatter/step/pending'
1
+ require 'turnip_formatter/scenario/base'
5
2
 
6
3
  module TurnipFormatter
7
4
  module Scenario
8
- class NotPendingScenarioError < ::StandardError; end
9
- class NoExistPendingStepInformationError < ::StandardError; end
10
-
11
- class Pending
12
- include TurnipFormatter::Scenario
13
-
5
+ class Pending < Base
14
6
  def steps
15
7
  steps = super
16
- steps[offending_line].extend TurnipFormatter::Step::Pending
8
+ steps[@offending_line].status = :pending
9
+ steps[(@offending_line + 1)..-1].each do |step|
10
+ step.status = :unexecuted
11
+ end
17
12
  steps
18
13
  end
19
14
 
20
- def validation
21
- raise NotPendingScenarioError if status != 'pending'
22
- offending_line
23
- super
24
- end
15
+ protected
25
16
 
26
- private
17
+ def validation
18
+ if pending_message =~ /^No such step\((?<stepno>\d+)\): /
19
+ @offending_line = $~[:stepno].to_i
20
+ else
21
+ @errors << 'has no pending step information'
22
+ end
27
23
 
28
- def offending_line
29
- unless pending_message =~ /^No such step\((?<stepno>\d+)\): /
30
- raise NoExistPendingStepInformationError
24
+ super
31
25
  end
32
- $~[:stepno].to_i
33
- end
34
26
 
35
- def pending_message
36
- example.execution_result[:pending_message]
37
- end
27
+ private
28
+
29
+ def pending_message
30
+ example.execution_result[:pending_message]
31
+ end
38
32
  end
39
33
  end
40
34
  end