Sha256: b94307441ba152e4740a63ff4b972ba4934fcdf5b278d0f264bc505ac8efc775

Contents?: true

Size: 1.57 KB

Versions: 11

Compression:

Stored size: 1.57 KB

Contents

# -*- coding: utf-8 -*-
require 'spec_helper'

require 'tdiary/compatible'
require 'fileutils'

describe PStore, "auto convert library" do
	before do
		# rake specで動かすと、comppatible.rb が既に読み込まれてしまっているため、
		# このPStoreがASCII-8BITではなくUTF-8になってしまう。
		# そのため、下記と同様の ascii8bit-pstore.db をテストフィクスチャとしている。
		# PStore.new(@dbfile).transaction do |db|
		# 	db["key1".to_8bit] = "val1".to_8bit
		# 	db["key2".to_8bit] = 2
		# 	db["key3".to_8bit] = [1, :sym, "string".to_8bit]
		# end
		dbfilename = '../fixtures/ascii8bit-pstore.db'
		dbfile_orig = File.join(File.dirname(__FILE__), dbfilename)
		@dbfile = File.join(File.dirname(__FILE__), "#{dbfilename}.work")
		FileUtils.cp dbfile_orig, @dbfile
	end

	after do
		FileUtils.rm @dbfile
	end

	it "should convert an encoding to UTF-8 automatically" do
		PStore.new(@dbfile).transaction do |db|
			expect(db["key1"].encoding).to eq(Encoding::UTF_8)
			expect(db["key2"]).to  eq(2)
			expect(db["key3"][2].encoding).to  eq(Encoding::UTF_8)
		end
	end

	it "1回目のtransactionではMashal.loadが3回呼ばれる" do
		expect(Marshal).to receive(:load).exactly(3).and_return({})
		PStore.new(@dbfile).transaction {}
	end

	it "2回目のtransactionではMashal.loadが1回だけ呼ばれる" do
		expect(Marshal).to receive(:load).exactly(4).and_return({})
		PStore.new(@dbfile).transaction {}
		PStore.new(@dbfile).transaction {}
	end
end

# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End:

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/tdiary-4.2.0/spec/core/compatible_spec.rb
tdiary-4.2.0 spec/core/compatible_spec.rb
tdiary-4.1.3 spec/core/compatible_spec.rb
tdiary-4.1.2 spec/core/compatible_spec.rb
tdiary-4.1.1 spec/core/compatible_spec.rb
tdiary-4.1.0 spec/core/compatible_spec.rb
tdiary-4.1.0.20141126 spec/core/compatible_spec.rb
tdiary-4.0.5.1 spec/core/compatible_spec.rb
tdiary-4.0.5 spec/core/compatible_spec.rb
tdiary-4.0.4 spec/core/compatible_spec.rb
tdiary-4.0.3 spec/core/compatible_spec.rb