require_relative './spec_helper' describe Groovy do before :each do Groonga::Context.default = nil end describe '.open' do it 'explodes if called with no params' do expect do Groovy.open end.to raise_error(ArgumentError) end it 'explodes if called with nil db_path' do expect do Groovy.open(nil) end.to raise_error(ArgumentError) end context 'if no context given' do it 'sets up database for default context' do expect(Groonga::Context.default.database).to be_nil Groovy.open('tmp/foo1') expect(Groonga::Context.default.database).to be_a(Groonga::Database) Groovy.close # default end end context 'if context given' do it 'sets up database for default context' do expect(Groonga::Context.default.database).to be_nil Groovy.open('tmp/foo2', :test) expect(Groonga::Context.default.database).to be_nil expect(Groovy['test']).to be_a(Groonga::Context) expect(Groovy[:test].database).to be_a(Groonga::Database) Groovy.close(:test) end end end describe '.close' do it 'thows if not opened (default)' do expect { Groovy.close }.to raise_error(Groovy::ContextNotFound) end it 'thows if context does not exist' do expect { Groovy.close(:foo) }.to raise_error(Groovy::ContextNotFound) end it 'thows if already closed' do Groovy.open('tmp/foo') Groovy.close expect do Groovy.close end.to raise_error(Groovy::ContextNotFound) end it 'works if ctx exists and open' do Groovy.open('tmp/foo', :test) expect(Groovy.close(:test)).to eq(nil) end end end