dots_formatter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +35 -0
- data/docs/all_passing.jpg +0 -0
- data/docs/with_failure.jpg +0 -0
- data/dots_formatter.gemspec +13 -0
- data/lib/dots_formatter/dots_formatter_rspec_2.rb +60 -0
- data/lib/dots_formatter/dots_formatter_rspec_3.rb +101 -0
- data/lib/dots_formatter.rb +10 -0
- metadata +53 -0
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Dots formatter
|
2
|
+
|
3
|
+
An RSpec formatter that has nothing to do with dots, honest.
|
4
|
+
|
5
|
+
Format your Rspec output simply, but informatively.
|
6
|
+
|
7
|
+
For example, running with guard, your RSpec output could look like
|
8
|
+
this:
|
9
|
+
|
10
|
+
![Passing](docs/all_passing.jpg))
|
11
|
+
|
12
|
+
Or get instance feedback when an example fails:
|
13
|
+
|
14
|
+
![Failing](docs/with_failure.jpg))
|
15
|
+
|
16
|
+
If you set debug mode to true then you can get each test on a new line
|
17
|
+
with the time taken for each test.
|
18
|
+
|
19
|
+
Currently only works with RSpec 3 and up.
|
20
|
+
|
21
|
+
To run, clone the repo then in either a project specific .rspec file or
|
22
|
+
in your home .rspec file, or directly on the command line:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
--require /path/to/dots_formatter/lib/dots_formmater.rb
|
26
|
+
--format DotsFormatter
|
27
|
+
```
|
28
|
+
|
29
|
+
## TODO
|
30
|
+
|
31
|
+
* Port RSpec 3 to RSpec 2
|
32
|
+
* Better Readme
|
33
|
+
* Gem-ify
|
34
|
+
* Debug as command line option
|
35
|
+
* Tests
|
Binary file
|
Binary file
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'dots_formatter'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2015-05-14'
|
5
|
+
s.summary = "A simple, informative RSpec formatter"
|
6
|
+
s.description = "Get instance feedback on number of passed:failed:pending / total with quick failure status"
|
7
|
+
s.authors = ["Paul Brennan"]
|
8
|
+
s.email = 'paul@dryule.com'
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
s.require_paths = ["lib"]
|
11
|
+
s.homepage = 'https://github.com/yule/dots_formatter'
|
12
|
+
s.license = 'MIT'
|
13
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'rspec/core/formatters/progress_formatter'
|
3
|
+
class Rspec2 < RSpec::Core::Formatters::BaseTextFormatter
|
4
|
+
|
5
|
+
def start(number)
|
6
|
+
super(number)
|
7
|
+
output.puts
|
8
|
+
end
|
9
|
+
|
10
|
+
def example_started(example)
|
11
|
+
super(example)
|
12
|
+
print_progress(example)
|
13
|
+
end
|
14
|
+
|
15
|
+
def example_passed(example)
|
16
|
+
super(example)
|
17
|
+
#print_progress
|
18
|
+
end
|
19
|
+
|
20
|
+
def example_failed(example)
|
21
|
+
super(example)
|
22
|
+
@failure_count += 1
|
23
|
+
print_progress(example)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def dump_summary(duration, example_count, failure_count, pending_count)
|
28
|
+
output.puts
|
29
|
+
output.puts
|
30
|
+
output.puts "Finished in #{format_duration duration}"
|
31
|
+
output.puts
|
32
|
+
if failure_count == 0
|
33
|
+
output.puts success_color("┌" + "--------------" + "-".ljust(20,"-") + "┐")
|
34
|
+
output.puts success_color("│" + " (^ヽ--△<^)" + " ".ljust(20) + "│")
|
35
|
+
output.puts success_color("│" + " / ~▽" + " ".ljust(20) + "│")
|
36
|
+
output.puts success_color("│" + "士 0 o 0 士" + " #{example_count} test#{example_count > 1? 's' : ' '}".ljust(20) + "│")
|
37
|
+
output.puts success_color("│" + " メ ___ メ " + " ".ljust(20) + "│")
|
38
|
+
output.puts success_color("│" + " / へ`-L、 " + " No failures.".ljust(20) + "│")
|
39
|
+
output.puts success_color("│" + " (~( し′| )" + " ".ljust(20) + "│")
|
40
|
+
output.puts success_color("└" + "--------------" + "-".ljust(20,"-") + "┘")
|
41
|
+
else
|
42
|
+
output.puts failure_color("┌" + "-".ljust(50,"-") + "┐")
|
43
|
+
output.puts failure_color("│ #{example_count} test#{example_count > 1? 's' : ' '}, #{failure_count} failure#{failure_count > 1? 's' : ' '}".ljust(50) + " │")
|
44
|
+
output.puts failure_color("└" + "-".ljust(50,"-") + "┘")
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def print_progress(example)
|
50
|
+
if @failure_count > 0
|
51
|
+
output.print failure_color("\r ● #{@examples.count - @failure_count}/#{@example_count}. #{@pending_count + '. pending.' if @pending_count > 0} #{example.full_description.ljust(150)}")
|
52
|
+
elsif @pending_count > 0
|
53
|
+
output.print pending_color("\r ● #{@examples.count - @failure_count}/#{@example_count}. #{@pending_count} pending #{example.full_description.ljust(150)}")
|
54
|
+
else
|
55
|
+
output.print success_color("\r ● #{@examples.count - @failure_count}/#{@example_count} #{example.full_description.ljust(150)}\r")
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
RSpec::Support.require_rspec_core "formatters/base_text_formatter"
|
3
|
+
module RSpec
|
4
|
+
module Core
|
5
|
+
module Formatters
|
6
|
+
|
7
|
+
class Dots < BaseTextFormatter
|
8
|
+
|
9
|
+
Formatters.register self, :example_passed, :example_pending, :example_started,
|
10
|
+
:example_failed, :start, :dump_failures
|
11
|
+
|
12
|
+
attr_accessor :passes, :fails, :runs, :pendings, :screen_width, :start_time, :example_start, :debug
|
13
|
+
|
14
|
+
def initialize(output)
|
15
|
+
@passes = 0
|
16
|
+
@fails = 0
|
17
|
+
@runs = 0
|
18
|
+
@pendings = 0
|
19
|
+
@screen_width = `tput cols`.to_i - 1
|
20
|
+
@debug = false
|
21
|
+
super(output)
|
22
|
+
end
|
23
|
+
|
24
|
+
def start(notification)
|
25
|
+
@start_time = Time.now
|
26
|
+
@example_count = notification.count
|
27
|
+
output.puts #new line
|
28
|
+
end
|
29
|
+
|
30
|
+
def example_started(example)
|
31
|
+
@example_start = Time.now
|
32
|
+
print_progress(example)
|
33
|
+
end
|
34
|
+
|
35
|
+
def example_pending(example)
|
36
|
+
@runs += 1
|
37
|
+
@pendings += 1
|
38
|
+
print_progress(example, true)
|
39
|
+
end
|
40
|
+
|
41
|
+
def example_passed(example)
|
42
|
+
@runs += 1
|
43
|
+
@passes += 1
|
44
|
+
print_progress(example, true)
|
45
|
+
end
|
46
|
+
|
47
|
+
def example_failed(example)
|
48
|
+
@fails += 1
|
49
|
+
@runs += 1
|
50
|
+
failure = ConsoleCodes.wrap("\r Failed example: ", :failure) +
|
51
|
+
ConsoleCodes.wrap(example.example.full_description, :white)
|
52
|
+
output.puts failure[0..@screen_width].ljust(@screen_width) unless @debug
|
53
|
+
print_progress(example, true)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def dump_summary(summary)
|
58
|
+
output.puts
|
59
|
+
output.puts
|
60
|
+
colour = (@fails == 0)? :success : :failure
|
61
|
+
|
62
|
+
output.puts ConsoleCodes.wrap("┌" + "-".ljust(50,"-") + "┐", colour)
|
63
|
+
output.puts ConsoleCodes.wrap("│ #{summary.example_count} test#{summary.example_count == 1? '' : 's'}".ljust(50) + " |", colour)
|
64
|
+
output.puts ConsoleCodes.wrap("| #{@fails} failure#{@fails == 1? '' : 's'}".ljust(50) + " |", colour)
|
65
|
+
output.puts ConsoleCodes.wrap("| Ran in #{Helpers.format_duration summary.duration}".ljust(50) + " |", colour)
|
66
|
+
output.puts ConsoleCodes.wrap("└" + "-".ljust(50,"-") + "┘", colour)
|
67
|
+
output.puts
|
68
|
+
output.puts summary.colorized_rerun_commands
|
69
|
+
end
|
70
|
+
|
71
|
+
def dump_failures(notification)
|
72
|
+
output.puts
|
73
|
+
output.puts notification.fully_formatted_failed_examples
|
74
|
+
end
|
75
|
+
|
76
|
+
def print_progress(example, finish = false)
|
77
|
+
|
78
|
+
tot = ConsoleCodes.wrap("#{@example_count}", :white)
|
79
|
+
fls = ConsoleCodes.wrap("#{fails}", :failure)
|
80
|
+
suc = ConsoleCodes.wrap("#{@runs - @fails}", :success)
|
81
|
+
png = ConsoleCodes.wrap("#{@pendings}", :pending)
|
82
|
+
current_dur = Time.now - @start_time
|
83
|
+
prev_dur = Time.now - @example_start
|
84
|
+
tim = ConsoleCodes.wrap( "(Running #{Helpers.format_duration current_dur})", :cyan)
|
85
|
+
dot = ConsoleCodes.wrap(" ● ", @fails == 0 ? :success : :failure)
|
86
|
+
|
87
|
+
if @debug
|
88
|
+
run = ConsoleCodes.wrap(" Just ran: #{example.example.description}, which took ", :cyan)
|
89
|
+
tim2 = ConsoleCodes.wrap(Helpers.format_duration(prev_dur), :red)
|
90
|
+
output.puts " #{dot}#{suc}:#{fls}:#{png}/#{tot}#{dot} #{run}#{tim2}" if finish
|
91
|
+
else
|
92
|
+
run = ConsoleCodes.wrap(" Now running: #{example.example.description}", :cyan) unless finish
|
93
|
+
all = "\r #{dot}#{suc}:#{fls}:#{png} / #{tot}#{dot} #{tim} #{run}".ljust(@screen_width)+"\r"
|
94
|
+
output.print all
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
if Gem::Version.new(RSpec::Core::Version::STRING).release >= Gem::Version.new('3.0.0')
|
4
|
+
require_relative './dots_formatter/dots_formatter_rspec_3'
|
5
|
+
DotsFormatter = RSpec::Core::Formatters::Dots
|
6
|
+
else
|
7
|
+
require_relative './dots_formmater/dots_formatter_rspec_2'
|
8
|
+
DotsFormatter = Rspec2
|
9
|
+
end
|
10
|
+
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dots_formatter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Paul Brennan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Get instance feedback on number of passed:failed:pending / total with
|
15
|
+
quick failure status
|
16
|
+
email: paul@dryule.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- README.md
|
22
|
+
- docs/all_passing.jpg
|
23
|
+
- docs/with_failure.jpg
|
24
|
+
- dots_formatter.gemspec
|
25
|
+
- lib/dots_formatter.rb
|
26
|
+
- lib/dots_formatter/dots_formatter_rspec_2.rb
|
27
|
+
- lib/dots_formatter/dots_formatter_rspec_3.rb
|
28
|
+
homepage: https://github.com/yule/dots_formatter
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.24
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: A simple, informative RSpec formatter
|
53
|
+
test_files: []
|