rspec_yah_formatter 0.0.5 → 0.0.6

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: 1a7bad1267c438124ef01fd2825113cea0a8deaa
4
- data.tar.gz: 8dd20d5b5dd1eb7642fc9b04ab146c48bf44bb5a
3
+ metadata.gz: 78aa4ce207ac8c86257815cb0c464d5f3e0a5cd4
4
+ data.tar.gz: d00e505e3a4f237a1dfed353a2f26de528b51d94
5
5
  SHA512:
6
- metadata.gz: 021cd492d0e39a275e2b53232d143b58ba79cf391a6bdf8d9faf2eea10fbdff6592c97bcdb348c7e3527eb46d6b3882eeb72b2c6cecfc5ca6093a422a6d527c0
7
- data.tar.gz: a67c55a7478b6bd70aad82c57d2739f7324c929e2b17bd883835a15506deb1313bd0764eb58e9154cf010f04f979d330d84a05ce495fe0e172d1c5a04aa16b66
6
+ metadata.gz: dce7ebe550470f383d37fd55ecbfe7ba60ac1c41fc8df76f1912da57cc5833cf8667068638389f57ed820c670e0b2dccaf07c6313577a9f81e9d57860dc5009b
7
+ data.tar.gz: 6be13527a162f06244ae1975ded4481623ae173ee9ed95eca2c2704eb784f32a5dc3f52705c7c2cfa0233acd584c32adae968910bcef7fa071614886c953d719
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
data/lib/example.rb CHANGED
@@ -1,23 +1,21 @@
1
1
 
2
2
  require 'oopsy'
3
+ require 'pathname'
3
4
 
4
5
  class Example
5
6
 
6
7
  attr_reader :description, :full_description, :run_time, :duration, :status,
7
- :exception, :file_path, :metadata, :spec, :screenshot
8
+ :exception, :file_path, :metadata, :spec
8
9
 
9
- def initialize(example)
10
+ def initialize(example, report_folder)
10
11
  @description = example.description
11
12
  @full_description = example.full_description
12
13
  @execution_result = example.execution_result
13
- @run_time = (@execution_result.run_time).round(5)
14
- @duration = @execution_result.run_time.to_s(:rounded, precision: 5)
15
- @status = @execution_result.status.to_s
16
14
  @metadata = example.metadata
17
15
  @file_path = @metadata[:file_path]
18
16
  @exception = Oopsy.new(example.exception, @file_path)
19
- @screenshot = screenshot_path
20
17
  @spec = nil
18
+ @report_folder = report_folder
21
19
  end
22
20
 
23
21
  def has_exception?
@@ -34,15 +32,28 @@ class Example
34
32
 
35
33
  def klass(prefix = 'label-')
36
34
  class_map = { passed: "#{prefix}success", failed: "#{prefix}danger", pending: "#{prefix}warning" }
37
- class_map[@status.to_sym]
35
+ class_map[status.to_sym]
38
36
  end
39
37
 
40
- private
38
+ def screenshot
39
+ return nil unless @metadata[:screenshot]
41
40
 
42
- def screenshot_path
43
- filename = File.basename(@metadata[:file_path])
44
- line_number = @metadata[:line_number]
45
- default_path = "#{filename}-#{line_number}.png"
46
- File.exist?(default_path) ? default_path : @metadata[:screenshot]
41
+ unless File.exist?(@metadata[:screenshot])
42
+ puts "The screenshot '#{@metadata[:screenshot]}' does not exist"
43
+ end
44
+
45
+ path = Pathname.new(File.dirname(@report_folder))
46
+ Pathname.new(@metadata[:screenshot]).relative_path_from(path).to_s
47
+ end
48
+
49
+ def run_time
50
+ (@execution_result.run_time).round(5)
51
+ end
52
+
53
+ def duration
54
+ @execution_result.run_time.to_s(:rounded, precision: 5)
55
+ end
56
+ def status
57
+ @execution_result.status.to_s
47
58
  end
48
59
  end
@@ -10,43 +10,45 @@ require 'example'
10
10
 
11
11
  I18n.enforce_available_locales = false
12
12
 
13
+ # Formatter that builds a pretty html report, and includes a screenshot if it
14
+ # is included in the example metadata.
13
15
  class RspecYahFormatter < RSpec::Core::Formatters::BaseFormatter
14
16
  RSpec::Core::Formatters.register self, :example_passed, :example_failed,
15
17
  :example_pending
16
18
 
17
- def initialize(io_standard_output)
19
+ def initialize(out_file)
18
20
  @examples = []
19
21
  @passed = 0
20
22
  @failed = 0
21
23
  @pending = 0
22
- unless io_standard_output.is_a?(File)
23
- raise 'You should specify a file with the --out option, STDOUT cannot be used with this formatter'
24
+ if !out_file.is_a?(File)
25
+ raise 'You should specify a html file with the --out option, STDOUT cannot be used with this formatter'
24
26
  end
25
- @io_standard_output = io_standard_output
26
- copy_resources
27
+ @out_file = out_file
27
28
  end
28
29
 
29
30
  def example_passed(notification)
30
31
  @passed += 1
31
- @examples << Example.new(notification.example)
32
+ @examples << Example.new(notification.example, @out_file)
32
33
  end
33
34
 
34
35
  def example_failed(notification)
35
36
  @failed += 1
36
- @examples << Example.new(notification.example)
37
+ @examples << Example.new(notification.example, @out_file)
37
38
  end
38
39
 
39
40
  def example_pending(notification)
40
41
  @pending += 1
41
- @examples << Example.new(notification.example)
42
+ @examples << Example.new(notification.example, @out_file)
42
43
  end
43
44
 
44
- def close(notification)
45
+ def close(_notification)
45
46
  calculate_durations
46
- File.open(@io_standard_output, 'w') do |f|
47
+ File.open(@out_file, 'w') do |file|
47
48
  template_file = File.read(File.dirname(__FILE__) + '/../templates/report.erb')
48
- f.puts ERB.new(template_file).result(binding)
49
+ file.puts ERB.new(template_file).result(binding)
49
50
  end
51
+ copy_resources
50
52
  end
51
53
 
52
54
  private
@@ -58,10 +60,11 @@ class RspecYahFormatter < RSpec::Core::Formatters::BaseFormatter
58
60
  duration_values << duration_values.first if duration_values.size == 1
59
61
 
60
62
  @durations = duration_values.each_with_index.map { |e, i| [i, e] }
61
- @summary_duration = duration_values.inject(:+).to_s(:rounded, precision: 5)
63
+ @summary_duration = duration_values.inject(:+).to_f.to_s(:rounded, precision: 5)
62
64
  end
63
65
 
66
+ # Copies resources to the same folder where the report will be saved
64
67
  def copy_resources
65
- FileUtils.cp_r(File.dirname(__FILE__) + '/../resources', File.dirname(@io_standard_output))
68
+ FileUtils.cp_r(File.dirname(__FILE__) + '/../resources', File.dirname(@out_file))
66
69
  end
67
70
  end
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: rspec_yah_formatter 0.0.5 ruby lib
5
+ # stub: rspec_yah_formatter 0.0.6 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "rspec_yah_formatter"
9
- s.version = "0.0.5"
9
+ s.version = "0.0.6"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Kingsley Hendrickse", "David Garcia"]
14
- s.date = "2016-02-15"
14
+ s.date = "2016-02-29"
15
15
  s.description = "Rspec html formatter to generate pretty results with images"
16
16
  s.email = "david.garcia.mora@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
43
43
  "rspec_yah_formatter.gemspec",
44
44
  "spec/penders_spec.rb",
45
45
  "spec/rspec_html_formatter_spec.rb",
46
+ "spec/something.png",
46
47
  "spec/test2_spec.rb",
47
48
  "templates/report.erb"
48
49
  ]
Binary file
data/spec/test2_spec.rb CHANGED
@@ -1,8 +1,24 @@
1
1
  require 'rspec'
2
- # require_relative '../lib/rspec_html_formatter'
3
2
 
4
- describe 'The second Test' do
3
+ def fake_screenshot(metadata)
4
+ filename = File.basename(metadata[:file_path])
5
+ line_number = metadata[:line_number]
6
+ FileUtils.mkdir 'screenshots' unless File.exist? 'screenshots'
7
+ screenshot_name = "screenshots/#{filename}-#{line_number}.png"
8
+ FileUtils.cp(File.join(__dir__, 'something.png'), screenshot_name)
9
+ screenshot_name
10
+ end
11
+
12
+ RSpec.configure do |config|
13
+ config.after(:each) do |example|
14
+ if example.exception
15
+ screenshot_name = fake_screenshot(example.metadata)
16
+ example.metadata[:screenshot] = screenshot_name
17
+ end
18
+ end
19
+ end
5
20
 
21
+ describe 'The second Test' do
6
22
  it 'should do cool test stuff' do
7
23
  pending('coming soon')
8
24
  fail
@@ -13,26 +29,17 @@ describe 'The second Test' do
13
29
  end
14
30
 
15
31
  it 'should do superb test stuff' do
16
- #-> Given there are some ships
17
- #-> When I sail one
18
- #-> Then it should go fast
19
32
  expect('ships').to eq 'ships'
20
33
  end
21
34
 
22
35
  it 'should do example stuff' do
23
36
  expect('apple').to eq 'apple'
24
37
  expect('pear').to eq 1
25
- #-> Given I have some stuff to do
26
- #-> And I like to do is wait here for a while
27
- #-> Then I do it real good!!
28
38
  end
29
39
 
30
40
  it 'should do very cool test stuff' do
31
- #-> Given I have some cars
32
41
  expect('cars').to eq 'cars'
33
- #-> And I drive one of them
34
42
  expect('diesel').to eq 'diesels'
35
- #-> Then I should go fast
36
43
  expect('apple').to eq 'apple'
37
44
  end
38
45
 
@@ -45,14 +52,11 @@ describe 'The second Test' do
45
52
  end
46
53
 
47
54
  it 'should do very rawesome test stuff' do
48
- #-> Given I have some cars
49
55
  pending('give me a woop')
50
56
  fail
51
57
  end
52
58
 
53
59
  it 'should do insane and cool test stuff' do
54
60
  expect('ships').to eq 'ships'
55
- end
56
-
57
-
61
+ end
58
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_yah_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kingsley Hendrickse
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-15 00:00:00.000000000 Z
12
+ date: 2016-02-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-core
@@ -141,6 +141,7 @@ files:
141
141
  - rspec_yah_formatter.gemspec
142
142
  - spec/penders_spec.rb
143
143
  - spec/rspec_html_formatter_spec.rb
144
+ - spec/something.png
144
145
  - spec/test2_spec.rb
145
146
  - templates/report.erb
146
147
  homepage: http://github.com/dgmora/rspec_yah_formatter