22
33describe GTX do
44 subject { described_class . new template }
5+
56 let ( :context ) { double user : 'admin' }
67 let ( :template ) { "> some output\n ruby_code = 'yes'\n = ruby_code" }
7- let ( :example_path ) { " examples/full.gtx" }
8+ let ( :example_path ) { ' examples/full.gtx' }
89
910 describe 'full example' do
1011 subject { described_class . load_file example_path }
1112
12- it " generates the correct ERB source" do
13- expect ( subject . erb_source ) . to match_approval ( " examples/full.erb" )
13+ it ' generates the correct ERB source' do
14+ expect ( subject . erb_source ) . to match_approval ( ' examples/full.erb' )
1415 end
1516
16- it " generates the correct output" do
17- expect ( subject . parse context ) . to match_approval ( " examples/full.txt" )
17+ it ' generates the correct output' do
18+ expect ( subject . parse context ) . to match_approval ( ' examples/full.txt' )
1819 end
1920 end
2021
2122 describe '#erb_source' do
22- it " returns ERB code" do
23- expect ( subject . erb_source ) . to match_approval ( " gtx/erb_source" )
23+ it ' returns ERB code' do
24+ expect ( subject . erb_source ) . to match_approval ( ' gtx/erb_source' )
2425 end
2526 end
2627
2728 describe '#erb' do
28- it " returns ERB object" do
29+ it ' returns ERB object' do
2930 expect ( subject . erb ) . to be_an ERB
3031 end
3132 end
3233
3334 describe '#parse' do
34- it " returns the parsed ERB output" do
35+ it ' returns the parsed ERB output' do
3536 expect ( subject . parse context ) . to match_approval ( 'gtx/parse' )
3637 end
3738
38- context "on error" do
39- subject { described_class . load_file " spec/fixtures/error.gtx" }
39+ context 'when an error occurs' do
40+ subject { described_class . load_file ' spec/fixtures/error.gtx' }
4041
41- it " registers the correct file and line number in the backtrace" do
42+ it ' registers the correct file and line number in the backtrace' do
4243 expect { subject . parse } . to raise_error ( ZeroDivisionError ) do |e |
43- expect ( e . backtrace . first ) . to include " spec/fixtures/error.gtx:18"
44+ expect ( e . backtrace . first ) . to include ' spec/fixtures/error.gtx:18'
4445 end
4546 end
4647 end
4748
48- context "when a Binding object is passed instead of a regular object" do
49- let ( :context ) do
50- module Context
51- class One
52- def get_binding ; binding ; end
53- end
54-
55- class Two
56- def report ; "success" ; end
57- end
58- end
49+ context 'when a Binding object is passed instead of a regular object' do
50+ let ( :context ) { MockContext ::One . new . get_binding }
51+ let ( :template ) { '= Two.new.report' }
5952
60- Context ::One . new . get_binding
61- end
62-
63- let ( :template ) { "= Two.new.report" }
64-
65- it "uses the Binding object as is instead of re-binding it" do
53+ it 'uses the Binding object as is instead of re-binding it' do
6654 expect ( subject . parse context ) . to match_approval ( 'gtx/parse-binding' )
6755 end
6856 end
6957 end
7058
71- context " class methods" do
59+ describe ' class methods' do
7260 subject { described_class }
7361
74- describe " ::render" do
75- it " returns a parsed result" do
62+ describe ' ::render' do
63+ it ' returns a parsed result' do
7664 expect ( subject . render template , context : context ) . to match_approval ( 'gtx/parse' )
7765 end
7866 end
7967
80- describe " ::load_file" do
68+ describe ' ::load_file' do
8169 subject { described_class . load_file example_path }
8270
83- it " returns a GTX object" do
84- expect ( subject ) . to be_a GTX
71+ it ' returns a GTX object' do
72+ expect ( subject ) . to be_a described_class
8573 end
8674
8775 it "loads the file's content to the GTX object" do
@@ -93,15 +81,14 @@ def report; "success"; end
9381 end
9482 end
9583
96- describe " ::render_file" do
84+ describe ' ::render_file' do
9785 let ( :gtx_double ) { double :parse }
9886
99- it " is a shortcut to ::load_file(path).parse context" do
100- expect ( subject ) . to receive ( :load_file ) . with ( example_path , filename : nil ) . and_return ( gtx_double )
87+ it ' is a shortcut to ::load_file(path).parse context' do
88+ allow ( subject ) . to receive ( :load_file ) . with ( example_path , filename : nil ) . and_return ( gtx_double )
10189 expect ( gtx_double ) . to receive ( :parse ) . with ( context )
10290 subject . render_file example_path , context : context
10391 end
10492 end
10593 end
106-
10794end
0 commit comments