forked from BetterErrors/better_errors
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_formatter_spec.rb
More file actions
92 lines (78 loc) · 2.68 KB
/
code_formatter_spec.rb
File metadata and controls
92 lines (78 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require "spec_helper"
module BetterErrors
describe CodeFormatter do
let(:filename) { File.expand_path("../support/my_source.rb", __FILE__) }
let(:formatter) { CodeFormatter.new(filename, 8) }
it "picks an appropriate scanner" do
expect(formatter.coderay_scanner).to eq(:ruby)
end
it "shows 5 lines of context" do
expect(formatter.line_range).to eq(3..13)
expect(formatter.context_lines).to eq([
"three\n",
"four\n",
"five\n",
"six\n",
"seven\n",
"eight\n",
"nine\n",
"ten\n",
"eleven\n",
"twelve\n",
"thirteen\n"
])
end
it "works when the line is right on the edge" do
formatter = CodeFormatter.new(filename, 20)
expect(formatter.line_range).to eq(15..20)
end
describe CodeFormatter::HTML do
it "highlights the erroring line" do
formatter = CodeFormatter::HTML.new(filename, 8)
expect(formatter.output).to match(/highlight.*eight/)
end
it "works when the line is right on the edge" do
formatter = CodeFormatter::HTML.new(filename, 20)
expect(formatter.output).not_to eq(formatter.source_unavailable)
end
it "doesn't barf when the lines don't make any sense" do
formatter = CodeFormatter::HTML.new(filename, 999)
expect(formatter.output).to eq(formatter.source_unavailable)
end
it "doesn't barf when the file doesn't exist" do
formatter = CodeFormatter::HTML.new("fkdguhskd7e l", 1)
expect(formatter.output).to eq(formatter.source_unavailable)
end
end
describe CodeFormatter::Text do
it "highlights the erroring line" do
formatter = CodeFormatter::Text.new(filename, 8)
expect(formatter.output).to eq <<-TEXT.gsub(/^ /, "")
3 three
4 four
5 five
6 six
7 seven
> 8 eight
9 nine
10 ten
11 eleven
12 twelve
13 thirteen
TEXT
end
it "works when the line is right on the edge" do
formatter = CodeFormatter::Text.new(filename, 20)
expect(formatter.output).not_to eq(formatter.source_unavailable)
end
it "doesn't barf when the lines don't make any sense" do
formatter = CodeFormatter::Text.new(filename, 999)
expect(formatter.output).to eq(formatter.source_unavailable)
end
it "doesn't barf when the file doesn't exist" do
formatter = CodeFormatter::Text.new("fkdguhskd7e l", 1)
expect(formatter.output).to eq(formatter.source_unavailable)
end
end
end
end