rspec_pretty 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rspec_pretty.gemspec
4
+ gemspec
@@ -0,0 +1,38 @@
1
+ # RSPEC_PRETTY
2
+
3
+ "RSpec Pretty" contains two formatters for cleaner and prettier rspec logs
4
+
5
+ There were two inspirations for this project
6
+
7
+ ### FROGGER
8
+ Frogger Gem for cucumber logs [https://github.com/evolve2k/frogger]
9
+
10
+ ### PRETTY_TEST_
11
+ Pretty Test for minitest [https://github.com/bobes/pretty_test]
12
+
13
+ ## SETUP
14
+
15
+ ### GEMFILE
16
+
17
+ In your Gemfile:
18
+
19
+ gem 'rspec_pretty', '~> 0.0.1'
20
+
21
+ ### SPEC_HELPER
22
+ In spec/spec_helper.rb:
23
+
24
+ config.formatters << Pretty::Logger.new
25
+
26
+ ### .rspec
27
+ In .rspec
28
+
29
+ --format Pretty::Formatter
30
+
31
+ ### Guardfile
32
+
33
+ guard 'rspec', :version => 2, :cli => '--colour --format Pretty::Formatter', ...
34
+
35
+
36
+
37
+ ----
38
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,94 @@
1
+ require 'rspec/core/formatters/base_formatter'
2
+
3
+ module Pretty
4
+ class Formatter < RSpec::Core::Formatters::BaseFormatter
5
+
6
+ PENDING_FORMAT = "\e[1m\e[37m%s\n\e[33m [PENDING] %s\e[0m"
7
+ PENDING_FORMAT_MSG = " \e[34m%s\e[0m"
8
+ PENDING_FORMAT_CALLER = " \e[34m# %s\e[0m"
9
+
10
+ FAILURE_FORMAT = "\e[1m\e[37m%s\n\e[31m\e[1m[FAILURE] %s\e[0m"
11
+ FAILURE_FORMAT_LINE = " \e[31m%s\e[0m"
12
+ FAILURE_FORMAT_BACK = " \e[36m# %s\e[0m"
13
+
14
+
15
+ STATUS_FORMAT = "\e[2K\r\e[?7l\e[1m\e[37m(%.1fs) \e[32m%d/%d tests\e[37m, \e[31m%d failures\e[37m, \e[33m%d pending \e[37m%s\e[?7h\e[0m"
16
+
17
+ def initialize(output = nil)
18
+ super(output)
19
+ @started_at = Time.now
20
+ @finished = 0
21
+ @failure = 0
22
+ @pending = 0
23
+ end
24
+
25
+ def example_group_finished(example_group)
26
+ update_status("")
27
+ end
28
+
29
+ def example_started(example)
30
+ update_status(example.full_description)
31
+ end
32
+
33
+ def example_passed(example)
34
+ @finished += 1
35
+ update_status(example.full_description)
36
+ end
37
+
38
+ def example_failed(example)
39
+ @finished += 1
40
+ @failure += 1
41
+ print_failure example
42
+ end
43
+
44
+ def example_pending(example)
45
+ @finished += 1
46
+ @pending += 1
47
+ print_pending example
48
+ end
49
+
50
+ protected
51
+
52
+ def print_failure(example)
53
+ remove_status
54
+
55
+ exception = example.execution_result[:exception]
56
+ description = example.full_description
57
+ path = RSpec::Core::Formatters::BaseFormatter::relative_path(example.location)
58
+
59
+ puts
60
+ puts FAILURE_FORMAT % [description, path]
61
+ puts FAILURE_FORMAT_LINE % [read_failed_line(exception, example).strip]
62
+ if exception.message
63
+ exception.message.split("\n").each do |line|
64
+ puts FAILURE_FORMAT_LINE % [line]
65
+ end
66
+ end
67
+ format_backtrace(example.execution_result[:exception].backtrace, example)[0 .. 1].each do |backtrace_info|
68
+ puts FAILURE_FORMAT_BACK % [backtrace_info]
69
+ end
70
+ end
71
+
72
+ def print_pending(example)
73
+ remove_status
74
+
75
+ description = example.full_description
76
+ path = RSpec::Core::Formatters::BaseFormatter::relative_path(example.location)
77
+ calller = backtrace_line(example.location.to_s.split(':in `block').first)
78
+
79
+ puts
80
+ puts PENDING_FORMAT % [description, path]
81
+ puts PENDING_FORMAT_MSG % [example.execution_result[:pending_message]]
82
+ puts PENDING_FORMAT_CALLER % [calller]
83
+ end
84
+
85
+
86
+ def update_status(message = "")
87
+ print STATUS_FORMAT % [Time.now - @started_at, @finished, example_count, @failure, @pending, message]
88
+ end
89
+
90
+ def remove_status
91
+ print "\e[2K\r"
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,54 @@
1
+ require 'rspec/core/formatters/base_formatter'
2
+
3
+ module Pretty
4
+ class Logger < RSpec::Core::Formatters::BaseFormatter
5
+
6
+ COLOR_START = "\e[34m" # blue
7
+ COLOR_FAILED = "\e[31m" # red
8
+ COLOR_PASSED = "\e[32m" # green
9
+ COLOR_PENDING = "\e[33m" # yellow
10
+
11
+ def initialize(output = nil)
12
+ super(output)
13
+ @group_level = 0
14
+ end
15
+
16
+ def example_group_started(example_group)
17
+ @group_level += 1
18
+ end
19
+
20
+ def example_group_finished(example_group)
21
+ @group_level -= 1
22
+ end
23
+
24
+ def example_started(example)
25
+ log(COLOR_START, "start", example)
26
+ end
27
+
28
+ def example_passed(example)
29
+ log(COLOR_PASSED, "passed", example)
30
+ end
31
+
32
+ def example_pending(example)
33
+ log(COLOR_PENDING, "pending", example)
34
+ end
35
+
36
+ def example_failed(example)
37
+ log(COLOR_FAILED, "failed", example)
38
+ end
39
+
40
+ protected
41
+ def current_indentation
42
+ '**' * @group_level
43
+ end
44
+
45
+ def log(color_code, action, example)
46
+ # for support of itslog
47
+ if Rails.logger.respond_to?(:namespace=)
48
+ Rails.logger.namespace = "pretty"
49
+ end
50
+
51
+ Rails.logger.info "#{color_code}#{current_indentation} #{action} : #{example.full_description}\e[0m"
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ require "rspec_pretty/version"
2
+
3
+ require "pretty/logger"
4
+ require "pretty/formatter"
5
+
@@ -0,0 +1,3 @@
1
+ module RSpecPretty
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rspec_pretty/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rspec_pretty"
7
+ s.version = RSpecPretty::VERSION
8
+ s.authors = ["Chris Douglas"]
9
+ s.email = ["dougo.chris@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Pretty RSpec}
12
+ s.description = %q{Pretty Formatter and Logger Formatter for RSpec}
13
+
14
+ s.rubyforge_project = "rspec_pretty"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rake"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_pretty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Douglas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-15 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70281114849220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70281114849220
25
+ description: Pretty Formatter and Logger Formatter for RSpec
26
+ email:
27
+ - dougo.chris@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - lib/pretty/formatter.rb
37
+ - lib/pretty/logger.rb
38
+ - lib/rspec_pretty.rb
39
+ - lib/rspec_pretty/version.rb
40
+ - rspec_pretty.gemspec
41
+ homepage: ''
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ segments:
54
+ - 0
55
+ hash: 3126477280433936121
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ segments:
63
+ - 0
64
+ hash: 3126477280433936121
65
+ requirements: []
66
+ rubyforge_project: rspec_pretty
67
+ rubygems_version: 1.8.10
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Pretty RSpec
71
+ test_files: []