colorful-exceptions 0.1.20170811

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2cd34a53c890e8926d3e5678a71a974f3910bcf0
4
+ data.tar.gz: ac7b8ae06e391a4f1855f40b80dd2eb6ef572a9a
5
+ SHA512:
6
+ metadata.gz: 75b58386ee32e37e6c731e409c315047367279cb5dddf610e8048115a9ea93be5f39afa2bc7225d4575504ea783e90ae0bf9703fd76ee63ef615e789546d1d82
7
+ data.tar.gz: c73c4d5e7cf4271c39b5d5d5729c5bdb9a14ad80b3a2e2827d73919ae4e3bc1172dfc6d87491a79a58aca63c1d82c8e21b4d21fb7b3b36780e0013b81d125510
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1 @@
1
+ If you want your stacktraces to be colorful add `colorful-exceptions` to your `Gemfile`.
@@ -0,0 +1,23 @@
1
+ task "default" => "spec"
2
+ task "test" => "spec"
3
+
4
+ desc "Run tests"
5
+ task "spec" do
6
+ system "rspec"
7
+ end
8
+
9
+ desc "Clean up"
10
+ task "clean" do
11
+ system "trash colorful-exceptions-*.gem"
12
+ end
13
+
14
+ desc "Build gem"
15
+ task "gem:build" do
16
+ system "gem build colorful-exceptions.gemspec"
17
+ end
18
+
19
+ desc "Upload gem"
20
+ task "gem:push" => "gem:build" do
21
+ gem_file = Dir["colorful-exceptions-*.gem"][-1] or raise "No gem found"
22
+ system "gem", "push", gem_file
23
+ end
@@ -0,0 +1,27 @@
1
+ module ColorfulExceptions
2
+ def backtrace
3
+ value = super
4
+ if value
5
+ green = "\e[#{32}m"
6
+ cyan = "\e[#{36}m"
7
+ clear = "\e[0m"
8
+ value.map do |msg|
9
+ case msg
10
+ when %r[\A(.*?):(\d+):in `(.*)'\z]
11
+ "#{green}#{$1}#{clear}:#{green}#{$2}#{clear}: in `#{cyan}#{$3}#{clear}'"
12
+ # Never seen them, but documentation insists they exist
13
+ when %r[\A(.*?):(\d+)]
14
+ "#{green}#{$1}#{clear}:#{green}#{$2}#{clear}"
15
+ else
16
+ "#{green}#{msg}#{clear}"
17
+ end
18
+ end
19
+ else
20
+ value
21
+ end
22
+ end
23
+ end
24
+
25
+ class Exception
26
+ prepend ColorfulExceptions
27
+ end
@@ -0,0 +1,45 @@
1
+ describe ColorfulExceptions do
2
+ let(:g) { "\e[#{32}m" }
3
+ let(:c) { "\e[#{36}m" }
4
+ let(:e) { "\e[0m" }
5
+
6
+ it "prints colorful exceptions" do
7
+ exception = (eval("1.times{\n1/0\n}", nil, "/lib/test.rb", 1) rescue $!)
8
+ expect(exception.backtrace[0]).to eq(
9
+ "#{g}/lib/test.rb#{e}:#{g}2#{e}: in `#{c}/#{e}'"
10
+ )
11
+ expect(exception.backtrace[1]).to eq(
12
+ "#{g}/lib/test.rb#{e}:#{g}2#{e}: in `#{c}block (3 levels) in <top (required)>#{e}'"
13
+ )
14
+ expect(exception.backtrace[2]).to eq(
15
+ "#{g}/lib/test.rb#{e}:#{g}1#{e}: in `#{c}times#{e}'"
16
+ )
17
+ expect(exception.backtrace[3]).to eq(
18
+ "#{g}/lib/test.rb#{e}:#{g}1#{e}: in `#{c}block (2 levels) in <top (required)>#{e}'"
19
+ )
20
+ end
21
+
22
+ it "nil backtrace" do
23
+ exception = RuntimeError.new("fail")
24
+ expect(exception.backtrace).to eq(nil)
25
+ end
26
+
27
+ it "weird backtrace still mostly works" do
28
+ exception = RuntimeError.new("fail")
29
+ exception.set_backtrace([
30
+ "/lib/foo.rb:1: in `times'",
31
+ "/lib/bar.rb:2",
32
+ "somewhere",
33
+ ])
34
+ # What set_backtraace is doing exactly...
35
+ expect(exception.backtrace[0]).to eq(
36
+ "#{g}/lib/foo.rb#{e}:#{g}1#{e}"
37
+ )
38
+ expect(exception.backtrace[1]).to eq(
39
+ "#{g}/lib/bar.rb#{e}:#{g}2#{e}"
40
+ )
41
+ expect(exception.backtrace[2]).to eq(
42
+ "#{g}somewhere#{e}"
43
+ )
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ require_relative "../lib/colorful-exceptions"
2
+
3
+ RSpec.configure do |config|
4
+ config.define_derived_metadata do |meta|
5
+ meta[:aggregate_failures] = true
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colorful-exceptions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.20170811
5
+ platform: ruby
6
+ authors:
7
+ - Tomasz Wegrzanowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Recolors exception backtraces. Compatible with most software.
42
+ email: Tomasz.Wegrzanowski@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".rspec"
48
+ - README.md
49
+ - Rakefile
50
+ - lib/colorful-exceptions.rb
51
+ - spec/colorful-exceptions_spec.rb
52
+ - spec/spec_helper.rb
53
+ homepage: https://github.com/taw/colorful-exceptions
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.5.2
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Colorful exception backtraces
77
+ test_files: []