better_errors-creditkudos 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.travis.yml +8 -0
  4. data/.yardopts +1 -0
  5. data/CHANGELOG.md +3 -0
  6. data/Gemfile +11 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +128 -0
  9. data/Rakefile +13 -0
  10. data/better_errors-creditkudos.gemspec +28 -0
  11. data/lib/better_errors.rb +152 -0
  12. data/lib/better_errors/code_formatter.rb +63 -0
  13. data/lib/better_errors/code_formatter/html.rb +26 -0
  14. data/lib/better_errors/code_formatter/text.rb +14 -0
  15. data/lib/better_errors/error_page.rb +129 -0
  16. data/lib/better_errors/exception_extension.rb +17 -0
  17. data/lib/better_errors/middleware.rb +141 -0
  18. data/lib/better_errors/rails.rb +28 -0
  19. data/lib/better_errors/raised_exception.rb +68 -0
  20. data/lib/better_errors/repl.rb +30 -0
  21. data/lib/better_errors/repl/basic.rb +20 -0
  22. data/lib/better_errors/repl/pry.rb +78 -0
  23. data/lib/better_errors/stack_frame.rb +111 -0
  24. data/lib/better_errors/templates/main.erb +1032 -0
  25. data/lib/better_errors/templates/text.erb +21 -0
  26. data/lib/better_errors/templates/variable_info.erb +72 -0
  27. data/lib/better_errors/version.rb +3 -0
  28. data/spec/better_errors/code_formatter_spec.rb +92 -0
  29. data/spec/better_errors/error_page_spec.rb +122 -0
  30. data/spec/better_errors/middleware_spec.rb +180 -0
  31. data/spec/better_errors/raised_exception_spec.rb +72 -0
  32. data/spec/better_errors/repl/basic_spec.rb +18 -0
  33. data/spec/better_errors/repl/pry_spec.rb +40 -0
  34. data/spec/better_errors/repl/shared_examples.rb +18 -0
  35. data/spec/better_errors/stack_frame_spec.rb +157 -0
  36. data/spec/better_errors/support/my_source.rb +20 -0
  37. data/spec/better_errors_spec.rb +73 -0
  38. data/spec/spec_helper.rb +5 -0
  39. data/spec/without_binding_of_caller.rb +9 -0
  40. metadata +136 -0
@@ -0,0 +1,72 @@
1
+ require "spec_helper"
2
+
3
+ module BetterErrors
4
+ describe RaisedException do
5
+ let(:exception) { RuntimeError.new("whoops") }
6
+ subject { RaisedException.new(exception) }
7
+
8
+ its(:exception) { should == exception }
9
+ its(:message) { should == "whoops" }
10
+ its(:type) { should == RuntimeError }
11
+
12
+ context "when the exception wraps another exception" do
13
+ let(:original_exception) { RuntimeError.new("something went wrong!") }
14
+ let(:exception) { double(:original_exception => original_exception) }
15
+
16
+ its(:exception) { should == original_exception }
17
+ its(:message) { should == "something went wrong!" }
18
+ end
19
+
20
+ context "when the exception is a syntax error" do
21
+ let(:exception) { SyntaxError.new("foo.rb:123: you made a typo!") }
22
+
23
+ its(:message) { should == "you made a typo!" }
24
+ its(:type) { should == SyntaxError }
25
+
26
+ it "has the right filename and line number in the backtrace" do
27
+ subject.backtrace.first.filename.should == "foo.rb"
28
+ subject.backtrace.first.line.should == 123
29
+ end
30
+ end
31
+
32
+ context "when the exception is a HAML syntax error" do
33
+ before do
34
+ stub_const("Haml::SyntaxError", Class.new(SyntaxError))
35
+ end
36
+
37
+ let(:exception) {
38
+ Haml::SyntaxError.new("you made a typo!").tap do |ex|
39
+ ex.set_backtrace(["foo.rb:123", "haml/internals/blah.rb:123456"])
40
+ end
41
+ }
42
+
43
+ its(:message) { should == "you made a typo!" }
44
+ its(:type) { should == Haml::SyntaxError }
45
+
46
+ it "has the right filename and line number in the backtrace" do
47
+ subject.backtrace.first.filename.should == "foo.rb"
48
+ subject.backtrace.first.line.should == 123
49
+ end
50
+ end
51
+
52
+ context "when the exception is a Coffeelint syntax error" do
53
+ before do
54
+ stub_const("Sprockets::Coffeelint::Error", Class.new(SyntaxError))
55
+ end
56
+
57
+ let(:exception) {
58
+ Sprockets::Coffeelint::Error.new("[stdin]:11:88: error: unexpected=").tap do |ex|
59
+ ex.set_backtrace(["app/assets/javascripts/files/index.coffee:11", "sprockets/coffeelint.rb:3"])
60
+ end
61
+ }
62
+
63
+ its(:message) { should == "[stdin]:11:88: error: unexpected=" }
64
+ its(:type) { should == Sprockets::Coffeelint::Error }
65
+
66
+ it "has the right filename and line number in the backtrace" do
67
+ subject.backtrace.first.filename.should == "app/assets/javascripts/files/index.coffee"
68
+ subject.backtrace.first.line.should == 11
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+ require "better_errors/repl/basic"
3
+ require "better_errors/repl/shared_examples"
4
+
5
+ module BetterErrors
6
+ module REPL
7
+ describe Basic do
8
+ let(:fresh_binding) {
9
+ local_a = 123
10
+ binding
11
+ }
12
+
13
+ let(:repl) { Basic.new fresh_binding }
14
+
15
+ it_behaves_like "a REPL provider"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+ require "pry"
3
+ require "better_errors/repl/pry"
4
+ require "better_errors/repl/shared_examples"
5
+
6
+ module BetterErrors
7
+ module REPL
8
+ describe Pry do
9
+ let(:fresh_binding) {
10
+ local_a = 123
11
+ binding
12
+ }
13
+
14
+ let(:repl) { Pry.new fresh_binding }
15
+
16
+ it "does line continuation" do
17
+ output, prompt, filled = repl.send_input ""
18
+ output.should == "=> nil\n"
19
+ prompt.should == ">>"
20
+ filled.should == ""
21
+
22
+ output, prompt, filled = repl.send_input "def f(x)"
23
+ output.should == ""
24
+ prompt.should == ".."
25
+ filled.should == " "
26
+
27
+ output, prompt, filled = repl.send_input "end"
28
+ if RUBY_VERSION >= "2.1.0"
29
+ output.should == "=> :f\n"
30
+ else
31
+ output.should == "=> nil\n"
32
+ end
33
+ prompt.should == ">>"
34
+ filled.should == ""
35
+ end
36
+
37
+ it_behaves_like "a REPL provider"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,18 @@
1
+ shared_examples_for "a REPL provider" do
2
+ it "evaluates ruby code in a given context" do
3
+ repl.send_input("local_a = 456")
4
+ fresh_binding.eval("local_a").should == 456
5
+ end
6
+
7
+ it "returns a tuple of output and the new prompt" do
8
+ output, prompt = repl.send_input("1 + 2")
9
+ output.should == "=> 3\n"
10
+ prompt.should == ">>"
11
+ end
12
+
13
+ it "doesn't barf if the code throws an exception" do
14
+ output, prompt = repl.send_input("raise Exception")
15
+ output.should include "Exception: Exception"
16
+ prompt.should == ">>"
17
+ end
18
+ end
@@ -0,0 +1,157 @@
1
+ require "spec_helper"
2
+
3
+ module BetterErrors
4
+ describe StackFrame do
5
+ context "#application?" do
6
+ it "is true for application filenames" do
7
+ BetterErrors.stub(:application_root).and_return("/abc/xyz")
8
+ frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index")
9
+
10
+ frame.should be_application
11
+ end
12
+
13
+ it "is false for everything else" do
14
+ BetterErrors.stub(:application_root).and_return("/abc/xyz")
15
+ frame = StackFrame.new("/abc/nope", 123, "foo")
16
+
17
+ frame.should_not be_application
18
+ end
19
+
20
+ it "doesn't care if no application_root is set" do
21
+ frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index")
22
+
23
+ frame.should_not be_application
24
+ end
25
+ end
26
+
27
+ context "#gem?" do
28
+ it "is true for gem filenames" do
29
+ Gem.stub(:path).and_return(["/abc/xyz"])
30
+ frame = StackFrame.new("/abc/xyz/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo")
31
+
32
+ frame.should be_gem
33
+ end
34
+
35
+ it "is false for everything else" do
36
+ Gem.stub(:path).and_return(["/abc/xyz"])
37
+ frame = StackFrame.new("/abc/nope", 123, "foo")
38
+
39
+ frame.should_not be_gem
40
+ end
41
+ end
42
+
43
+ context "#application_path" do
44
+ it "chops off the application root" do
45
+ BetterErrors.stub(:application_root).and_return("/abc/xyz")
46
+ frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index")
47
+
48
+ frame.application_path.should == "app/controllers/crap_controller.rb"
49
+ end
50
+ end
51
+
52
+ context "#gem_path" do
53
+ it "chops of the gem path and stick (gem) there" do
54
+ Gem.stub(:path).and_return(["/abc/xyz"])
55
+ frame = StackFrame.new("/abc/xyz/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo")
56
+
57
+ frame.gem_path.should == "whatever (1.2.3) lib/whatever.rb"
58
+ end
59
+
60
+ it "prioritizes gem path over application path" do
61
+ BetterErrors.stub(:application_root).and_return("/abc/xyz")
62
+ Gem.stub(:path).and_return(["/abc/xyz/vendor"])
63
+ frame = StackFrame.new("/abc/xyz/vendor/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo")
64
+
65
+ frame.gem_path.should == "whatever (1.2.3) lib/whatever.rb"
66
+ end
67
+ end
68
+
69
+ context "#pretty_path" do
70
+ it "returns #application_path for application paths" do
71
+ BetterErrors.stub(:application_root).and_return("/abc/xyz")
72
+ frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index")
73
+ frame.pretty_path.should == frame.application_path
74
+ end
75
+
76
+ it "returns #gem_path for gem paths" do
77
+ Gem.stub(:path).and_return(["/abc/xyz"])
78
+ frame = StackFrame.new("/abc/xyz/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo")
79
+
80
+ frame.pretty_path.should == frame.gem_path
81
+ end
82
+ end
83
+
84
+ it "special cases SyntaxErrors" do
85
+ begin
86
+ eval(%{ raise SyntaxError, "you wrote bad ruby!" }, nil, "my_file.rb", 123)
87
+ rescue SyntaxError => syntax_error
88
+ end
89
+ frames = StackFrame.from_exception(syntax_error)
90
+ frames.first.filename.should == "my_file.rb"
91
+ frames.first.line.should == 123
92
+ end
93
+
94
+ it "doesn't blow up if no method name is given" do
95
+ error = StandardError.allocate
96
+
97
+ error.stub(:backtrace).and_return(["foo.rb:123"])
98
+ frames = StackFrame.from_exception(error)
99
+ frames.first.filename.should == "foo.rb"
100
+ frames.first.line.should == 123
101
+
102
+ error.stub(:backtrace).and_return(["foo.rb:123: this is an error message"])
103
+ frames = StackFrame.from_exception(error)
104
+ frames.first.filename.should == "foo.rb"
105
+ frames.first.line.should == 123
106
+ end
107
+
108
+ it "ignores a backtrace line if its format doesn't make any sense at all" do
109
+ error = StandardError.allocate
110
+ error.stub(:backtrace).and_return(["foo.rb:123:in `foo'", "C:in `find'", "bar.rb:123:in `bar'"])
111
+ frames = StackFrame.from_exception(error)
112
+ frames.count.should == 2
113
+ end
114
+
115
+ it "doesn't blow up if a filename contains a colon" do
116
+ error = StandardError.allocate
117
+ error.stub(:backtrace).and_return(["crap:filename.rb:123"])
118
+ frames = StackFrame.from_exception(error)
119
+ frames.first.filename.should == "crap:filename.rb"
120
+ end
121
+
122
+ it "doesn't blow up with a BasicObject as frame binding" do
123
+ obj = BasicObject.new
124
+ def obj.my_binding
125
+ ::Kernel.binding
126
+ end
127
+ frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index", obj.my_binding)
128
+ frame.class_name.should == 'BasicObject'
129
+ end
130
+
131
+ it "sets method names properly" do
132
+ obj = "string"
133
+ def obj.my_method
134
+ begin
135
+ raise "foo"
136
+ rescue => err
137
+ err
138
+ end
139
+ end
140
+
141
+ frame = StackFrame.from_exception(obj.my_method).first
142
+ if BetterErrors.binding_of_caller_available?
143
+ frame.method_name.should == "#my_method"
144
+ frame.class_name.should == "String"
145
+ else
146
+ frame.method_name.should == "my_method"
147
+ frame.class_name.should == nil
148
+ end
149
+ end
150
+
151
+ if RUBY_ENGINE == "java"
152
+ it "doesn't blow up on a native Java exception" do
153
+ expect { StackFrame.from_exception(java.lang.Exception.new) }.to_not raise_error
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,20 @@
1
+ one
2
+ two
3
+ three
4
+ four
5
+ five
6
+ six
7
+ seven
8
+ eight
9
+ nine
10
+ ten
11
+ eleven
12
+ twelve
13
+ thirteen
14
+ fourteen
15
+ fifteen
16
+ sixteen
17
+ seventeen
18
+ eighteen
19
+ nineteen
20
+ twenty
@@ -0,0 +1,73 @@
1
+ require "spec_helper"
2
+
3
+ describe BetterErrors do
4
+ context ".editor" do
5
+ it "defaults to textmate" do
6
+ subject.editor["foo.rb", 123].should == "txmt://open?url=file://foo.rb&line=123"
7
+ end
8
+
9
+ it "url escapes the filename" do
10
+ subject.editor["&.rb", 0].should == "txmt://open?url=file://%26.rb&line=0"
11
+ end
12
+
13
+ [:emacs, :emacsclient].each do |editor|
14
+ it "uses emacs:// scheme when set to #{editor.inspect}" do
15
+ subject.editor = editor
16
+ subject.editor[].should start_with "emacs://"
17
+ end
18
+ end
19
+
20
+ [:macvim, :mvim].each do |editor|
21
+ it "uses mvim:// scheme when set to #{editor.inspect}" do
22
+ subject.editor = editor
23
+ subject.editor[].should start_with "mvim://"
24
+ end
25
+ end
26
+
27
+ [:sublime, :subl, :st].each do |editor|
28
+ it "uses subl:// scheme when set to #{editor.inspect}" do
29
+ subject.editor = editor
30
+ subject.editor[].should start_with "subl://"
31
+ end
32
+ end
33
+
34
+ [:textmate, :txmt, :tm].each do |editor|
35
+ it "uses txmt:// scheme when set to #{editor.inspect}" do
36
+ subject.editor = editor
37
+ subject.editor[].should start_with "txmt://"
38
+ end
39
+ end
40
+
41
+ ["emacsclient", "/usr/local/bin/emacsclient"].each do |editor|
42
+ it "uses emacs:// scheme when EDITOR=#{editor}" do
43
+ ENV["EDITOR"] = editor
44
+ subject.editor = subject.default_editor
45
+ subject.editor[].should start_with "emacs://"
46
+ end
47
+ end
48
+
49
+ ["mvim -f", "/usr/local/bin/mvim -f"].each do |editor|
50
+ it "uses mvim:// scheme when EDITOR=#{editor}" do
51
+ ENV["EDITOR"] = editor
52
+ subject.editor = subject.default_editor
53
+ subject.editor[].should start_with "mvim://"
54
+ end
55
+ end
56
+
57
+ ["subl -w", "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl"].each do |editor|
58
+ it "uses subl:// scheme when EDITOR=#{editor}" do
59
+ ENV["EDITOR"] = editor
60
+ subject.editor = subject.default_editor
61
+ subject.editor[].should start_with "subl://"
62
+ end
63
+ end
64
+
65
+ ["mate -w", "/usr/bin/mate -w"].each do |editor|
66
+ it "uses txmt:// scheme when EDITOR=#{editor}" do
67
+ ENV["EDITOR"] = editor
68
+ subject.editor = subject.default_editor
69
+ subject.editor[].should start_with "txmt://"
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,5 @@
1
+ $: << File.expand_path("../../lib", __FILE__)
2
+
3
+ ENV["EDITOR"] = nil
4
+
5
+ require "better_errors"
@@ -0,0 +1,9 @@
1
+ module Kernel
2
+ alias_method :require_with_binding_of_caller, :require
3
+
4
+ def require(feature)
5
+ raise LoadError if feature == "binding_of_caller"
6
+
7
+ require_with_binding_of_caller(feature)
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: better_errors-creditkudos
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Charlie Somerville
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: erubis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.6.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.6.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: coderay
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.0
55
+ description: Temporary fork of better_errors with some performance improvements.
56
+ email:
57
+ - charlie@charliesomerville.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - ".yardopts"
65
+ - CHANGELOG.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - better_errors-creditkudos.gemspec
71
+ - lib/better_errors.rb
72
+ - lib/better_errors/code_formatter.rb
73
+ - lib/better_errors/code_formatter/html.rb
74
+ - lib/better_errors/code_formatter/text.rb
75
+ - lib/better_errors/error_page.rb
76
+ - lib/better_errors/exception_extension.rb
77
+ - lib/better_errors/middleware.rb
78
+ - lib/better_errors/rails.rb
79
+ - lib/better_errors/raised_exception.rb
80
+ - lib/better_errors/repl.rb
81
+ - lib/better_errors/repl/basic.rb
82
+ - lib/better_errors/repl/pry.rb
83
+ - lib/better_errors/stack_frame.rb
84
+ - lib/better_errors/templates/main.erb
85
+ - lib/better_errors/templates/text.erb
86
+ - lib/better_errors/templates/variable_info.erb
87
+ - lib/better_errors/version.rb
88
+ - spec/better_errors/code_formatter_spec.rb
89
+ - spec/better_errors/error_page_spec.rb
90
+ - spec/better_errors/middleware_spec.rb
91
+ - spec/better_errors/raised_exception_spec.rb
92
+ - spec/better_errors/repl/basic_spec.rb
93
+ - spec/better_errors/repl/pry_spec.rb
94
+ - spec/better_errors/repl/shared_examples.rb
95
+ - spec/better_errors/stack_frame_spec.rb
96
+ - spec/better_errors/support/my_source.rb
97
+ - spec/better_errors_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/without_binding_of_caller.rb
100
+ homepage: https://github.com/creditkudos/better_errors
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 2.0.0
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.5.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Temporary fork of better_errors with some performance improvements.
124
+ test_files:
125
+ - spec/better_errors/code_formatter_spec.rb
126
+ - spec/better_errors/error_page_spec.rb
127
+ - spec/better_errors/middleware_spec.rb
128
+ - spec/better_errors/raised_exception_spec.rb
129
+ - spec/better_errors/repl/basic_spec.rb
130
+ - spec/better_errors/repl/pry_spec.rb
131
+ - spec/better_errors/repl/shared_examples.rb
132
+ - spec/better_errors/stack_frame_spec.rb
133
+ - spec/better_errors/support/my_source.rb
134
+ - spec/better_errors_spec.rb
135
+ - spec/spec_helper.rb
136
+ - spec/without_binding_of_caller.rb