rspec-axlsx-formatter 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -2
- data/lib/rspec/axlsx/formatter.rb +10 -12
- data/lib/rspec/axlsx/formatter/core.rb +167 -0
- data/lib/rspec/axlsx/formatter/version.rb +1 -1
- data/lib/rspec/axlsx/formatter_rspec2.rb +34 -0
- data/lib/rspec/axlsx/formatter_rspec3.rb +3 -171
- data/lib/rspec/axlsx/rake/rspec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bba59518d6e5ee9421165fd3a67b2877ad5b903
|
4
|
+
data.tar.gz: 9e62dbf5b2c980a695cd765445d045e7b8be3cf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43b18f85b51db674dcc98ce4576933131a84752d5802c43a252e36bf53457f4a21795e027badfe7cabeeb7069fe04ef2815e8f1a0e5f0b444ba84a59759172bc
|
7
|
+
data.tar.gz: 92c4a968577e60195dfece2f81b10be656de96639506b841884129338d05fb11bc0859e5dec7c4471a30347e8bd2b2fc8a70dfa1310c420ecf314ab3863c54c5
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Rspec::Axlsx::Formatter
|
2
2
|
|
3
|
-
|
3
|
+
"rspec-axlsx-formatter" is a [RSpec](http://github.com/rspec) custom formatter that uses [Axlsx](https://github.com/randym/axlsx) and generate xlsx file as spec result.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,23 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Require the follow in your Rakefile.
|
22
|
+
|
23
|
+
```
|
24
|
+
require 'rspec/axlsx/rake/rspec'
|
25
|
+
```
|
26
|
+
|
27
|
+
And, add `axlsx:setup:rspec` at rake command.
|
28
|
+
|
29
|
+
|
30
|
+
Example)
|
31
|
+
|
32
|
+
```
|
33
|
+
rake axlsx:setup:rspec spec
|
34
|
+
```
|
35
|
+
|
36
|
+
This usage is similar to ci_report_rspec.
|
37
|
+
(In actuality, I use ci_report_rspec as reference.)
|
22
38
|
|
23
39
|
## Contributing
|
24
40
|
|
@@ -27,3 +43,7 @@ TODO: Write usage instructions here
|
|
27
43
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
44
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
45
|
5. Create a new Pull Request
|
46
|
+
|
47
|
+
## Liscense
|
48
|
+
|
49
|
+
MIT
|
@@ -1,18 +1,16 @@
|
|
1
1
|
require "rspec/axlsx/formatter/version"
|
2
2
|
require "rspec/core"
|
3
|
-
#require "rspec/core/formatters/base_formatter"
|
4
3
|
|
5
4
|
module Rspec
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
RSPEC_3_AVAILABLE = rspec_version >= rspec_3
|
5
|
+
rspec_version = Gem::Version.new(::RSpec::Core::Version::STRING)
|
6
|
+
rspec_3 = Gem::Version.new('3.0.0')
|
7
|
+
RSPEC_3_AVAILABLE = rspec_version >= rspec_3
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
if RSPEC_3_AVAILABLE
|
10
|
+
require "rspec/axlsx/formatter_rspec3"
|
11
|
+
AxlsxFormatter = Rspec::Axlsx::FormatterRSpec3
|
12
|
+
else
|
13
|
+
require "rspec/axlsx/formatter_rspec2"
|
14
|
+
AxlsxFormatter = Rspec::Axlsx::FormatterRSpec2
|
15
|
+
end
|
18
16
|
end
|
@@ -1,9 +1,176 @@
|
|
1
1
|
require "axlsx"
|
2
|
+
require "axlsx/package"
|
2
3
|
|
3
4
|
module Rspec
|
4
5
|
module Axlsx
|
5
6
|
module Formatter
|
6
7
|
class Core
|
8
|
+
|
9
|
+
ALL_IN_ONE_SHEET = 0
|
10
|
+
|
11
|
+
def initialize()
|
12
|
+
@p = ::Axlsx::Package.new
|
13
|
+
@workbook = @p.workbook
|
14
|
+
@report_dir = ENV["XLSX_REPORT"] || "spec/xlsx"
|
15
|
+
|
16
|
+
@example_num = 0
|
17
|
+
|
18
|
+
#@describe_column = ["Expected"]
|
19
|
+
@describe_column = []
|
20
|
+
|
21
|
+
@sheet_mode = ALL_IN_ONE_SHEET
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_sheet(example_groups)
|
25
|
+
@example_groups = example_groups
|
26
|
+
convert_to_sheet do |worksheet|
|
27
|
+
end
|
28
|
+
@p.use_shared_strings = true
|
29
|
+
FileUtils.mkdir_p(@report_dir)
|
30
|
+
@p.serialize("#{@report_dir}/report.xlsx")
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def success?(example)
|
36
|
+
result = example.execution_result
|
37
|
+
return result[:status] == "passed" if result.kind_of?(Hash) # RSpec2
|
38
|
+
return result.status == :passed
|
39
|
+
end
|
40
|
+
|
41
|
+
def has_status?(example)
|
42
|
+
example.respond_to?(:execution_result)
|
43
|
+
end
|
44
|
+
|
45
|
+
def sheet_style(worksheet)
|
46
|
+
worksheet.column_widths(*[nil].concat(max_example_depth.times.map{5}))
|
47
|
+
#worksheet.column_widths(nil, 5, 5)
|
48
|
+
end
|
49
|
+
|
50
|
+
def sheet_header(worksheet)
|
51
|
+
worksheet.add_row do |row|
|
52
|
+
row.add_cell('No' , style: header_style)
|
53
|
+
row.add_cell('Test Case' , style: header_style)
|
54
|
+
max_example_depth.times{row.add_cell('', style: header_style)}
|
55
|
+
@describe_column.each do |c|
|
56
|
+
row.add_cell(c, style: header_style)
|
57
|
+
end
|
58
|
+
row.add_cell('Result' , style: header_style)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def convert_to_sheet
|
63
|
+
if @sheet_mode == ALL_IN_ONE_SHEET
|
64
|
+
@workbook.add_worksheet do |worksheet|
|
65
|
+
sheet_header(worksheet)
|
66
|
+
@example_groups.each do |example_group|
|
67
|
+
add_sheet_row(worksheet, example_group)
|
68
|
+
end
|
69
|
+
sheet_style(worksheet)
|
70
|
+
end
|
71
|
+
else
|
72
|
+
transepose =
|
73
|
+
@example_groups.inject({}) do |h, example_group|
|
74
|
+
h[example_group.example.file_path] ||= []
|
75
|
+
h[example_group.example.file_path].push(example_group)
|
76
|
+
h
|
77
|
+
end
|
78
|
+
transepose.each do |k, v|
|
79
|
+
@workbook.add_worksheet do |worksheet|
|
80
|
+
yield(worksheet)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def add_sheet_row(worksheet, example_group)
|
87
|
+
worksheet.add_row do |row|
|
88
|
+
if has_status?(example_group)
|
89
|
+
@example_num += 1
|
90
|
+
row.add_cell(@example_num, style: idx_column_style)
|
91
|
+
example_depth(example_group).times do
|
92
|
+
row.add_cell("", style: grey_style)
|
93
|
+
end
|
94
|
+
row.add_cell(example_group.description)
|
95
|
+
offset = max_example_depth - example_depth(example_group) + @describe_column.length
|
96
|
+
offset.times do
|
97
|
+
row.add_cell("")
|
98
|
+
end
|
99
|
+
if success?(example_group)
|
100
|
+
row.add_cell("T", style: success_style)
|
101
|
+
else
|
102
|
+
row.add_cell("F", style: failed_style)
|
103
|
+
end
|
104
|
+
else
|
105
|
+
row.add_cell("", style: pink_style)
|
106
|
+
example_depth(example_group).times do
|
107
|
+
row.add_cell("", style: grey_style)
|
108
|
+
end
|
109
|
+
row.add_cell(example_group.description)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def max_example_depth
|
115
|
+
@max_example_depth ||=
|
116
|
+
@example_groups.map{|e| example_depth(e)}.max
|
117
|
+
end
|
118
|
+
|
119
|
+
def example_depth(example)
|
120
|
+
if has_status?(example)
|
121
|
+
example.example_group.parent_groups.select{|p| p != example}.length
|
122
|
+
else
|
123
|
+
example.parent_groups.select{|p| p != example}.length
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def style_hash
|
128
|
+
{
|
129
|
+
header_style: {
|
130
|
+
bg_color: 'F4FA58',
|
131
|
+
b: true,
|
132
|
+
border: { style: :thin, color: '666666' },
|
133
|
+
},
|
134
|
+
idx_column_style: {
|
135
|
+
bg_color: 'FFDD99',
|
136
|
+
b: true,
|
137
|
+
border: { style: :thin, color: '666666', edges: [:right] },
|
138
|
+
},
|
139
|
+
test_case_style: {
|
140
|
+
},
|
141
|
+
success_style: {
|
142
|
+
bg_color: '58FA58',
|
143
|
+
},
|
144
|
+
failed_style: {
|
145
|
+
bg_color: 'FE2E2E',
|
146
|
+
},
|
147
|
+
grey_space_style: {
|
148
|
+
bg_color: 'CCCCCC',
|
149
|
+
},
|
150
|
+
pink_space_style: {
|
151
|
+
bg_color: '6CEEC',
|
152
|
+
},
|
153
|
+
}
|
154
|
+
end
|
155
|
+
|
156
|
+
def header_style
|
157
|
+
@header_style ||= @workbook.styles.add_style(style_hash[:header_style])
|
158
|
+
end
|
159
|
+
def pink_style
|
160
|
+
@pink_style ||= @workbook.styles.add_style(style_hash[:idx_column_style].merge(style_hash[:pink_space_style]))
|
161
|
+
end
|
162
|
+
def grey_style
|
163
|
+
@grey_style ||= @workbook.styles.add_style(style_hash[:grey_space_style])
|
164
|
+
end
|
165
|
+
def success_style
|
166
|
+
@success_style ||= @workbook.styles.add_style(style_hash[:success_style])
|
167
|
+
end
|
168
|
+
def failed_style
|
169
|
+
@failed_style ||= @workbook.styles.add_style(style_hash[:failed_style])
|
170
|
+
end
|
171
|
+
def idx_column_style
|
172
|
+
@idx_column_style ||= @workbook.styles.add_style(style_hash[:idx_column_style])
|
173
|
+
end
|
7
174
|
end
|
8
175
|
end
|
9
176
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "rspec/core/formatters/base_formatter"
|
2
|
+
require "rspec/axlsx/formatter/core"
|
3
|
+
|
4
|
+
module Rspec
|
5
|
+
module Axlsx
|
6
|
+
#class Formatter < ::RSpec::Core::Formatters::BaseFormatter
|
7
|
+
class FormatterRSpec2 < ::RSpec::Core::Formatters::BaseFormatter
|
8
|
+
|
9
|
+
def initialize(*)
|
10
|
+
super
|
11
|
+
@example_groups = []
|
12
|
+
@core = Rspec::Axlsx::Formatter::Core.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def example_group_started(example_group)
|
16
|
+
@example_groups.push(example_group)
|
17
|
+
end
|
18
|
+
|
19
|
+
def example_passed(example)
|
20
|
+
@example_groups.push(example)
|
21
|
+
end
|
22
|
+
|
23
|
+
def example_failed(example)
|
24
|
+
@example_groups.push(example)
|
25
|
+
end
|
26
|
+
|
27
|
+
def dump_summary(*args)
|
28
|
+
@core.to_sheet(@example_groups)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -1,46 +1,24 @@
|
|
1
1
|
require "rspec/core"
|
2
|
-
require "axlsx"
|
3
|
-
require "axlsx/package"
|
4
2
|
require "rspec/core/formatters/base_formatter"
|
5
3
|
require "rspec/axlsx/formatter/core"
|
6
4
|
|
7
|
-
require "pp"
|
8
|
-
|
9
5
|
module Rspec
|
10
6
|
module Axlsx
|
11
7
|
#class Formatter < ::RSpec::Core::Formatters::BaseFormatter
|
12
8
|
class FormatterRSpec3 < ::RSpec::Core::Formatters::BaseFormatter
|
13
9
|
::RSpec::Core::Formatters.register self,
|
14
|
-
:
|
10
|
+
:example_group_started, :stop,
|
15
11
|
:example_passed, :example_failed
|
16
12
|
|
17
|
-
ALL_IN_ONE_SHEET = 0
|
18
|
-
|
19
13
|
def initialize(*)
|
20
|
-
super ::Axlsx::Package.new
|
21
|
-
|
22
|
-
@workbook = output.workbook
|
23
14
|
@example_groups = []
|
24
|
-
@
|
25
|
-
|
26
|
-
@example_num = 0
|
27
|
-
|
28
|
-
#@describe_column = ["Expected"]
|
29
|
-
@describe_column = []
|
30
|
-
|
31
|
-
@sheet_mode = ALL_IN_ONE_SHEET
|
32
|
-
end
|
33
|
-
|
34
|
-
def start(notification)
|
15
|
+
@core = Rspec::Axlsx::Formatter::Core.new
|
35
16
|
end
|
36
17
|
|
37
18
|
def example_group_started(notification)
|
38
19
|
@example_groups.push(notification.group)
|
39
20
|
end
|
40
21
|
|
41
|
-
def example_group_finished(notification)
|
42
|
-
end
|
43
|
-
|
44
22
|
def example_passed(notification)
|
45
23
|
@example_groups.push(notification.example)
|
46
24
|
end
|
@@ -50,155 +28,9 @@ module Rspec
|
|
50
28
|
end
|
51
29
|
|
52
30
|
def stop(notification)
|
53
|
-
to_sheet
|
54
|
-
output.use_shared_strings = true
|
55
|
-
output.serialize("report.xlsx")
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def success?(example)
|
61
|
-
example.execution_result.status == :passed
|
62
|
-
end
|
63
|
-
|
64
|
-
def has_status?(example)
|
65
|
-
example.respond_to?(:execution_result)
|
66
|
-
end
|
67
|
-
|
68
|
-
def to_sheet
|
69
|
-
convert_to_sheet do |worksheet|
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def sheet_style(worksheet)
|
74
|
-
worksheet.column_widths(*[nil].concat(max_example_depth.times.map{5}))
|
75
|
-
#worksheet.column_widths(nil, 5, 5)
|
31
|
+
@core.to_sheet(@example_groups)
|
76
32
|
end
|
77
33
|
|
78
|
-
def sheet_header(worksheet)
|
79
|
-
worksheet.add_row do |row|
|
80
|
-
row.add_cell('No' , style: header_style)
|
81
|
-
row.add_cell('Test Case' , style: header_style)
|
82
|
-
max_example_depth.times{row.add_cell('', style: header_style)}
|
83
|
-
@describe_column.each do |c|
|
84
|
-
row.add_cell(c, style: header_style)
|
85
|
-
end
|
86
|
-
row.add_cell('Result' , style: header_style)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def convert_to_sheet
|
91
|
-
if @sheet_mode == ALL_IN_ONE_SHEET
|
92
|
-
@workbook.add_worksheet do |worksheet|
|
93
|
-
sheet_header(worksheet)
|
94
|
-
@example_groups.each do |example_group|
|
95
|
-
add_sheet_row(worksheet, example_group)
|
96
|
-
end
|
97
|
-
sheet_style(worksheet)
|
98
|
-
end
|
99
|
-
else
|
100
|
-
transepose =
|
101
|
-
@example_groups.inject({}) do |h, example_group|
|
102
|
-
h[example_group.example.file_path] ||= []
|
103
|
-
h[example_group.example.file_path].push(example_group)
|
104
|
-
h
|
105
|
-
end
|
106
|
-
transepose.each do |k, v|
|
107
|
-
@workbook.add_worksheet do |worksheet|
|
108
|
-
yield(worksheet)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def add_sheet_row(worksheet, example_group)
|
115
|
-
worksheet.add_row do |row|
|
116
|
-
if has_status?(example_group)
|
117
|
-
@example_num += 1
|
118
|
-
row.add_cell(@example_num, style: idx_column_style)
|
119
|
-
example_depth(example_group).times do
|
120
|
-
row.add_cell("", style: grey_style)
|
121
|
-
end
|
122
|
-
row.add_cell(example_group.description)
|
123
|
-
offset = max_example_depth - example_depth(example_group) + @describe_column.length
|
124
|
-
offset.times do
|
125
|
-
row.add_cell("")
|
126
|
-
end
|
127
|
-
if success?(example_group)
|
128
|
-
row.add_cell("T", style: success_style)
|
129
|
-
else
|
130
|
-
row.add_cell("F", style: failed_style)
|
131
|
-
end
|
132
|
-
else
|
133
|
-
row.add_cell("", style: pink_style)
|
134
|
-
example_depth(example_group).times do
|
135
|
-
row.add_cell("", style: grey_style)
|
136
|
-
end
|
137
|
-
row.add_cell(example_group.description)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def max_example_depth
|
143
|
-
@max_example_depth ||=
|
144
|
-
@example_groups.map{|e| example_depth(e)}.max
|
145
|
-
end
|
146
|
-
|
147
|
-
def example_depth(example)
|
148
|
-
if has_status?(example)
|
149
|
-
example.example_group.parent_groups.select{|p| p != example}.length
|
150
|
-
else
|
151
|
-
example.parent_groups.select{|p| p != example}.length
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def style_hash
|
156
|
-
{
|
157
|
-
header_style: {
|
158
|
-
bg_color: 'F4FA58',
|
159
|
-
b: true,
|
160
|
-
border: { style: :thin, color: '666666' },
|
161
|
-
},
|
162
|
-
idx_column_style: {
|
163
|
-
bg_color: 'FFDD99',
|
164
|
-
b: true,
|
165
|
-
border: { style: :thin, color: '666666', edges: [:right] },
|
166
|
-
},
|
167
|
-
test_case_style: {
|
168
|
-
},
|
169
|
-
success_style: {
|
170
|
-
bg_color: '58FA58',
|
171
|
-
},
|
172
|
-
failed_style: {
|
173
|
-
bg_color: 'FE2E2E',
|
174
|
-
},
|
175
|
-
grey_space_style: {
|
176
|
-
bg_color: 'CCCCCC',
|
177
|
-
},
|
178
|
-
pink_space_style: {
|
179
|
-
bg_color: '6CEEC',
|
180
|
-
},
|
181
|
-
}
|
182
|
-
end
|
183
|
-
|
184
|
-
def header_style
|
185
|
-
@header_style ||= @workbook.styles.add_style(style_hash[:header_style])
|
186
|
-
end
|
187
|
-
def pink_style
|
188
|
-
@pink_style ||= @workbook.styles.add_style(style_hash[:idx_column_style].merge(style_hash[:pink_space_style]))
|
189
|
-
end
|
190
|
-
def grey_style
|
191
|
-
@grey_style ||= @workbook.styles.add_style(style_hash[:grey_space_style])
|
192
|
-
end
|
193
|
-
def success_style
|
194
|
-
@success_style ||= @workbook.styles.add_style(style_hash[:success_style])
|
195
|
-
end
|
196
|
-
def failed_style
|
197
|
-
@failed_style ||= @workbook.styles.add_style(style_hash[:failed_style])
|
198
|
-
end
|
199
|
-
def idx_column_style
|
200
|
-
@idx_column_style ||= @workbook.styles.add_style(style_hash[:idx_column_style])
|
201
|
-
end
|
202
34
|
end
|
203
35
|
end
|
204
36
|
end
|
@@ -11,7 +11,7 @@ namespace :axlsx do
|
|
11
11
|
def setup_spec_opts(*extra_options)
|
12
12
|
base_opts = [
|
13
13
|
"--require", "#{File.dirname(__FILE__)}/rspec_loader.rb",
|
14
|
-
"--format", "Rspec::
|
14
|
+
"--format", "Rspec::AxlsxFormatter"
|
15
15
|
]
|
16
16
|
|
17
17
|
spec_opts = (base_opts + extra_options).join(" ")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-axlsx-formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yasuhiroki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: axlsx
|