Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 84 lines (65 sloc) 1.91 kb
6461c78 @adamwiggins start on Rush::Process
authored
1 require File.dirname(__FILE__) + '/base'
2
3 describe Rush::File do
c25b27e @adamwiggins before(:each) -> before
authored
4 before do
6461c78 @adamwiggins start on Rush::Process
authored
5 @sandbox_dir = "/tmp/rush_spec.#{Process.pid}"
6 system "rm -rf #{@sandbox_dir}; mkdir -p #{@sandbox_dir}"
7
8 @filename = "#{@sandbox_dir}/test_file"
9 @contents = "1234"
c0aac3d @adamwiggins mix commands into hash so that search return value works
authored
10 system "echo #{@contents} > #{@filename}"
11 @contents += "\n"
6461c78 @adamwiggins start on Rush::Process
authored
12
13 @file = Rush::File.new(@filename)
14 end
15
c25b27e @adamwiggins before(:each) -> before
authored
16 after do
6461c78 @adamwiggins start on Rush::Process
authored
17 system "rm -rf #{@sandbox_dir}"
18 end
19
20 it "is a child of Rush::Entry" do
21 @file.should be_kind_of(Rush::Entry)
22 end
23
8cedf80 @adamwiggins directory? -> dir? to be more consistent
authored
24 it "is not a dir" do
25 @file.should_not be_dir
6461c78 @adamwiggins start on Rush::Process
authored
26 end
27
4eb1a14 @adamwiggins introduce Rush::Config for saving configs in ~/.rush
authored
28 it "can create itself as a blank file, and return itself" do
29 create_me = Rush::File.new("#{@sandbox_dir}/create_me")
30 create_me.create.should == create_me
31 File.exists?("#{@sandbox_dir}/create_me").should == true
32 end
33
6461c78 @adamwiggins start on Rush::Process
authored
34 it "knows its size in bytes" do
7818ada @adamwiggins line_count for files and file arrays
authored
35 @file.size.should == @contents.length
6461c78 @adamwiggins start on Rush::Process
authored
36 end
37
38 it "can read its contents" do
7818ada @adamwiggins line_count for files and file arrays
authored
39 @file.contents.should == @contents
6461c78 @adamwiggins start on Rush::Process
authored
40 end
41
020ca29 @adamwiggins File#read alias for contents
authored
42 it "read is an alias for contents" do
43 @file.read.should == @contents
44 end
45
6461c78 @adamwiggins start on Rush::Process
authored
46 it "can write new contents" do
47 @file.write('write test')
7818ada @adamwiggins line_count for files and file arrays
authored
48 @file.contents.should == 'write test'
49 end
50
51 it "can count the number of lines it contains" do
52 @file.write("1\n2\n3\n")
53 @file.line_count.should == 3
6461c78 @adamwiggins start on Rush::Process
authored
54 end
55
056b0b8 @adamwiggins SearchResults to cleanly handle entry / line management
authored
56 it "searches its contents for matching lines" do
57 @file.write("a\n1\nb\n2\n")
58 @file.search(/\d/).should == %w(1 2)
59 end
60
61 it "search returns nil if no lines match" do
62 @file.write("a\nb\nc\n")
63 @file.search(/\d/).should be_nil
64 end
65
761479c @adamwiggins use Commands mixin for search, replace, and others
authored
66 it "find-in-file replace" do
67 @file.replace_contents!(/\d/, 'x')
c0aac3d @adamwiggins mix commands into hash so that search return value works
authored
68 @file.contents.should == "xxxx\n"
6461c78 @adamwiggins start on Rush::Process
authored
69 end
70
71 it "can destroy itself" do
72 @file.destroy
73 ::File.exists?(@filename).should be_false
74 end
afb1295 @adamwiggins history is a flat text file instead of yaml
authored
75
76 it "can fetch contents or blank if doesn't exist" do
77 Rush::File.new('/does/not/exist').contents_or_blank.should == ""
78 end
5cf5a3b @adamwiggins first exception: File#contents raises Rush::DoesNotExist if there is no ...
authored
79
80 it "can fetch lines, or empty if doesn't exist" do
81 Rush::File.new('/does/not/exist').lines_or_empty.should == []
82 end
6461c78 @adamwiggins start on Rush::Process
authored
83 end
Something went wrong with that request. Please try again.