better_errors 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of better_errors might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +19 -51
- data/better_errors.gemspec +5 -3
- data/lib/better_errors.rb +1 -1
- data/lib/better_errors/error_page.rb +16 -9
- data/lib/better_errors/middleware.rb +30 -3
- data/lib/better_errors/repl.rb +3 -1
- data/lib/better_errors/repl/basic.rb +1 -1
- data/lib/better_errors/repl/pry.rb +11 -1
- data/lib/better_errors/stack_frame.rb +7 -0
- data/lib/better_errors/templates/main.erb +7 -4
- data/lib/better_errors/version.rb +1 -1
- metadata +6 -40
- data/Rakefile +0 -13
- data/feature-screenshots/1-application-error.jpg +0 -0
- data/feature-screenshots/2-other-application-frame.jpg +0 -0
- data/feature-screenshots/3-live-shell.jpg +0 -0
- data/feature-screenshots/4-other-frames.jpg +0 -0
- data/feature-screenshots/5-open-editor.jpg +0 -0
- data/feature-screenshots/6-local-variables.jpg +0 -0
- data/feature-screenshots/7-non-html-requests.jpg +0 -0
- data/feature-screenshots/8-xhr-shows-text-error.jpg +0 -0
- data/feature-screenshots/9-xhr-error-in-manual-console.jpg +0 -0
- data/spec/better_errors/code_formatter_spec.rb +0 -92
- data/spec/better_errors/error_page_spec.rb +0 -92
- data/spec/better_errors/middleware_spec.rb +0 -188
- data/spec/better_errors/raised_exception_spec.rb +0 -73
- data/spec/better_errors/repl/basic_spec.rb +0 -18
- data/spec/better_errors/repl/pry_spec.rb +0 -40
- data/spec/better_errors/repl/shared_examples.rb +0 -18
- data/spec/better_errors/stack_frame_spec.rb +0 -157
- data/spec/better_errors/support/my_source.rb +0 -20
- data/spec/better_errors_spec.rb +0 -73
- data/spec/spec_helper.rb +0 -5
- data/spec/without_binding_of_caller.rb +0 -9
@@ -1,18 +0,0 @@
|
|
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
|
@@ -1,40 +0,0 @@
|
|
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
|
-
expect(output).to eq("=> nil\n")
|
19
|
-
expect(prompt).to eq(">>")
|
20
|
-
expect(filled).to eq("")
|
21
|
-
|
22
|
-
output, prompt, filled = repl.send_input "def f(x)"
|
23
|
-
expect(output).to eq("")
|
24
|
-
expect(prompt).to eq("..")
|
25
|
-
expect(filled).to eq(" ")
|
26
|
-
|
27
|
-
output, prompt, filled = repl.send_input "end"
|
28
|
-
if RUBY_VERSION >= "2.1.0"
|
29
|
-
expect(output).to eq("=> :f\n")
|
30
|
-
else
|
31
|
-
expect(output).to eq("=> nil\n")
|
32
|
-
end
|
33
|
-
expect(prompt).to eq(">>")
|
34
|
-
expect(filled).to eq("")
|
35
|
-
end
|
36
|
-
|
37
|
-
it_behaves_like "a REPL provider"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,18 +0,0 @@
|
|
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
|
-
expect(fresh_binding.eval("local_a")).to eq(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
|
-
expect(output).to eq("=> 3\n")
|
10
|
-
expect(prompt).to eq(">>")
|
11
|
-
end
|
12
|
-
|
13
|
-
it "doesn't barf if the code throws an exception" do
|
14
|
-
output, prompt = repl.send_input("raise Exception")
|
15
|
-
expect(output).to include "Exception: Exception"
|
16
|
-
expect(prompt).to eq(">>")
|
17
|
-
end
|
18
|
-
end
|
@@ -1,157 +0,0 @@
|
|
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
|
-
allow(BetterErrors).to receive(:application_root).and_return("/abc/xyz")
|
8
|
-
frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index")
|
9
|
-
|
10
|
-
expect(frame).to be_application
|
11
|
-
end
|
12
|
-
|
13
|
-
it "is false for everything else" do
|
14
|
-
allow(BetterErrors).to receive(:application_root).and_return("/abc/xyz")
|
15
|
-
frame = StackFrame.new("/abc/nope", 123, "foo")
|
16
|
-
|
17
|
-
expect(frame).not_to 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
|
-
expect(frame).not_to be_application
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "#gem?" do
|
28
|
-
it "is true for gem filenames" do
|
29
|
-
allow(Gem).to receive(:path).and_return(["/abc/xyz"])
|
30
|
-
frame = StackFrame.new("/abc/xyz/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo")
|
31
|
-
|
32
|
-
expect(frame).to be_gem
|
33
|
-
end
|
34
|
-
|
35
|
-
it "is false for everything else" do
|
36
|
-
allow(Gem).to receive(:path).and_return(["/abc/xyz"])
|
37
|
-
frame = StackFrame.new("/abc/nope", 123, "foo")
|
38
|
-
|
39
|
-
expect(frame).not_to be_gem
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "#application_path" do
|
44
|
-
it "chops off the application root" do
|
45
|
-
allow(BetterErrors).to receive(:application_root).and_return("/abc/xyz")
|
46
|
-
frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index")
|
47
|
-
|
48
|
-
expect(frame.application_path).to eq("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
|
-
allow(Gem).to receive(:path).and_return(["/abc/xyz"])
|
55
|
-
frame = StackFrame.new("/abc/xyz/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo")
|
56
|
-
|
57
|
-
expect(frame.gem_path).to eq("whatever (1.2.3) lib/whatever.rb")
|
58
|
-
end
|
59
|
-
|
60
|
-
it "prioritizes gem path over application path" do
|
61
|
-
allow(BetterErrors).to receive(:application_root).and_return("/abc/xyz")
|
62
|
-
allow(Gem).to receive(: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
|
-
expect(frame.gem_path).to eq("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
|
-
allow(BetterErrors).to receive(:application_root).and_return("/abc/xyz")
|
72
|
-
frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index")
|
73
|
-
expect(frame.pretty_path).to eq(frame.application_path)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "returns #gem_path for gem paths" do
|
77
|
-
allow(Gem).to receive(:path).and_return(["/abc/xyz"])
|
78
|
-
frame = StackFrame.new("/abc/xyz/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo")
|
79
|
-
|
80
|
-
expect(frame.pretty_path).to eq(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
|
-
expect(frames.first.filename).to eq("my_file.rb")
|
91
|
-
expect(frames.first.line).to eq(123)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "doesn't blow up if no method name is given" do
|
95
|
-
error = StandardError.allocate
|
96
|
-
|
97
|
-
allow(error).to receive(:backtrace).and_return(["foo.rb:123"])
|
98
|
-
frames = StackFrame.from_exception(error)
|
99
|
-
expect(frames.first.filename).to eq("foo.rb")
|
100
|
-
expect(frames.first.line).to eq(123)
|
101
|
-
|
102
|
-
allow(error).to receive(:backtrace).and_return(["foo.rb:123: this is an error message"])
|
103
|
-
frames = StackFrame.from_exception(error)
|
104
|
-
expect(frames.first.filename).to eq("foo.rb")
|
105
|
-
expect(frames.first.line).to eq(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
|
-
allow(error).to receive(:backtrace).and_return(["foo.rb:123:in `foo'", "C:in `find'", "bar.rb:123:in `bar'"])
|
111
|
-
frames = StackFrame.from_exception(error)
|
112
|
-
expect(frames.count).to eq(2)
|
113
|
-
end
|
114
|
-
|
115
|
-
it "doesn't blow up if a filename contains a colon" do
|
116
|
-
error = StandardError.allocate
|
117
|
-
allow(error).to receive(:backtrace).and_return(["crap:filename.rb:123"])
|
118
|
-
frames = StackFrame.from_exception(error)
|
119
|
-
expect(frames.first.filename).to eq("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
|
-
expect(frame.class_name).to eq('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
|
-
expect(frame.method_name).to eq("#my_method")
|
144
|
-
expect(frame.class_name).to eq("String")
|
145
|
-
else
|
146
|
-
expect(frame.method_name).to eq("my_method")
|
147
|
-
expect(frame.class_name).to eq(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
|
data/spec/better_errors_spec.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe BetterErrors do
|
4
|
-
context ".editor" do
|
5
|
-
it "defaults to textmate" do
|
6
|
-
expect(subject.editor["foo.rb", 123]).to eq("txmt://open?url=file://foo.rb&line=123")
|
7
|
-
end
|
8
|
-
|
9
|
-
it "url escapes the filename" do
|
10
|
-
expect(subject.editor["&.rb", 0]).to eq("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
|
-
expect(subject.editor[]).to 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
|
-
expect(subject.editor[]).to 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
|
-
expect(subject.editor[]).to 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
|
-
expect(subject.editor[]).to 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
|
-
expect(subject.editor[]).to 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
|
-
expect(subject.editor[]).to 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
|
-
expect(subject.editor[]).to 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
|
-
expect(subject.editor[]).to start_with "txmt://"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
data/spec/spec_helper.rb
DELETED