spec/figtree/transformer_spec.rb in figtree-0.0.1 vs spec/figtree/transformer_spec.rb in figtree-0.0.2

- old
+ new

@@ -1,18 +1,58 @@ require 'spec_helper' module Figtree describe Transformer do - let(:tree) do - Parser.new.parse("[common]\nbasic_size_limit = 26214400\n") + context "can do type conversion" do + let(:int_tree) do + Parser.new.parse("[common]\nbasic_size_limit = 26214400\n") + end + let(:arr_tree) do + Parser.new.parse("[http]\nparams = array,of,values\n") + end + let(:bool_tree) do + Parser.new.parse("[ftp]\nenabled = no\n") + end + it 'can apply an int type conversion' do + expect(Transformer.new.apply(int_tree)).to eq( + [ + { + common: Subgroup.new({basic_size_limit: 26214400}) + } + ] + ) + end + it 'can apply an array type conversion' do + expect(Transformer.new.apply(arr_tree)).to eq( + [ + { + http: Subgroup.new(params: ["array", "of", "values"]) + } + ] + ) + end + it 'can apply a bool type conversion' do + expect(Transformer.new.apply(bool_tree)).to eq( + [ + { + ftp: Subgroup.new(enabled: false) + } + ] + ) + end end - it 'can apply an int type conversion' do - expect(Transformer.new.apply(tree)).to eq( - [ - { - common: OpenStruct.new({basic_size_limit: 26214400}) - } - ] - ) + context "overrides by angle brackets" do + let(:override_tree) do + Parser.new.parse("[http]\npath = /srv/\npath<production> = /srv/var/tmp/\n") + end + it 'can apply an override' do + expect(Transformer.new.apply(override_tree, overrides: [:production])).to eq( + [ + { + http: Subgroup.new(path: '/srv/var/tmp/') + } + ] + ) + end end end end