turnip_formatter 0.6.0.pre.beta.1 → 0.6.0.pre.beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +4 -1
  4. data/Rakefile +8 -0
  5. data/lib/rspec/core/formatters/turnip_formatter.rb +1 -0
  6. data/lib/turnip_formatter/ext/turnip/rspec.rb +6 -6
  7. data/lib/turnip_formatter/printer/runtime_error.rb +0 -1
  8. data/lib/turnip_formatter/printer/scenario.rb +1 -1
  9. data/lib/turnip_formatter/renderer/html/base.rb +47 -0
  10. data/lib/turnip_formatter/renderer/html/data_table.rb +16 -0
  11. data/lib/turnip_formatter/renderer/html/doc_string.rb +16 -0
  12. data/lib/turnip_formatter/renderer/html/step.rb +47 -0
  13. data/lib/turnip_formatter/renderer/html/views/data_table.html.erb +9 -0
  14. data/lib/turnip_formatter/renderer/html/views/doc_string.html.erb +1 -0
  15. data/lib/turnip_formatter/renderer/html/views/step.html.erb +10 -0
  16. data/lib/turnip_formatter/resource/step.rb +23 -0
  17. data/lib/turnip_formatter/scenario/base.rb +2 -2
  18. data/lib/turnip_formatter/template/scenario.slim +1 -1
  19. data/lib/turnip_formatter/template/turnip_formatter.css +5 -1
  20. data/lib/turnip_formatter/template/turnip_formatter.scss +2 -2
  21. data/lib/turnip_formatter/version.rb +1 -1
  22. data/spec/support/step_helper.rb +1 -1
  23. data/spec/turnip_formatter/scenario/base_spec.rb +1 -1
  24. data/test/helper.rb +31 -0
  25. data/test/sample.feature +16 -0
  26. data/test/turnip_formatter/renderer/html/test_data_table.rb +30 -0
  27. data/test/turnip_formatter/renderer/html/test_doc_string.rb +17 -0
  28. data/test/turnip_formatter/renderer/html/test_step.rb +38 -0
  29. data/turnip_formatter.gemspec +8 -1
  30. metadata +73 -13
  31. data/lib/turnip_formatter/printer/step.rb +0 -35
  32. data/lib/turnip_formatter/printer/step_extra_args.rb +0 -24
  33. data/lib/turnip_formatter/template/step.slim +0 -6
  34. data/lib/turnip_formatter/template/step_multiline.slim +0 -1
  35. data/lib/turnip_formatter/template/step_outline.slim +0 -6
  36. data/spec/turnip_formatter/printer/step_extra_args_spec.rb +0 -32
  37. data/spec/turnip_formatter/printer/step_spec.rb +0 -49
@@ -86,14 +86,14 @@ div#steps-statistics section.scenario {
86
86
  @extend .panel-body;
87
87
  }
88
88
 
89
- table.step_outline {
89
+ table.step_data_table {
90
90
  margin-top: 2em;
91
91
  @extend .table;
92
92
  @extend .table-striped;
93
93
  @extend .table-bordered;
94
94
  }
95
95
 
96
- pre.multiline {
96
+ pre.step_doc_string {
97
97
  margin-top: 2em;
98
98
  font-size: 13px;
99
99
  color: #586e75;
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module TurnipFormatter
4
- VERSION = '0.6.0-beta.1'
4
+ VERSION = '0.6.0-beta.2'
5
5
  end
@@ -18,7 +18,7 @@ module StepHelper
18
18
  private
19
19
 
20
20
  def base_step(example)
21
- TurnipFormatter::Step.new(example, step_description)
21
+ TurnipFormatter::Resource::Step.new(example, step_description)
22
22
  end
23
23
 
24
24
  def step_description
@@ -31,7 +31,7 @@ describe TurnipFormatter::Scenario::Base do
31
31
 
32
32
  it 'returns step array' do
33
33
  expect(subject).to be_a Array
34
- expect(subject[0]).to be_a TurnipFormatter::Step
34
+ expect(subject[0]).to be_a TurnipFormatter::Resource::Step
35
35
  end
36
36
  end
37
37
 
data/test/helper.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'test/unit'
2
+ require 'oga'
3
+
4
+ def html_parse(str)
5
+ Oga.parse_xml(str)
6
+ end
7
+
8
+ module TurnipFormatter
9
+ module TestHelper
10
+ @@sample_feature = nil
11
+
12
+ def sample_step
13
+ sample_feature.scenarios[0].steps[0]
14
+ end
15
+
16
+ def sample_step_with_docstring
17
+ sample_feature.scenarios[0].steps[1]
18
+ end
19
+
20
+ def sample_step_with_datatable
21
+ sample_feature.scenarios[0].steps[2]
22
+ end
23
+
24
+ def sample_feature
25
+ return @@sample_feature if @@sample_feature
26
+
27
+ filename = File.expand_path('./sample.feature', File.dirname(__FILE__))
28
+ @@sample_feature = Turnip::Builder.build(filename)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ Feature: Feature
2
+
3
+ Scenario: Scenario
4
+ When step
5
+ When step with DocString
6
+ """
7
+ DocString
8
+ """
9
+ When step with DataTable:
10
+ | nam | age |
11
+ | Tom | 10 |
12
+ | Jerry | 23 |
13
+
14
+ @tag1 @tag2
15
+ Scenario: Scenario With Tags
16
+ When step
@@ -0,0 +1,30 @@
1
+ require 'helper'
2
+ require 'turnip_formatter/renderer/html/data_table'
3
+ require 'turnip/table'
4
+
5
+ module TurnipFormatter::Renderer::Html
6
+ class TestDataTable < Test::Unit::TestCase
7
+ def test_render
8
+ renderer = DataTable.new(
9
+ table(
10
+ [
11
+ ['name', 'hp'],
12
+ ['slime', '10'],
13
+ ['daemon', '300']
14
+ ]
15
+ )
16
+ )
17
+
18
+ document = html_parse(renderer.render).at_xpath('table')
19
+
20
+ assert_equal(3, document.xpath('./tr').size)
21
+ assert_equal(6, document.xpath('.//td').size)
22
+ end
23
+
24
+ private
25
+
26
+ def table(rows)
27
+ Turnip::Table.new(rows)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ require 'helper'
2
+ require 'turnip_formatter/renderer/html/doc_string'
3
+
4
+ module TurnipFormatter::Renderer::Html
5
+ class TestDocString < Test::Unit::TestCase
6
+ def test_render
7
+ renderer = DocString.new(<<-'EOS')
8
+ I Am a Cat
9
+ EOS
10
+
11
+ document = html_parse(renderer.render).at_xpath('pre')
12
+
13
+ assert_equal('step_doc_string', document.get('class'))
14
+ assert_equal('I Am a Cat', document.text.strip)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,38 @@
1
+ require 'helper'
2
+ require 'turnip_formatter/renderer/html/step'
3
+ require 'turnip_formatter/resource/step'
4
+
5
+ module TurnipFormatter::Renderer::Html
6
+ class TestStep < Test::Unit::TestCase
7
+ include TurnipFormatter::TestHelper
8
+
9
+ sub_test_case 'step without argument' do
10
+ def setup
11
+ resource = TurnipFormatter::Resource::Step.new(nil, sample_step)
12
+ @renderer = Step.new(resource)
13
+ end
14
+
15
+ def test_render
16
+ document = html_parse(@renderer.render).at_xpath('/div')
17
+
18
+ assert_equal('step passed', document.get('class'))
19
+ assert_equal('When step', document.at_css('div.step-title').text)
20
+ assert_nil(document.at_css('div.step-body'))
21
+ end
22
+ end
23
+
24
+ sub_test_case 'step with argument' do
25
+ def setup
26
+ resource = TurnipFormatter::Resource::Step.new(nil, sample_step_with_docstring)
27
+ @renderer = Step.new(resource)
28
+ end
29
+
30
+ def test_render
31
+ document = html_parse(@renderer.render).at_xpath('/div')
32
+
33
+ assert_equal('When step with DocString', document.at_css('div.step-title').text)
34
+ assert_not_nil(document.at_css('div.step-body'))
35
+ end
36
+ end
37
+ end
38
+ end
@@ -18,12 +18,19 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^spec/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'turnip', '~> 3.0.0.pre.beta'
21
+ spec.add_dependency 'turnip', '~> 3.0.0.pre.beta.4'
22
22
  spec.add_dependency 'slim'
23
+ spec.add_dependency 'tilt'
23
24
  spec.add_dependency 'rspec', [">=3.0", "<3.5"]
25
+
26
+ # For ruby >= 2.1
27
+ spec.add_dependency 'activesupport', '~> 4.2.7'
28
+
29
+ spec.add_development_dependency 'test-unit'
24
30
  spec.add_development_dependency 'bundler', '~> 1.3'
25
31
  spec.add_development_dependency 'rake'
26
32
  spec.add_development_dependency 'coveralls'
27
33
  spec.add_development_dependency 'sass'
28
34
  spec.add_development_dependency 'bootstrap-sass'
35
+ spec.add_development_dependency 'oga'
29
36
  end
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.1
4
+ version: 0.6.0.pre.beta.2
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-10-04 00:00:00.000000000 Z
11
+ date: 2016-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: turnip
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0.pre.beta
19
+ version: 3.0.0.pre.beta.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.0.pre.beta
26
+ version: 3.0.0.pre.beta.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: slim
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tilt
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +72,34 @@ dependencies:
58
72
  - - "<"
59
73
  - !ruby/object:Gem::Version
60
74
  version: '3.5'
75
+ - !ruby/object:Gem::Dependency
76
+ name: activesupport
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 4.2.7
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 4.2.7
89
+ - !ruby/object:Gem::Dependency
90
+ name: test-unit
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
61
103
  - !ruby/object:Gem::Dependency
62
104
  name: bundler
63
105
  requirement: !ruby/object:Gem::Requirement
@@ -128,6 +170,20 @@ dependencies:
128
170
  - - ">="
129
171
  - !ruby/object:Gem::Version
130
172
  version: '0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: oga
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
131
187
  description: RSpec custom formatter for Turnip
132
188
  email:
133
189
  - gonngo@gmail.com
@@ -171,11 +227,17 @@ files:
171
227
  - lib/turnip_formatter/printer/index.rb
172
228
  - lib/turnip_formatter/printer/runtime_error.rb
173
229
  - lib/turnip_formatter/printer/scenario.rb
174
- - lib/turnip_formatter/printer/step.rb
175
- - lib/turnip_formatter/printer/step_extra_args.rb
176
230
  - lib/turnip_formatter/printer/tab_feature_statistics.rb
177
231
  - lib/turnip_formatter/printer/tab_speed_statistics.rb
178
232
  - lib/turnip_formatter/printer/tab_tag_statistics.rb
233
+ - lib/turnip_formatter/renderer/html/base.rb
234
+ - lib/turnip_formatter/renderer/html/data_table.rb
235
+ - lib/turnip_formatter/renderer/html/doc_string.rb
236
+ - lib/turnip_formatter/renderer/html/step.rb
237
+ - lib/turnip_formatter/renderer/html/views/data_table.html.erb
238
+ - lib/turnip_formatter/renderer/html/views/doc_string.html.erb
239
+ - lib/turnip_formatter/renderer/html/views/step.html.erb
240
+ - lib/turnip_formatter/resource/step.rb
179
241
  - lib/turnip_formatter/scenario/base.rb
180
242
  - lib/turnip_formatter/scenario/failure.rb
181
243
  - lib/turnip_formatter/scenario/pass.rb
@@ -190,9 +252,6 @@ files:
190
252
  - lib/turnip_formatter/template/index.slim
191
253
  - lib/turnip_formatter/template/runtime_exception.slim
192
254
  - lib/turnip_formatter/template/scenario.slim
193
- - lib/turnip_formatter/template/step.slim
194
- - lib/turnip_formatter/template/step_multiline.slim
195
- - lib/turnip_formatter/template/step_outline.slim
196
255
  - lib/turnip_formatter/template/tab_feature_statistics.slim
197
256
  - lib/turnip_formatter/template/tab_speed_statistics.slim
198
257
  - lib/turnip_formatter/template/tab_tag_statistics.slim
@@ -206,8 +265,6 @@ files:
206
265
  - spec/support/step_helper.rb
207
266
  - spec/turnip_formatter/printer/index_spec.rb
208
267
  - spec/turnip_formatter/printer/scenario_spec.rb
209
- - spec/turnip_formatter/printer/step_extra_args_spec.rb
210
- - spec/turnip_formatter/printer/step_spec.rb
211
268
  - spec/turnip_formatter/printer/tab_feature_statistics_spec.rb
212
269
  - spec/turnip_formatter/printer/tab_speed_statistics_spec.rb
213
270
  - spec/turnip_formatter/printer/tab_tag_statistics_spec.rb
@@ -218,6 +275,11 @@ files:
218
275
  - spec/turnip_formatter/step_template/exception_spec.rb
219
276
  - spec/turnip_formatter/step_template/source_spec.rb
220
277
  - spec/turnip_formatter/template_spec.rb
278
+ - test/helper.rb
279
+ - test/sample.feature
280
+ - test/turnip_formatter/renderer/html/test_data_table.rb
281
+ - test/turnip_formatter/renderer/html/test_doc_string.rb
282
+ - test/turnip_formatter/renderer/html/test_step.rb
221
283
  - turnip_formatter.gemspec
222
284
  homepage: https://github.com/gongo/turnip_formatter
223
285
  licenses:
@@ -250,8 +312,6 @@ test_files:
250
312
  - spec/support/step_helper.rb
251
313
  - spec/turnip_formatter/printer/index_spec.rb
252
314
  - spec/turnip_formatter/printer/scenario_spec.rb
253
- - spec/turnip_formatter/printer/step_extra_args_spec.rb
254
- - spec/turnip_formatter/printer/step_spec.rb
255
315
  - spec/turnip_formatter/printer/tab_feature_statistics_spec.rb
256
316
  - spec/turnip_formatter/printer/tab_speed_statistics_spec.rb
257
317
  - spec/turnip_formatter/printer/tab_tag_statistics_spec.rb
@@ -1,35 +0,0 @@
1
- require 'turnip_formatter/printer'
2
-
3
- module TurnipFormatter
4
- module Printer
5
- class Step
6
- class << self
7
- include TurnipFormatter::Printer
8
-
9
- def print_out(step)
10
- step_templates = TurnipFormatter.step_templates_for(step.status)
11
-
12
- render_template(:step,
13
- {
14
- step: step,
15
- has_args_or_documents: has_args_or_documents?(step, step_templates),
16
- step_docs: documents(step, step_templates)
17
- }
18
- )
19
- end
20
-
21
- private
22
-
23
- def has_args_or_documents?(step, templates)
24
- step.argument || (templates.length > 0)
25
- end
26
-
27
- def documents(step, templates)
28
- templates.map do |template, method|
29
- template.send(method, step.example)
30
- end.join("\n")
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,24 +0,0 @@
1
- require 'turnip_formatter/printer'
2
-
3
- module TurnipFormatter
4
- module Printer
5
- class StepExtraArgs
6
- class << self
7
- include TurnipFormatter::Printer
8
-
9
- #
10
- # @param [nil or String or Turnip::Table] Step argument
11
- #
12
- def print_out(argument)
13
- return '' if argument.nil?
14
-
15
- if argument.instance_of?(Turnip::Table)
16
- render_template(:step_outline, { table: argument.to_a })
17
- else
18
- render_template(:step_multiline, { lines: argument })
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,6 +0,0 @@
1
- div class="step #{step.status}"
2
- .step-title= step.name
3
- - if has_args_or_documents
4
- div.step-body
5
- == TurnipFormatter::Printer::StepExtraArgs.print_out(step.argument)
6
- == step_docs
@@ -1 +0,0 @@
1
- pre.multiline= lines
@@ -1,6 +0,0 @@
1
- table.step_outline
2
- - table.each do |tr|
3
- tr
4
- - tr.each do |td|
5
- td
6
- = td
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
- require 'turnip_formatter/printer/step_extra_args'
3
-
4
- module TurnipFormatter::Printer
5
- describe StepExtraArgs do
6
- context 'Turnip::Table' do
7
- describe '.print_out' do
8
- let(:string) do
9
- ::Turnip::Table.new([
10
- ["State", "Money"],
11
- ["<Tokushima>", "555"],
12
- ["<Okinawa>", "368"]
13
- ])
14
- end
15
-
16
- subject { StepExtraArgs.print_out(string) }
17
-
18
- it { should match %r{<td>State</td>[[:space:]]*<td>Money</td>} }
19
- it { should match %r{<td>&lt;Tokushima&gt;</td>[[:space:]]*<td>555</td>} }
20
- it { should match %r{<td>&lt;Okinawa&gt;</td>[[:space:]]*<td>368</td>} }
21
- end
22
- end
23
-
24
- context 'String' do
25
- describe '.print_out' do
26
- let(:string) { 'a<a>a' }
27
- subject { StepExtraArgs.print_out(string) }
28
- it { should match %r{<pre class="multiline">a&lt;a&gt;a</pre>} }
29
- end
30
- end
31
- end
32
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
- require 'turnip_formatter/printer/step'
3
-
4
- describe TurnipFormatter::Printer::Step do
5
- describe '.print_out' do
6
- subject { described_class.print_out(step) }
7
-
8
- context 'not has extra argument' do
9
- let(:step) do
10
- step = passed_step
11
- expect(step).to receive(:argument).and_return(nil)
12
- step
13
- end
14
-
15
- it {
16
- should match %r{<div class="step passed">}
17
- should match %r{<div class="step-title">}
18
- }
19
- end
20
-
21
- context 'has table argument' do
22
- let(:table) { Turnip::Table.new [] }
23
-
24
- let(:step) do
25
- step = passed_step
26
- allow(step).to receive(:argument).and_return(table)
27
- step
28
- end
29
-
30
- it {
31
- should match %r{<div class="step-body">}
32
- should match %r{<table class="step_outline">}
33
- }
34
- end
35
-
36
- context 'has outline argument' do
37
- let(:step) do
38
- step = passed_step
39
- allow(step).to receive(:argument).and_return('DocString')
40
- step
41
- end
42
-
43
- it {
44
- should match %r{<div class="step-body">}
45
- should match %r{<pre class="multiline">}
46
- }
47
- end
48
- end
49
- end