turnip_formatter 0.6.0.pre.beta.4 → 0.6.0.pre.beta.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67feb08897f64d961ba76a513c0db5b4b133c0d6
4
- data.tar.gz: 923976e4503e4588819f9adc5b625e89505990b5
3
+ metadata.gz: baf4114e2e982e5788654b0cdd6f72d7a7a3af99
4
+ data.tar.gz: 0444ef49fdcc2d624319a8b5b40e783cc08c5a31
5
5
  SHA512:
6
- metadata.gz: 41bc4fcec63fb4ef824d976b5f6c51f12f05d985716755fe1c1e6ee03cbab1ba7a5c00f007735c982d58b02d173f201bb2f7f2593356d508b7477995b7f3ff8f
7
- data.tar.gz: 8a451d6cc4471516b21499385e7300c2decccc554a652fc9d614eec35323db7b1a0b70ade4b7c014b6092e231a790f4d19ed0c45196dfecae8aec5976525d0da
6
+ metadata.gz: f42fa830ffaf90f70ab06b8ce582a2499b0366381d04d1615a71c2ff732b571bd7b8bde4163e7cff15e88e2a7332838f231390ba1014658fd8b0cab7ff05c273
7
+ data.tar.gz: 0e0de0bae97e4fe1e7fe367ae8ae7721622e1f2b9b06fee8a610efbbb10e74386e314e11f1e3d7382a8fed387ee3c7d3319967e2ce6c209766a058552536662f
data/.travis.yml CHANGED
@@ -10,7 +10,6 @@ branches:
10
10
 
11
11
  matrix:
12
12
  allow_failures:
13
- - gemfile: gemfiles/Gemfile-rspec-3.2.x
14
13
  - rvm: ruby-head
15
14
 
16
15
  rvm:
@@ -24,6 +23,5 @@ script:
24
23
  - bundle exec rake test
25
24
 
26
25
  gemfile:
27
- - gemfiles/Gemfile-rspec-3.2.x
28
26
  - gemfiles/Gemfile-rspec-3.3.x
29
27
  - gemfiles/Gemfile-rspec-3.4.x
@@ -0,0 +1,15 @@
1
+ Feature: A feature with argument
2
+ Scenario: This is a feature with DocString
3
+ When the monster sings the following song
4
+ """
5
+ Oh here be monsters
6
+ This is cool
7
+ """
8
+ Then the song should have 2 lines
9
+
10
+ Scenario: This is a feature with DocTable
11
+ When there are monsters:
12
+ | gargoyle |
13
+ | Cockatrice |
14
+ Then there should be 2 monsters
15
+
@@ -10,15 +10,18 @@ Feature: Battle a monster with weapon
10
10
  And Fanfare
11
11
 
12
12
  Scenario: strong monster
13
+
14
+ His attacks can defeat strong monster if has weapon.
15
+
13
16
  Given there is a strong monster
14
17
  When I attack it
15
18
  Then it should die
16
19
  And Fanfare
17
-
18
- Scenario: boss monster
19
20
 
20
- This scenario will error
21
- So, fanfare is not...oh...
21
+ Scenario: [ERROR] boss monster
22
+
23
+ This scenario will not success.
24
+ Because his attacks can't defeat boss monster even if has weapon.
22
25
 
23
26
  Given there is a boss monster
24
27
  When I attack it
@@ -6,19 +6,18 @@ Feature: Battle a monster
6
6
  Then it should die
7
7
  And Fanfare
8
8
 
9
- Scenario: strong monster
9
+ Scenario: [ERROR] strong monster
10
10
 
11
- This scenario will error
12
- So, fanfare is not...oh...
11
+ This scenario will not success because his attacks can't defeat strong monster
13
12
 
14
13
  Given there is a strong monster
15
14
  When I attack it
16
15
  Then it should die
17
16
  And Fanfare
18
17
 
19
- Scenario: spell magic
18
+ Scenario: [PENDING] spell magic
20
19
 
21
- This scenario will error because he can't cast spell
20
+ This scenario will not success because he can't cast spell
22
21
 
23
22
  Given there is a strong monster
24
23
  When I cast a spell 'fireball'
@@ -27,7 +26,9 @@ Feature: Battle a monster
27
26
  And Fanfare
28
27
 
29
28
  @magician
30
- Scenario: spell magic
29
+ Scenario: spell magic
30
+
31
+ `magician` can cast spell.
31
32
 
32
33
  Given there is a strong monster
33
34
  When I cast a spell 'fireball'
@@ -0,0 +1,22 @@
1
+ Feature: Battle a monster with hooks
2
+
3
+ @before_hook_error
4
+ Scenario: [ERROR] Error in before hook
5
+ Given there is a monster
6
+ When I attack it
7
+ Then it should die
8
+ And Fanfare
9
+
10
+ @after_hook_error
11
+ Scenario: [ERROR] Error in after hook
12
+ Given there is a monster
13
+ When I attack it
14
+ Then it should die
15
+ And Fanfare
16
+
17
+ @after_hook_error
18
+ Scenario: [ERROR] Error in steps and after hook
19
+ Given there is a strong monster
20
+ When I attack it
21
+ Then it should die
22
+ And Fanfare
@@ -6,6 +6,16 @@ end
6
6
 
7
7
  Dir.glob(File.dirname(__FILE__) + '/steps/**/*steps.rb') { |f| load f, true }
8
8
 
9
+ RSpec.configure do |config|
10
+ config.before(:example, before_hook_error: true) do
11
+ undefined_method # NameError
12
+ end
13
+
14
+ config.after(:example, after_hook_error: true) do
15
+ expect(true).to be false # RSpec Matcher Error
16
+ end
17
+ end
18
+
9
19
  # TurnipFormatter.configure do |config|
10
20
  # config.title = 'My Report'
11
21
  # config.add_stylesheet File.dirname(__FILE__) + '/foo.css'
@@ -32,6 +32,10 @@ step "there are monsters:" do |monsters|
32
32
  @monsters = monsters.map { |row| row[0] }
33
33
  end
34
34
 
35
+ step "there should be :count monsters" do |count|
36
+ @monsters.length.should eq(count.to_i)
37
+ end
38
+
35
39
  step "the monster sings the following song" do |song|
36
40
  @song = song
37
41
  end
@@ -15,9 +15,10 @@ module RSpec
15
15
 
16
16
  Formatters.register self, :example_passed, :example_pending, :example_failed, :dump_summary
17
17
 
18
- def self.formatted_backtrace(example)
18
+ def self.formatted_backtrace(example, exception = nil)
19
+ exception = example.exception if exception.nil?
19
20
  formatter = RSpec.configuration.backtrace_formatter
20
- formatter.format_backtrace(example.exception.backtrace, example.metadata)
21
+ formatter.format_backtrace(exception.backtrace, example.metadata)
21
22
  end
22
23
 
23
24
  def initialize(output)
@@ -0,0 +1,30 @@
1
+ module TurnipFormatter
2
+ module Resource
3
+ class Hook
4
+ attr_reader :example
5
+ attr_reader :keyword
6
+ attr_reader :status
7
+
8
+ #
9
+ # @param [RSpec::Core::Example] example
10
+ #
11
+ def initialize(example, keyword, status)
12
+ @example = example
13
+ @keyword = keyword
14
+ @status = status
15
+ end
16
+
17
+ def text
18
+ ''
19
+ end
20
+
21
+ def line
22
+ -1
23
+ end
24
+
25
+ def argument
26
+ nil
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,9 +1,12 @@
1
1
  require 'turnip_formatter/resource/scenario/base'
2
+ require 'turnip_formatter/resource/hook'
2
3
 
3
4
  module TurnipFormatter
4
5
  module Resource
5
6
  module Scenario
6
7
  class Failure < Base
8
+ alias :super_steps :steps
9
+
7
10
  #
8
11
  # Return steps
9
12
  #
@@ -19,11 +22,40 @@ module TurnipFormatter
19
22
  # #<Step 'baz'>.status = :failed
20
23
  # #<Step 'piyo'>.status = :unexecute
21
24
  #
25
+ # @TODO Correspond to multiple errors.
26
+ #
27
+ # example:
22
28
  #
23
- # @todo failed_at_before_hook, failed_at_after_hook GH-67
29
+ # # foo.feature
30
+ # @after_hook
31
+ # When foo
32
+ # And bar <= failed line
33
+ # Then baz
34
+ #
35
+ # # spec_helper.rb
36
+ # RSpec.configure do |config|
37
+ # config.after(:example, after_hook: true) do
38
+ # raise RuntimeError
39
+ # end
40
+ # end
41
+ #
42
+ # Currently, display only first error (`And bar`).
24
43
  #
25
44
  def steps
26
- steps = super
45
+ case
46
+ when error_in_steps?
47
+ steps_with_error
48
+ when error_in_before_hook?
49
+ steps_with_error_in_before_hook
50
+ when error_in_after_hook?
51
+ steps_with_error_in_after_hook
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def steps_with_error
58
+ steps = super_steps
27
59
 
28
60
  arys = steps.group_by { |s| (s.line <=> failed_line_number).to_s }
29
61
  arys['-1'].each { |s| s.status = :passed } unless arys['-1'].nil?
@@ -33,17 +65,52 @@ module TurnipFormatter
33
65
  steps
34
66
  end
35
67
 
36
- private
68
+ def steps_with_error_in_before_hook
69
+ steps = super_steps
70
+
71
+ steps.each { |s| s.status = :unexecute }
72
+ [TurnipFormatter::Resource::Hook.new(example, 'BeforeHook', :failed)] + steps
73
+ end
74
+
75
+ def steps_with_error_in_after_hook
76
+ super_steps + [TurnipFormatter::Resource::Hook.new(example, 'AfterHook', :failed)]
77
+ end
78
+
79
+ def error_in_steps?
80
+ !failed_line_number.nil?
81
+ end
82
+
83
+ def error_in_before_hook?
84
+ exception.backtrace.any? do |backtrace|
85
+ backtrace.match(/run_before_example/)
86
+ end
87
+ end
88
+
89
+ def error_in_after_hook?
90
+ exception.backtrace.any? do |backtrace|
91
+ backtrace.match(/run_after_example/)
92
+ end
93
+ end
37
94
 
38
95
  def failed_line_number
39
96
  @failed_line_number ||= (
40
97
  filepath = File.basename(feature_file_path)
41
- line = example.exception.backtrace.find do |backtrace|
98
+ line = exception.backtrace.find do |backtrace|
42
99
  backtrace.match(/#{filepath}:(\d+)/)
43
100
  end
44
101
  Regexp.last_match[1].to_i if line
45
102
  )
46
103
  end
104
+
105
+ def exception
106
+ @exception ||= (
107
+ if example.exception.is_a?(RSpec::Core::MultipleExceptionError)
108
+ example.exception.all_exceptions.first
109
+ else
110
+ example.exception
111
+ end
112
+ )
113
+ end
47
114
  end
48
115
  end
49
116
  end
@@ -30,8 +30,8 @@ module TurnipFormatter
30
30
  end
31
31
  end
32
32
 
33
- def formatted_backtrace(example)
34
- RSpec::Core::Formatters::TurnipFormatter.formatted_backtrace(example)
33
+ def formatted_backtrace(example, exception = nil)
34
+ RSpec::Core::Formatters::TurnipFormatter.formatted_backtrace(example, exception)
35
35
  end
36
36
  end
37
37
  end
@@ -28,7 +28,13 @@ module TurnipFormatter
28
28
  # @param [RSpec::Core::Example] example
29
29
  #
30
30
  def build_failed(example)
31
- build(example.exception.to_s, formatted_backtrace(example))
31
+ exception = example.exception
32
+
33
+ if example.exception.is_a?(RSpec::Core::MultipleExceptionError)
34
+ exception = example.exception.all_exceptions.first
35
+ end
36
+
37
+ build(exception.to_s, formatted_backtrace(example, exception))
32
38
  end
33
39
 
34
40
  #
@@ -40,13 +46,13 @@ module TurnipFormatter
40
46
 
41
47
  private
42
48
 
43
- def build(message, backtrace)
44
- template_step_exception.render(Object.new, { message: message, backtrace: backtrace })
45
- end
49
+ def build(message, backtrace)
50
+ template_step_exception.render(Object.new, { message: message, backtrace: backtrace })
51
+ end
46
52
 
47
- def template_step_exception
48
- @template_step_exception ||= Slim::Template.new(File.dirname(__FILE__) + "/exception.slim")
49
- end
53
+ def template_step_exception
54
+ @template_step_exception ||= Slim::Template.new(File.dirname(__FILE__) + "/exception.slim")
55
+ end
50
56
  end
51
57
  end
52
58
  end
@@ -38,7 +38,13 @@ module TurnipFormatter
38
38
  private
39
39
 
40
40
  def location(example)
41
- formatted_backtrace(example).first
41
+ exception = example.exception
42
+
43
+ if example.exception.is_a?(RSpec::Core::MultipleExceptionError)
44
+ exception = example.exception.all_exceptions.first
45
+ end
46
+
47
+ formatted_backtrace(example, exception).first
42
48
  end
43
49
 
44
50
  def extractor
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module TurnipFormatter
4
- VERSION = '0.6.0-beta.4'
4
+ VERSION = '0.6.0-beta.5'
5
5
  end
data/test/helper.rb CHANGED
@@ -71,6 +71,14 @@ module TurnipFormatter
71
71
  rspec_context.include(Turnip::RSpec::Execute)
72
72
  rspec_context.include(ExecuteWrapper)
73
73
 
74
+ rspec_context.before(:example, before_hook_error: true) do
75
+ undefined_method # NameError
76
+ end
77
+
78
+ rspec_context.after(:example, after_hook_error: true) do
79
+ expect(true).to be false # RSpec Matcher Error
80
+ end
81
+
74
82
  Turnip::RSpec.__send__(:run_feature, rspec_context, feature, filename)
75
83
  rspec_context.run(NoopObject.new)
76
84
  Turnip::RSpec.update_metadata(feature, rspec_context)
@@ -5,35 +5,100 @@ module TurnipFormatter::Resource::Scenario
5
5
  class TestFailure < Test::Unit::TestCase
6
6
  include TurnipFormatter::TestHelper
7
7
 
8
- def setup
9
- @resource = Failure.new(scenario_example)
10
- end
11
-
12
8
  def test_status
9
+ @resource = Failure.new(scenario_example)
13
10
  assert_equal(:failed, @resource.status)
14
11
  end
15
12
 
16
13
  def test_steps
14
+ @resource = Failure.new(scenario_example)
15
+
17
16
  expect = [:passed, :failed, :unexecute]
18
17
  actual = @resource.steps.map(&:status)
19
18
 
20
19
  assert_equal(expect, actual)
21
20
  end
22
21
 
22
+ def test_steps_has_error_in_before_hook
23
+ @resource = Failure.new(scenario_error_before_hook)
24
+
25
+ expect = [:failed, :unexecute, :unexecute]
26
+ actual = @resource.steps.map(&:status)
27
+
28
+ assert_equal(expect, actual)
29
+ assert_equal(TurnipFormatter::Resource::Hook, @resource.steps.first.class)
30
+ end
31
+
32
+ def test_steps_has_error_in_after_hook
33
+ @resource = Failure.new(scenario_error_after_hook)
34
+
35
+ expect = [:passed, :passed, :failed]
36
+ actual = @resource.steps.map(&:status)
37
+
38
+ assert_equal(expect, actual)
39
+ assert_equal(TurnipFormatter::Resource::Hook, @resource.steps.last.class)
40
+ end
41
+
42
+ def test_steps_has_error_in_steps_and_after_hook
43
+ @resource = Failure.new(scenario_error_step_and_after_hook)
44
+
45
+ expect = [:passed, :failed, :unexecute]
46
+ actual = @resource.steps.map(&:status)
47
+
48
+ assert_equal(expect, actual)
49
+ assert_equal(TurnipFormatter::Resource::Step, @resource.steps.last.class)
50
+ end
51
+
23
52
  private
24
53
 
25
54
  def scenario_example
26
- @@scenario_example ||= (
27
- feature = feature_build(<<-EOS)
28
- Feature: A simple feature
29
- Scenario: This is a simple feature
30
- When I attack it
31
- Then [ERROR] it should die
32
- And I get drop items
33
- EOS
34
-
35
- run_feature(feature, '/path/to/test.feature').first
55
+ scenario_examples[0]
56
+ end
57
+
58
+ def scenario_error_before_hook
59
+ scenario_examples[1]
60
+ end
61
+
62
+ def scenario_error_after_hook
63
+ scenario_examples[2]
64
+ end
65
+
66
+ def scenario_error_step_and_after_hook
67
+ scenario_examples[3]
68
+ end
69
+
70
+ def scenario_examples
71
+ @@scenario_examples ||= (
72
+ feature = feature_build(feature_text)
73
+ run_feature(feature, '/path/to/test.feature')
36
74
  )
37
75
  end
76
+
77
+ def feature_text
78
+ <<-EOS
79
+ Feature: A simple feature
80
+ Scenario: This is a simple feature
81
+ When I attack it
82
+ Then [ERROR] it should die
83
+ And I get drop items
84
+
85
+ @before_hook_error
86
+ Scenario: Error in before hook
87
+ When I attack it
88
+ Then it should die
89
+
90
+ @after_hook_error
91
+ Scenario: Error in after hook
92
+ When I attack it
93
+ Then it should die
94
+
95
+ @after_hook_error
96
+ Scenario: Error in after hook
97
+ When I attack it
98
+ Then [ERROR] it should die
99
+ And I get drop items
100
+
101
+ EOS
102
+ end
38
103
  end
39
104
  end
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'turnip', '~> 3.0.0.pre.beta.4'
22
22
  spec.add_dependency 'slim'
23
- spec.add_dependency 'rspec', [">=3.0", "<3.5"]
23
+ spec.add_dependency 'rspec', [">=3.3", "<3.5"]
24
24
 
25
25
  # For ruby >= 2.1
26
26
  spec.add_dependency 'activesupport', '~> 4.2.7'
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.6.0.pre.beta.4
4
+ version: 0.6.0.pre.beta.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wataru MIYAGUNI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-21 00:00:00.000000000 Z
11
+ date: 2017-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: turnip
@@ -44,7 +44,7 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '3.3'
48
48
  - - "<"
49
49
  - !ruby/object:Gem::Version
50
50
  version: '3.5'
@@ -54,7 +54,7 @@ dependencies:
54
54
  requirements:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
- version: '3.0'
57
+ version: '3.3'
58
58
  - - "<"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '3.5'
@@ -208,16 +208,16 @@ files:
208
208
  - example/images/outline.png
209
209
  - example/images/pending_step.png
210
210
  - example/spec/bar.js
211
- - example/spec/features/battle.feature
212
- - example/spec/features/battle2.feature
213
- - example/spec/features/battle3.feature
214
- - example/spec/features/songs.feature
211
+ - example/spec/features/argument.feature
212
+ - example/spec/features/background.feature
213
+ - example/spec/features/basic.feature
214
+ - example/spec/features/module_and_steps_for.feature
215
+ - example/spec/features/rspec_hooks.feature
215
216
  - example/spec/foo.css
216
217
  - example/spec/spec_helper.rb
217
218
  - example/spec/steps/escape_steps.rb
218
219
  - example/spec/steps/spell_steps.rb
219
220
  - example/spec/steps/steps.rb
220
- - gemfiles/Gemfile-rspec-3.2.x
221
221
  - gemfiles/Gemfile-rspec-3.3.x
222
222
  - gemfiles/Gemfile-rspec-3.4.x
223
223
  - lib/rspec/core/formatters/turnip_formatter.rb
@@ -246,6 +246,7 @@ files:
246
246
  - lib/turnip_formatter/renderer/html/views/statistics_speed.html.erb
247
247
  - lib/turnip_formatter/renderer/html/views/statistics_tag.html.erb
248
248
  - lib/turnip_formatter/renderer/html/views/step.html.erb
249
+ - lib/turnip_formatter/resource/hook.rb
249
250
  - lib/turnip_formatter/resource/scenario/base.rb
250
251
  - lib/turnip_formatter/resource/scenario/failure.rb
251
252
  - lib/turnip_formatter/resource/scenario/pass.rb
@@ -1,19 +0,0 @@
1
- # Based on turnip/examples
2
-
3
- Feature: A feature with multiline strings
4
- Scenario: This is a feature with multiline strings
5
- When the monster sings the following song
6
- """
7
- Oh here be monsters
8
- This is cool
9
- """
10
- Then the song should have 2 lines
11
-
12
- Scenario: This is a feature with multiline strings
13
- When a monster sings the following song
14
- """
15
- Oh here be monsters
16
- This is cool
17
- """
18
- Then the song should have 2 lines
19
-
@@ -1,4 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gemspec :path => '..'
4
- gem 'rspec', '~> 3.2.0'