forked from awestruct/awestruct
/
file_handler_spec.rb
57 lines (46 loc) · 2.12 KB
/
file_handler_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'fileutils'
require 'awestruct/handlers/file_handler'
describe Awestruct::Handlers::FileHandler do
before :all do
@site = OpenCascade.new :encoding=>false, :dir=>Pathname.new( File.dirname( __FILE__ ) + '/test-data' )
end
it "should be able to read a valid absolute file handler" do
filename = Pathname.new( File.dirname(__FILE__) + "/test-data/simple-file.txt" )
handler = Awestruct::Handlers::FileHandler.new( @site, filename )
handler.raw_content.strip.should == 'howdy'
end
it "should be able to read a valid relative file handler" do
filename = Pathname.new( File.dirname(__FILE__) + "/test-data/simple-file.txt" )
pwd = Pathname.new( Dir.pwd )
handler = Awestruct::Handlers::FileHandler.new( @site, filename.relative_path_from( pwd ) )
handler.raw_content.strip.should == 'howdy'
end
it "should be stale before being read" do
filename = Pathname.new( File.dirname(__FILE__) + "/test-data/simple-file.txt" )
handler = Awestruct::Handlers::FileHandler.new( @site, filename )
handler.should be_stale
end
it "should not be stale after being read" do
filename = Pathname.new( File.dirname(__FILE__) + "/test-data/simple-file.txt" )
handler = Awestruct::Handlers::FileHandler.new( @site, filename )
handler.raw_content.strip.should == 'howdy'
handler.should_not be_stale
end
it "should be stale if touched after being read" do
filename = Pathname.new( File.dirname(__FILE__) + "/test-data/simple-file.txt" )
handler = Awestruct::Handlers::FileHandler.new( @site, filename )
handler.raw_content.strip.should == 'howdy'
handler.should_not be_stale
sleep(1)
FileUtils.touch( filename )
handler.should be_stale
end
it "should provide reasonable paths" do
filename = Pathname.new( File.dirname(__FILE__) + "/test-data/simple-file.txt" )
handler = Awestruct::Handlers::FileHandler.new( @site, filename )
handler.relative_source_path.should == '/simple-file.txt'
handler.output_filename.should == 'simple-file.txt'
handler.output_extension.should == '.txt'
handler.output_path.should == '/simple-file.txt'
end
end