Skip to content

Commit 86a38cc

Browse files
committed
add error spec
1 parent fe15e9c commit 86a38cc

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
Runfile linguist-language=Ruby
2+
*.gtx linguist-language=Ruby

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ that is expected to be a part of the output.
8888
Any other line, will be treated as Ruby code and will be enclosed using ERB's
8989
`<%- ... -%>` syntax.
9090

91-
See the [example template](examples/full.rb) for additional nuances.
91+
See the [example template](examples/full.gtx) for additional nuances.
9292

9393
## Usage
9494

File renamed without changes.

spec/fixtures/error.gtx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
> first line
2+
> second line
3+
>
4+
5+
3.times do |i|
6+
> {{ " " * i * 2 }} this is loopy {{ i }}
7+
end
8+
>
9+
10+
if true
11+
> Welcome admin
12+
> WARNING: YOU HAVE ADMIN RIGHTS
13+
end
14+
15+
= "hello " * 3
16+
17+
# Fail here
18+
= 100 / 0
19+
= "hello " * 3

spec/gtx/gtx_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
subject { described_class.new template }
55
let(:context) { double user: 'admin' }
66
let(:template) { "> some output\nruby_code = 'yes'\n= ruby_code" }
7-
let(:example_path) { "examples/full.rb" }
7+
let(:example_path) { "examples/full.gtx" }
88

99
describe 'full example' do
1010
subject { described_class.load_file example_path }
@@ -34,6 +34,16 @@
3434
expect(subject.parse context).to match_approval('gtx/parse')
3535
end
3636

37+
context "on error" do
38+
subject { described_class.load_file "spec/fixtures/error.gtx" }
39+
40+
it "registers the correct file and line number in the backtrace" do
41+
expect { subject.parse }.to raise_error(ZeroDivisionError) do |e|
42+
expect(e.backtrace.first).to include "spec/fixtures/error.gtx:18"
43+
end
44+
end
45+
end
46+
3747
context "when a Binding object is passed instead of a regular object" do
3848
let(:context) do
3949
module Context

0 commit comments

Comments
 (0)