Skip to content

Commit

Permalink
remove conditions for Encoding definition
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Jul 19, 2013
1 parent 48b123b commit 0a06c4e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 77 deletions.
70 changes: 34 additions & 36 deletions spec/core/compatible_spec.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,46 @@
# -*- coding: utf-8 -*-
require 'spec_helper'

if defined?(Encoding)
require 'tdiary/compatible'
require 'fileutils'
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
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
after do
FileUtils.rm @dbfile
end

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

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

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

Expand Down
80 changes: 39 additions & 41 deletions spec/core/rack/assets/precompile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,63 @@
require 'fileutils'
require 'tdiary/rack/assets/precompile'

if defined?(Encoding)
describe TDiary::Rack::Assets::Precompile do
include Rack::Test::Methods
describe TDiary::Rack::Assets::Precompile do
include Rack::Test::Methods

let(:app) do
TDiary::Rack::Assets::Precompile.new(lambda{|env| [200, {}, ['Awesome']]}, @environment)
end
let(:assets_path) {"#{TDiary::PATH}/tmp/assets"}
let(:app) do
TDiary::Rack::Assets::Precompile.new(lambda{|env| [200, {}, ['Awesome']]}, @environment)
end
let(:assets_path) {"#{TDiary::PATH}/tmp/assets"}

before do
FileUtils.mkdir_p assets_path
@environment = Sprockets::Environment.new
@environment.append_path assets_path
end

after do
FileUtils.rm_rf assets_path
end

context "JavaScript が無い場合" do
before do
FileUtils.mkdir_p assets_path
@environment = Sprockets::Environment.new
@environment.append_path assets_path
FileUtils.touch "#{assets_path}/foo.coffee"
get '/'
end

after do
FileUtils.rm_rf assets_path
it "JavaScript にコンパイルされる" do
FileTest.exist?("#{assets_path}/foo.js").should be_true
end
end

context "JavaScript が無い場合" do
context "JavaScript がある場合" do
context "CoffeeScript の方が新しい場合" do
before do
FileUtils.touch "#{assets_path}/foo.js"
sleep 1
FileUtils.touch "#{assets_path}/foo.coffee"
@jstime = File.mtime("#{assets_path}/foo.js").to_i

get '/'
end

it "JavaScript にコンパイルされる" do
FileTest.exist?("#{assets_path}/foo.js").should be_true
it "JavaScript が更新される" do
@jstime.should < File.mtime("#{assets_path}/foo.js").to_i
end
end

context "JavaScript がある場合" do
context "CoffeeScript の方が新しい場合" do
before do
FileUtils.touch "#{assets_path}/foo.js"
sleep 1
FileUtils.touch "#{assets_path}/foo.coffee"
@jstime = File.mtime("#{assets_path}/foo.js").to_i

get '/'
end
context "JavaScript の方が新しい場合" do
before do
FileUtils.touch "#{assets_path}/foo.coffee"
sleep 1
FileUtils.touch "#{assets_path}/foo.js"
@jstime = File.mtime("#{assets_path}/foo.js").to_i

it "JavaScript が更新される" do
@jstime.should < File.mtime("#{assets_path}/foo.js").to_i
end
get '/'
end

context "JavaScript の方が新しい場合" do
before do
FileUtils.touch "#{assets_path}/foo.coffee"
sleep 1
FileUtils.touch "#{assets_path}/foo.js"
@jstime = File.mtime("#{assets_path}/foo.js").to_i

get '/'
end

it "JavaScript は更新されない" do
@jstime.should == File.mtime("#{assets_path}/foo.js").to_i
end
it "JavaScript は更新されない" do
@jstime.should == File.mtime("#{assets_path}/foo.js").to_i
end
end
end
Expand Down

0 comments on commit 0a06c4e

Please sign in to comment.