# frozen_string_literal: true require 'spec_helper' RSpec.describe 'query script' do let(:fixture_file_path) { File.expand_path('fixtures/sample_file.txt', __dir__) } let(:storage_dir) { Dir.mktmpdir } let(:import_script_path) { File.expand_path('../exe/import', __dir__) } let(:script_path) { File.expand_path('../exe/query', __dir__) } before { `#{import_script_path.inspect} -f #{fixture_file_path.inspect} -t #{storage_dir.inspect}` } after { FileUtils.remove_entry(storage_dir, true) } describe 'query -s PROJECT,SHOT,VERSION,STATUS -o FINISH_DATE,INTERNAL_BID' do subject { `#{script_path.inspect} -s PROJECT,SHOT,VERSION,STATUS -o FINISH_DATE,INTERNAL_BID` } it 'returns the correct results' do output = <<~OUTPUT lotr,03,16,finished king kong,42,128,not required the hobbit,40,32,finished the hobbit,01,64,scheduled OUTPUT expect(subject).to eq(output) end end describe 'query -s PROJECT,SHOT,VERSION,STATUS -f FINISH_DATE=2006-07-22' do subject { `#{script_path.inspect} -s PROJECT,SHOT,VERSION,STATUS -f FINISH_DATE=2006-07-22` } it 'returns the correct results' do output = <<~OUTPUT king kong,42,128,not required OUTPUT expect(subject).to eq(output) end end describe 'query -s PROJECT,INTERNAL_BID:sum,SHOT:collect -g PROJECT' do subject { `#{script_path.inspect} -s PROJECT,INTERNAL_BID:sum,SHOT:collect -g PROJECT` } it 'returns the correct results' do output = <<~OUTPUT the hobbit,67.80,[01,40] king kong,30.00,[42] lotr,15.00,[03] OUTPUT expect(subject).to eq(output) end end describe %(query -s PROJECT,INTERNAL_BID -f 'PROJECT="the hobbit" OR PROJECT="lotr"') do subject { `#{script_path.inspect} -s PROJECT,INTERNAL_BID -f 'PROJECT="the hobbit" OR PROJECT="lotr"'` } it 'returns the correct results' do output = <<~OUTPUT the hobbit,45.00 the hobbit,22.80 lotr,15.00 OUTPUT expect(subject).to eq(output) end end describe %(query -s PROJECT,INTERNAL_BID -f 'PROJECT="the hobbit" AND SHOT="01" OR SHOT="40"') do subject { `#{script_path.inspect} -s PROJECT,INTERNAL_BID -f 'PROJECT="the hobbit" AND SHOT="01" OR SHOT="40"'` } it 'returns the correct results' do output = <<~OUTPUT the hobbit,45.00 the hobbit,22.80 OUTPUT expect(subject).to eq(output) end end end