better_errors 0.9.0 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of better_errors might be problematic. Click here for more details.
- checksums.yaml +14 -6
- data/.travis.yml +1 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +2 -2
- data/README.md +7 -16
- data/better_errors.gemspec +0 -8
- data/lib/better_errors.rb +45 -31
- data/lib/better_errors/code_formatter.rb +2 -2
- data/lib/better_errors/code_formatter/html.rb +11 -4
- data/lib/better_errors/code_formatter/text.rb +2 -2
- data/lib/better_errors/error_page.rb +2 -1
- data/lib/better_errors/middleware.rb +10 -5
- data/lib/better_errors/repl.rb +2 -2
- data/lib/better_errors/repl/basic.rb +1 -1
- data/lib/better_errors/repl/pry.rb +11 -6
- data/lib/better_errors/stack_frame.rb +41 -7
- data/lib/better_errors/templates/main.erb +37 -5
- data/lib/better_errors/templates/variable_info.erb +4 -3
- data/lib/better_errors/version.rb +1 -1
- data/spec/better_errors/code_formatter_spec.rb +11 -11
- data/spec/better_errors/error_page_spec.rb +20 -13
- data/spec/better_errors/middleware_spec.rb +35 -16
- data/spec/better_errors/repl/basic_spec.rb +1 -1
- data/spec/better_errors/repl/pry_spec.rb +9 -6
- data/spec/better_errors/repl/shared_examples.rb +16 -20
- data/spec/better_errors/stack_frame_spec.rb +71 -30
- data/spec/better_errors_spec.rb +63 -3
- data/spec/spec_helper.rb +1 -0
- metadata +10 -110
- data/CONTRIBUTING.md +0 -9
- data/TIPS_AND_TRICKS.md +0 -39
@@ -3,21 +3,21 @@ require "spec_helper"
|
|
3
3
|
module BetterErrors
|
4
4
|
describe StackFrame do
|
5
5
|
context "#application?" do
|
6
|
-
it "
|
7
|
-
BetterErrors.stub
|
6
|
+
it "is true for application filenames" do
|
7
|
+
BetterErrors.stub(:application_root).and_return("/abc/xyz")
|
8
8
|
frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index")
|
9
9
|
|
10
10
|
frame.application?.should be_true
|
11
11
|
end
|
12
12
|
|
13
|
-
it "
|
14
|
-
BetterErrors.stub
|
13
|
+
it "is false for everything else" do
|
14
|
+
BetterErrors.stub(:application_root).and_return("/abc/xyz")
|
15
15
|
frame = StackFrame.new("/abc/nope", 123, "foo")
|
16
16
|
|
17
17
|
frame.application?.should be_false
|
18
18
|
end
|
19
19
|
|
20
|
-
it "
|
20
|
+
it "doesn't care if no application_root is set" do
|
21
21
|
frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index")
|
22
22
|
|
23
23
|
frame.application?.should be_false
|
@@ -25,15 +25,15 @@ module BetterErrors
|
|
25
25
|
end
|
26
26
|
|
27
27
|
context "#gem?" do
|
28
|
-
it "
|
29
|
-
Gem.stub
|
28
|
+
it "is true for gem filenames" do
|
29
|
+
Gem.stub(:path).and_return(["/abc/xyz"])
|
30
30
|
frame = StackFrame.new("/abc/xyz/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo")
|
31
31
|
|
32
32
|
frame.gem?.should be_true
|
33
33
|
end
|
34
34
|
|
35
|
-
it "
|
36
|
-
Gem.stub
|
35
|
+
it "is false for everything else" do
|
36
|
+
Gem.stub(:path).and_return(["/abc/xyz"])
|
37
37
|
frame = StackFrame.new("/abc/nope", 123, "foo")
|
38
38
|
|
39
39
|
frame.gem?.should be_false
|
@@ -41,8 +41,8 @@ module BetterErrors
|
|
41
41
|
end
|
42
42
|
|
43
43
|
context "#application_path" do
|
44
|
-
it "
|
45
|
-
BetterErrors.stub
|
44
|
+
it "chops off the application root" do
|
45
|
+
BetterErrors.stub(:application_root).and_return("/abc/xyz")
|
46
46
|
frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index")
|
47
47
|
|
48
48
|
frame.application_path.should == "app/controllers/crap_controller.rb"
|
@@ -50,16 +50,16 @@ module BetterErrors
|
|
50
50
|
end
|
51
51
|
|
52
52
|
context "#gem_path" do
|
53
|
-
it "
|
54
|
-
Gem.stub
|
53
|
+
it "chops of the gem path and stick (gem) there" do
|
54
|
+
Gem.stub(:path).and_return(["/abc/xyz"])
|
55
55
|
frame = StackFrame.new("/abc/xyz/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo")
|
56
56
|
|
57
57
|
frame.gem_path.should == "whatever (1.2.3) lib/whatever.rb"
|
58
58
|
end
|
59
59
|
|
60
|
-
it "
|
61
|
-
BetterErrors.stub
|
62
|
-
Gem.stub
|
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
63
|
frame = StackFrame.new("/abc/xyz/vendor/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo")
|
64
64
|
|
65
65
|
frame.gem_path.should == "whatever (1.2.3) lib/whatever.rb"
|
@@ -67,54 +67,95 @@ module BetterErrors
|
|
67
67
|
end
|
68
68
|
|
69
69
|
context "#pretty_path" do
|
70
|
-
it "
|
71
|
-
BetterErrors.stub
|
70
|
+
it "returns #application_path for application paths" do
|
71
|
+
BetterErrors.stub(:application_root).and_return("/abc/xyz")
|
72
72
|
frame = StackFrame.new("/abc/xyz/app/controllers/crap_controller.rb", 123, "index")
|
73
73
|
frame.pretty_path.should == frame.application_path
|
74
74
|
end
|
75
75
|
|
76
|
-
it "
|
77
|
-
Gem.stub
|
76
|
+
it "returns #gem_path for gem paths" do
|
77
|
+
Gem.stub(:path).and_return(["/abc/xyz"])
|
78
78
|
frame = StackFrame.new("/abc/xyz/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo")
|
79
79
|
|
80
80
|
frame.pretty_path.should == frame.gem_path
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
it "
|
85
|
-
|
86
|
-
|
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
|
87
89
|
frames = StackFrame.from_exception(syntax_error)
|
88
90
|
frames.first.filename.should == "my_file.rb"
|
89
91
|
frames.first.line.should == 123
|
90
92
|
end
|
91
93
|
|
92
|
-
it "
|
94
|
+
it "doesn't blow up if no method name is given" do
|
93
95
|
error = StandardError.allocate
|
94
96
|
|
95
|
-
error.stub
|
97
|
+
error.stub(:backtrace).and_return(["foo.rb:123"])
|
96
98
|
frames = StackFrame.from_exception(error)
|
97
99
|
frames.first.filename.should == "foo.rb"
|
98
100
|
frames.first.line.should == 123
|
99
101
|
|
100
|
-
error.stub
|
102
|
+
error.stub(:backtrace).and_return(["foo.rb:123: this is an error message"])
|
101
103
|
frames = StackFrame.from_exception(error)
|
102
104
|
frames.first.filename.should == "foo.rb"
|
103
105
|
frames.first.line.should == 123
|
104
106
|
end
|
105
107
|
|
106
|
-
it "
|
108
|
+
it "ignores a backtrace line if its format doesn't make any sense at all" do
|
107
109
|
error = StandardError.allocate
|
108
|
-
error.stub
|
110
|
+
error.stub(:backtrace).and_return(["foo.rb:123:in `foo'", "C:in `find'", "bar.rb:123:in `bar'"])
|
109
111
|
frames = StackFrame.from_exception(error)
|
110
112
|
frames.count.should == 2
|
111
113
|
end
|
112
114
|
|
113
|
-
it "
|
115
|
+
it "doesn't blow up if a filename contains a colon" do
|
114
116
|
error = StandardError.allocate
|
115
|
-
error.stub
|
117
|
+
error.stub(:backtrace).and_return(["crap:filename.rb:123"])
|
116
118
|
frames = StackFrame.from_exception(error)
|
117
119
|
frames.first.filename.should == "crap:filename.rb"
|
118
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
|
+
if RUBY_VERSION >= "2.0.0"
|
129
|
+
frame.class_name.should == 'BasicObject'
|
130
|
+
else
|
131
|
+
frame.class_name.should be_nil
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
it "sets method names properly" do
|
136
|
+
obj = "string"
|
137
|
+
def obj.my_method
|
138
|
+
begin
|
139
|
+
raise "foo"
|
140
|
+
rescue => err
|
141
|
+
err
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
frame = StackFrame.from_exception(obj.my_method).first
|
146
|
+
if RUBY_VERSION >= "2.0.0"
|
147
|
+
frame.method_name.should == "#my_method"
|
148
|
+
frame.class_name.should == "String"
|
149
|
+
else
|
150
|
+
frame.method_name.should == "my_method"
|
151
|
+
frame.class_name.should be_nil
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
if RUBY_ENGINE == "java"
|
156
|
+
it "doesn't blow up on a native Java exception" do
|
157
|
+
expect { StackFrame.from_exception(java.lang.Exception.new) }.to_not raise_error
|
158
|
+
end
|
159
|
+
end
|
119
160
|
end
|
120
161
|
end
|
data/spec/better_errors_spec.rb
CHANGED
@@ -2,12 +2,72 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe BetterErrors do
|
4
4
|
context ".editor" do
|
5
|
-
it "
|
5
|
+
it "defaults to textmate" do
|
6
6
|
subject.editor["foo.rb", 123].should == "txmt://open?url=file://foo.rb&line=123"
|
7
7
|
end
|
8
|
-
|
9
|
-
it "
|
8
|
+
|
9
|
+
it "url escapes the filename" do
|
10
10
|
subject.editor["&.rb", 0].should == "txmt://open?url=file://%26.rb&line=0"
|
11
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 mvim:// 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
|
12
72
|
end
|
13
73
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,139 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better_errors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Somerville
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-29 00:00:00.000000000 Z
|
12
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: 2.12.0
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 2.12.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: binding_of_caller
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '>='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: pry
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: simplecov
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - '>='
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - '>='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: yard
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - '>='
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - '>='
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: redcarpet
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - '>='
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - '>='
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
13
|
- !ruby/object:Gem::Dependency
|
112
14
|
name: erubis
|
113
15
|
requirement: !ruby/object:Gem::Requirement
|
114
16
|
requirements:
|
115
|
-
- - '>='
|
17
|
+
- - ! '>='
|
116
18
|
- !ruby/object:Gem::Version
|
117
19
|
version: 2.6.6
|
118
20
|
type: :runtime
|
119
21
|
prerelease: false
|
120
22
|
version_requirements: !ruby/object:Gem::Requirement
|
121
23
|
requirements:
|
122
|
-
- - '>='
|
24
|
+
- - ! '>='
|
123
25
|
- !ruby/object:Gem::Version
|
124
26
|
version: 2.6.6
|
125
27
|
- !ruby/object:Gem::Dependency
|
126
28
|
name: coderay
|
127
29
|
requirement: !ruby/object:Gem::Requirement
|
128
30
|
requirements:
|
129
|
-
- - '>='
|
31
|
+
- - ! '>='
|
130
32
|
- !ruby/object:Gem::Version
|
131
33
|
version: 1.0.0
|
132
34
|
type: :runtime
|
133
35
|
prerelease: false
|
134
36
|
version_requirements: !ruby/object:Gem::Requirement
|
135
37
|
requirements:
|
136
|
-
- - '>='
|
38
|
+
- - ! '>='
|
137
39
|
- !ruby/object:Gem::Version
|
138
40
|
version: 1.0.0
|
139
41
|
description: Provides a better error page for Rails and other Rack apps. Includes
|
@@ -148,12 +50,10 @@ files:
|
|
148
50
|
- .gitignore
|
149
51
|
- .travis.yml
|
150
52
|
- .yardopts
|
151
|
-
- CONTRIBUTING.md
|
152
53
|
- Gemfile
|
153
54
|
- LICENSE.txt
|
154
55
|
- README.md
|
155
56
|
- Rakefile
|
156
|
-
- TIPS_AND_TRICKS.md
|
157
57
|
- better_errors.gemspec
|
158
58
|
- lib/better_errors.rb
|
159
59
|
- lib/better_errors/code_formatter.rb
|
@@ -191,17 +91,17 @@ require_paths:
|
|
191
91
|
- lib
|
192
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
193
93
|
requirements:
|
194
|
-
- - '>='
|
94
|
+
- - ! '>='
|
195
95
|
- !ruby/object:Gem::Version
|
196
96
|
version: 1.9.2
|
197
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
98
|
requirements:
|
199
|
-
- - '
|
99
|
+
- - ! '>'
|
200
100
|
- !ruby/object:Gem::Version
|
201
|
-
version:
|
101
|
+
version: 1.3.1
|
202
102
|
requirements: []
|
203
103
|
rubyforge_project:
|
204
|
-
rubygems_version: 2.0.
|
104
|
+
rubygems_version: 2.0.6
|
205
105
|
signing_key:
|
206
106
|
specification_version: 4
|
207
107
|
summary: Better error page for Rails and other Rack apps
|