turnip_formatter 0.3.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29acbac39ffbed20aa935ee2325695f68b9348b7
4
- data.tar.gz: 71a9a4eda76d0420a31bd6dab1dbd142b6a3b039
3
+ metadata.gz: ea1f372fc6ecf5a43d8f00841896ca2d51c04f50
4
+ data.tar.gz: 78bdffd1e4b1326bd44ff556fb4697d269776855
5
5
  SHA512:
6
- metadata.gz: 561db6c050c5ad0432f528bdaefe8a46af59e5f1e382b7816a81bd0bc10f688eba031072b4799434c1c3ac36e1c02f7a795cfd7bd40f1e8e6335fa4e33c4bfa7
7
- data.tar.gz: 98b1d901dcb4d3a3f42654d505f50962b7f88d96d4cbe65ae006e4ea7bdeb739b2fce7a3750d4f00d7858c3f024589de3bb9394c0abd2fe2a6205b11d05434fd
6
+ metadata.gz: 8f54ee9957426623ccafed4561f8d3d219eaaa6bf74e5a73e891a878f6442aae0424ecf0e2009d3c5ea3e823345b98da386cf50c89632c8bcecaa3103ec08cfa
7
+ data.tar.gz: 78bbdd9833dea112843c297303e12c60df6ddfead24a9a3b87b27473a4e01c55e41d4ece88b042b9b1b79ff763dcb565b26d0a3c8ce9fc34b54f30c9fac06fc4
data/.travis.yml CHANGED
@@ -6,3 +6,7 @@ rvm:
6
6
  - 2.1.2
7
7
  - jruby-1.7.10
8
8
  script: bundle exec rspec
9
+ gemfile:
10
+ - spec/gemfiles/Gemfile-rspec-2.14.x
11
+ - spec/gemfiles/Gemfile-rspec-2.99.x
12
+ - spec/gemfiles/Gemfile-rspec-3.0.x
@@ -0,0 +1,47 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module RSpec
4
+ module Core
5
+ module Formatters
6
+ class TurnipFormatter < BaseFormatter
7
+ module ForRSpec2
8
+ def dump_summary(duration, _, failure_count, pending_count)
9
+ print_params = {
10
+ scenarios: scenarios,
11
+ failed_count: failure_count,
12
+ pending_count: pending_count,
13
+ total_time: duration,
14
+ scenario_files: scenario_output_files
15
+ }
16
+ output_html(print_params)
17
+ end
18
+
19
+ def example_passed(example)
20
+ scenario = ::TurnipFormatter::Scenario::Pass.new(example)
21
+ output_scenario(scenario)
22
+ end
23
+
24
+ def example_pending(example)
25
+ clean_backtrace(example)
26
+ scenario = ::TurnipFormatter::Scenario::Pending.new(example)
27
+ output_scenario(scenario)
28
+ end
29
+
30
+ def example_failed(example)
31
+ clean_backtrace(example)
32
+ scenario = ::TurnipFormatter::Scenario::Failure.new(example)
33
+ output_scenario(scenario)
34
+ end
35
+
36
+ private
37
+
38
+ def clean_backtrace(example)
39
+ return if example.exception.nil?
40
+ formatted = format_backtrace(example.exception.backtrace, example)
41
+ example.exception.set_backtrace(formatted)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module RSpec
4
+ module Core
5
+ module Formatters
6
+ class TurnipFormatter < BaseFormatter
7
+ module ForRSpec3
8
+ def self.included(klass)
9
+ RSpec::Core::Formatters.register klass, :example_passed, :example_pending, :example_failed, :dump_summary
10
+ end
11
+
12
+ def dump_summary(summary)
13
+ print_params = {
14
+ scenarios: scenarios,
15
+ failed_count: summary.failure_count,
16
+ pending_count: summary.pending_count,
17
+ total_time: summary.duration,
18
+ scenario_files: scenario_output_files
19
+ }
20
+ output_html(print_params)
21
+ end
22
+
23
+ def example_passed(notification)
24
+ scenario = ::TurnipFormatter::Scenario::Pass.new(notification.example)
25
+ output_scenario(scenario)
26
+ end
27
+
28
+ def example_pending(notification)
29
+ clean_backtrace(notification)
30
+ scenario = ::TurnipFormatter::Scenario::Pending.new(notification.example)
31
+ output_scenario(scenario)
32
+ end
33
+
34
+ def example_failed(notification)
35
+ clean_backtrace(notification)
36
+ scenario = ::TurnipFormatter::Scenario::Failure.new(notification.example)
37
+ output_scenario(scenario)
38
+ end
39
+
40
+ private
41
+
42
+ def clean_backtrace(notification)
43
+ if notification.respond_to?(:formatted_backtrace)
44
+ formatted = notification.formatted_backtrace
45
+ notification.example.exception.set_backtrace(formatted)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -6,6 +6,8 @@ require 'turnip_formatter/scenario/failure'
6
6
  require 'turnip_formatter/scenario/pending'
7
7
  require 'turnip_formatter/printer/index'
8
8
  require 'turnip_formatter/printer/scenario'
9
+ require_relative './turnip_formatter/for_rspec2'
10
+ require_relative './turnip_formatter/for_rspec3'
9
11
 
10
12
  module RSpec
11
13
  module Core
@@ -15,6 +17,12 @@ module RSpec
15
17
 
16
18
  SCENARIO_TEMPORARY_OUTPUT_DIR = File.expand_path('./turnip_tmp')
17
19
 
20
+ if Formatters.respond_to?(:register)
21
+ include TurnipFormatter::ForRSpec3
22
+ else
23
+ include TurnipFormatter::ForRSpec2
24
+ end
25
+
18
26
  def initialize(output)
19
27
  super(output)
20
28
  @scenarios = []
@@ -23,35 +31,13 @@ module RSpec
23
31
  FileUtils.mkdir_p(SCENARIO_TEMPORARY_OUTPUT_DIR)
24
32
  end
25
33
 
26
- def dump_summary(duration, example_count, failure_count, pending_count)
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)
36
- end
37
-
38
- def example_passed(example)
39
- scenario = ::TurnipFormatter::Scenario::Pass.new(example)
40
- output_scenario(scenario)
41
- end
42
-
43
- def example_pending(example)
44
- scenario = ::TurnipFormatter::Scenario::Pending.new(example)
45
- output_scenario(scenario)
46
- end
47
-
48
- def example_failed(example)
49
- scenario = ::TurnipFormatter::Scenario::Failure.new(example)
50
- output_scenario(scenario)
51
- end
52
-
53
34
  private
54
35
 
36
+ def output_html(params)
37
+ output.puts ::TurnipFormatter::Printer::Index.print_out(params)
38
+ FileUtils.rm_rf(SCENARIO_TEMPORARY_OUTPUT_DIR)
39
+ end
40
+
55
41
  def output_scenario(scenario)
56
42
  filepath = SCENARIO_TEMPORARY_OUTPUT_DIR + "/#{scenario.id}.html"
57
43
 
@@ -12,8 +12,14 @@ module Turnip
12
12
  step(step)
13
13
  rescue Turnip::Pending => e
14
14
  example.metadata[:line_number] = step.line
15
- pending("No such step(#{index}): '#{e}'")
16
- rescue StandardError => e
15
+ example.metadata[:location] = "#{example.metadata[:file_path]}:#{step.line}"
16
+
17
+ if ::RSpec::Version::STRING >= '2.99.0'
18
+ skip("No such step(#{index}): '#{e}'")
19
+ else
20
+ pending("No such step(#{index}): '#{e}'")
21
+ end
22
+ rescue StandardError, ::RSpec::Expectations::ExpectationNotMetError => e
17
23
  example.metadata[:line_number] = step.line
18
24
  e.backtrace.push "#{feature_file}:#{step.line}:in step:#{index} `#{step.description}'"
19
25
  raise e
@@ -40,7 +46,7 @@ module Turnip
40
46
  class << self
41
47
  def run(feature_file)
42
48
  Turnip::Builder.build(feature_file).features.each do |feature|
43
- describe feature.name, feature.metadata_hash do
49
+ ::RSpec.describe feature.name, feature.metadata_hash do
44
50
  let(:backgrounds) do
45
51
  feature.backgrounds
46
52
  end
@@ -0,0 +1,22 @@
1
+ module TurnipFormatter
2
+ module Helper
3
+ module HelperMethods
4
+ #
5
+ # @param [RSpec::Core::Example] example
6
+ # @param [OpenStruct or ::RSpec::Core::Example::ExecutionResult]
7
+ #
8
+ def example_execution_result(example)
9
+ case example.execution_result
10
+ when Hash
11
+ # RSpec 2
12
+ OpenStruct.new(example.execution_result)
13
+ when ::RSpec::Core::Example::ExecutionResult
14
+ # RSpec 3
15
+ example.execution_result
16
+ end
17
+ end
18
+ end
19
+
20
+ extend HelperMethods
21
+ end
22
+ end
@@ -6,10 +6,8 @@ module TurnipFormatter
6
6
  class RuntimeError
7
7
  class << self
8
8
  include TurnipFormatter::Printer
9
- include RSpec::Core::BacktraceFormatter
10
9
 
11
10
  def print_out(example, exception)
12
- exception.set_backtrace(format_backtrace(exception.backtrace))
13
11
  render_template(:runtime_exception, {
14
12
  example: example,
15
13
  runtime_exception: runtime_exception(exception),
@@ -3,8 +3,6 @@ require 'turnip_formatter/step'
3
3
  module TurnipFormatter
4
4
  module Scenario
5
5
  class Base
6
- include RSpec::Core::BacktraceFormatter
7
-
8
6
  attr_reader :errors
9
7
 
10
8
  #
@@ -15,7 +13,6 @@ module TurnipFormatter
15
13
  @errors = []
16
14
 
17
15
  validation
18
- clean_backtrace
19
16
  end
20
17
 
21
18
  def valid?
@@ -43,14 +40,14 @@ module TurnipFormatter
43
40
  # @return [String] scenario status ('passed', 'failed' or 'pending')
44
41
  #
45
42
  def status
46
- example.execution_result[:status]
43
+ execution_result.status.to_s
47
44
  end
48
45
 
49
46
  #
50
47
  # @return [String] scenario run time
51
48
  #
52
49
  def run_time
53
- example.execution_result[:run_time]
50
+ execution_result.run_time
54
51
  end
55
52
 
56
53
  def feature_info
@@ -59,7 +56,7 @@ module TurnipFormatter
59
56
  end
60
57
 
61
58
  def feature_name
62
- example.example_group.metadata[:example_group][:example_group][:description]
59
+ parent_example_group[:description]
63
60
  end
64
61
 
65
62
  def tags
@@ -72,27 +69,41 @@ module TurnipFormatter
72
69
 
73
70
  protected
74
71
 
75
- def validation
76
- unless example.metadata.key?(:turnip_formatter)
77
- @errors << 'has no steps information'
78
- end
72
+ def validation
73
+ unless example.metadata.key?(:turnip_formatter)
74
+ @errors << 'has no steps information'
79
75
  end
76
+ end
80
77
 
81
78
  private
82
79
 
83
- def feature_file_path
84
- example.metadata[:file_path]
85
- end
80
+ def feature_file_path
81
+ example.metadata[:file_path]
82
+ end
86
83
 
87
- def raw_steps
88
- example.metadata[:turnip_formatter][:steps]
89
- end
84
+ def raw_steps
85
+ example.metadata[:turnip_formatter][:steps]
86
+ end
90
87
 
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)
88
+ #
89
+ # @return [Hash] parent example group
90
+ #
91
+ def parent_example_group
92
+ if example.example_group.metadata.key?(:parent_example_group)
93
+ # RSpec 3
94
+ example.example_group.metadata[:parent_example_group]
95
+ else
96
+ # RSpec 2
97
+ example.example_group.metadata[:example_group][:example_group]
95
98
  end
99
+ end
100
+
101
+ #
102
+ # @return [OpenStruct or ::RSpec::Core::Example::ExecutionResult]
103
+ #
104
+ def execution_result
105
+ @execution_result ||= Helper.example_execution_result(example)
106
+ end
96
107
  end
97
108
  end
98
109
  end
@@ -27,7 +27,8 @@ module TurnipFormatter
27
27
  private
28
28
 
29
29
  def pending_message
30
- example.execution_result[:pending_message]
30
+ result = TurnipFormatter::Helper.example_execution_result(example)
31
+ result.pending_message
31
32
  end
32
33
  end
33
34
  end
@@ -32,23 +32,21 @@ module TurnipFormatter
32
32
  # @param [RSpec::Core::Example] example
33
33
  #
34
34
  def build_failed(example)
35
- build(example.exception)
35
+ build(example.exception.to_s, example.exception.backtrace)
36
36
  end
37
37
 
38
38
  #
39
39
  # @param [RSpec::Core::Example] example
40
40
  #
41
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)
42
+ result = TurnipFormatter::Helper.example_execution_result(example)
43
+ build(result.pending_message, [example.location])
46
44
  end
47
45
 
48
46
  private
49
47
 
50
- def build(exception)
51
- template_step_exception.render(exception)
48
+ def build(message, backtrace)
49
+ template_step_exception.render(Object.new, { message: message, backtrace: backtrace })
52
50
  end
53
51
 
54
52
  def template_step_exception
@@ -57,11 +55,11 @@ module TurnipFormatter
57
55
  %dl
58
56
  %dt Failure:
59
57
  %dd
60
- %pre&= exception.to_s
58
+ %pre&= message
61
59
  %dt Backtrace:
62
60
  %dd
63
61
  %ol
64
- - exception.backtrace.each do |line|
62
+ - backtrace.each do |line|
65
63
  %li&= line
66
64
  EOS
67
65
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module TurnipFormatter
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
@@ -43,6 +43,7 @@ module TurnipFormatter
43
43
  end
44
44
 
45
45
  require 'rspec/core/formatters/turnip_formatter'
46
+ require 'turnip_formatter/helper'
46
47
  require 'turnip_formatter/template'
47
48
  require 'turnip_formatter/step_template/exception'
48
49
  require 'turnip_formatter/step_template/source'
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec :path => '../..'
4
+ gem 'rspec', '~> 2.14.0'
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec :path => '../..'
4
+ gem 'rspec', '~> 2.99.0'
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec :path => '../..'
4
+ gem 'rspec', '~> 3.0.0'
@@ -10,9 +10,19 @@ module ExampleHelper
10
10
  end
11
11
 
12
12
  def pending_example
13
- example = base_example { pending('Pending') }
14
- example.execution_result[:pending_message] = 'No such step(0): '
15
- example
13
+ if ::RSpec::Version::STRING >= '2.99.0'
14
+ base_example { skip('No such step(0): ') }
15
+ else
16
+ base_example { pending('No such step(0): ') }
17
+ end
18
+ end
19
+
20
+ def invalid_pending_example
21
+ if ::RSpec::Version::STRING >= '2.99.0'
22
+ base_example { skip('Pending') }
23
+ else
24
+ base_example { pending('Pending') }
25
+ end
16
26
  end
17
27
 
18
28
  private
@@ -20,6 +30,7 @@ module ExampleHelper
20
30
  def base_example(&assertion)
21
31
  group = ::RSpec::Core::ExampleGroup.describe('Feature').describe('Scenario')
22
32
  example = group.example('example', example_metadata, &assertion)
33
+ example.metadata[:file_path] = '/path/to/hoge.feature'
23
34
  group.run(NoopObject.new)
24
35
  example
25
36
  end
@@ -29,8 +40,7 @@ module ExampleHelper
29
40
  turnip_formatter: {
30
41
  steps: [ { name: 'Step 1', extra_args: [], keyword: 'When' } ],
31
42
  tags: []
32
- },
33
- file_path: '/path/to/hoge.feature'
43
+ }
34
44
  }
35
45
  end
36
46
  end
@@ -13,7 +13,7 @@ describe TurnipFormatter::Scenario::Pending do
13
13
 
14
14
  context 'called by not turnip example' do
15
15
  let(:example) do
16
- pending_example.tap { |e| e.execution_result[:pending_message] = '' }
16
+ invalid_pending_example
17
17
  end
18
18
 
19
19
  it { should be false }
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'haml'
24
24
  spec.add_dependency 'sass'
25
25
  spec.add_dependency 'bootstrap-sass'
26
- spec.add_dependency 'rspec', '~> 2.14.0'
26
+ spec.add_dependency 'rspec', ['>=2.14.0', '<4.0']
27
27
  spec.add_development_dependency 'bundler', '~> 1.3'
28
28
  spec.add_development_dependency 'rake'
29
29
  spec.add_development_dependency 'rspec-html-matchers'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turnip_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wataru MIYAGUNI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-12 00:00:00.000000000 Z
11
+ date: 2014-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: turnip
@@ -84,16 +84,22 @@ dependencies:
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: 2.14.0
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '4.0'
90
93
  type: :runtime
91
94
  prerelease: false
92
95
  version_requirements: !ruby/object:Gem::Requirement
93
96
  requirements:
94
- - - "~>"
97
+ - - ">="
95
98
  - !ruby/object:Gem::Version
96
99
  version: 2.14.0
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: '4.0'
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: bundler
99
105
  requirement: !ruby/object:Gem::Requirement
@@ -198,8 +204,11 @@ files:
198
204
  - example/spec/steps/spell_steps.rb
199
205
  - example/spec/steps/steps.rb
200
206
  - lib/rspec/core/formatters/turnip_formatter.rb
207
+ - lib/rspec/core/formatters/turnip_formatter/for_rspec2.rb
208
+ - lib/rspec/core/formatters/turnip_formatter/for_rspec3.rb
201
209
  - lib/turnip_formatter.rb
202
210
  - lib/turnip_formatter/ext/turnip/rspec.rb
211
+ - lib/turnip_formatter/helper.rb
203
212
  - lib/turnip_formatter/printer.rb
204
213
  - lib/turnip_formatter/printer/index.rb
205
214
  - lib/turnip_formatter/printer/runtime_error.rb
@@ -231,6 +240,9 @@ files:
231
240
  - lib/turnip_formatter/template/turnip_formatter.js
232
241
  - lib/turnip_formatter/template/turnip_formatter.scss
233
242
  - lib/turnip_formatter/version.rb
243
+ - spec/gemfiles/Gemfile-rspec-2.14.x
244
+ - spec/gemfiles/Gemfile-rspec-2.99.x
245
+ - spec/gemfiles/Gemfile-rspec-3.0.x
234
246
  - spec/spec_helper.rb
235
247
  - spec/support/example_helper.rb
236
248
  - spec/support/passed.feature
@@ -275,6 +287,9 @@ signing_key:
275
287
  specification_version: 4
276
288
  summary: RSpec custom formatter for Turnip
277
289
  test_files:
290
+ - spec/gemfiles/Gemfile-rspec-2.14.x
291
+ - spec/gemfiles/Gemfile-rspec-2.99.x
292
+ - spec/gemfiles/Gemfile-rspec-3.0.x
278
293
  - spec/spec_helper.rb
279
294
  - spec/support/example_helper.rb
280
295
  - spec/support/passed.feature