######################################################################## # dbi_dbrc_xml_spec.rb # # Test suite for the XML specific version of DBI::DBRC. This test case # should be run via the 'rake test' task. ######################################################################## require 'dbi/dbrc' require 'rspec' require 'pp' # Need this to avoid fakefs error require 'fakefs/spec_helpers' RSpec.describe DBI::DBRC::XML, :xml => true do include FakeFS::SpecHelpers let(:home) { File.join(Dir.pwd, 'home', 'someone') } let(:dbrc) { File.join(home, '.dbrc') } let(:db_foo){ 'foo' } let(:user1) { 'user1' } let(:xml){ %q{ user1 pwd1 Oracle 60 40 3 user2 pwd2 OCI8 60 60 4 user1 pwd3 Oracle 30 30 2 user3 pwd4 }.lstrip } before do allow(Dir).to receive(:home).and_return(home) if File::ALT_SEPARATOR allow(FakeFS::File).to receive(:hidden?).and_return(true) allow(FakeFS::File).to receive(:encrypted?).and_return(false) end FileUtils.mkdir_p(home) File.open(dbrc, 'w'){ |fh| fh.write(xml) } File.chmod(0600, dbrc) # FakeFS doesn't implement this yet allow_any_instance_of(FakeFS::File::Stat).to receive(:owned?).and_return(true) end context "instance methods" do before do @dbrc = described_class.new(db_foo, user1) end example "database method returns expected value" do expect(@dbrc.database).to eq('foo') end example "password method returns expected value" do expect(@dbrc.password).to eq('pwd1') end example "driver method returns expected value" do expect(@dbrc.driver).to eq('Oracle') end example "interval method returns expected value" do expect(@dbrc.interval).to eq(60) end example "timeout method returns expected value" do expect(@dbrc.timeout).to eq(40) end example "maximum_reconnects method returns expected value" do expect(@dbrc.maximum_reconnects).to eq(3) end end end