Sha256: dd40a07cc6561319efda89d6e7169e54fded06877f7a566282d399088fc9004f

Contents?: true

Size: 946 Bytes

Versions: 1

Compression:

Stored size: 946 Bytes

Contents

require 'spec_helper'
describe Upsert do
  describe "logger" do
    it "logs to stderr by default" do
      begin
        old_stderr = $stderr
        old_logger = Upsert.logger
        Upsert.logger = nil
        $stderr = StringIO.new
        Upsert.logger.warn "hello"
        $stderr.rewind
        $stderr.read.chomp.should == 'hello'
      ensure
        Upsert.logger = old_logger
        $stderr = old_stderr
      end
    end

    it "logs queries" do
      require 'sqlite3'
      db = SQLite3::Database.open(':memory:')
      db.execute_batch "CREATE TABLE cats (name CHARACTER VARYING(255))"
      begin
        io = StringIO.new
        old_logger = Upsert.logger
        Upsert.logger = Logger.new io, Logger::DEBUG
        u = Upsert.new(db, :cats)
        u.row :name => 'you'
        io.rewind
        io.read.chomp.should =~ /INSERT OR IGNORE.*you/mi
      ensure
        Upsert.logger = old_logger
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
upsert-0.5.0 spec/logger_spec.rb