examples/unit/local_example.rb in astrails-safe-0.1.9 vs examples/unit/local_example.rb in astrails-safe-0.1.10

- old
+ new

@@ -3,10 +3,13 @@ describe Astrails::Safe::Local do def def_config { :local => { :path => "/:kind~:id~:timestamp" + }, + :keep => { + :local => 2 } } end def def_backup @@ -32,27 +35,27 @@ it "should be true" do local.should be_active end end - describe :prefix do + describe :path do it "should raise RuntimeError when no path" do lambda { - local({}).send :prefix + local({}).send :path }.should raise_error(RuntimeError, "missing :local/:path") end it "should use local/path" do - local.send(:prefix).should == "/mysqldump~blog~NoW" + local.send(:path).should == "/mysqldump~blog~NoW" end end describe :save do before(:each) do @local = local stub(@local).system - stub(@local).path {"file-path"} + stub(@local).full_path {"file-path"} stub(FileUtils).mkdir_p end it "should call system to save the file" do mock(@local).system("command>file-path") @@ -75,8 +78,27 @@ it "should set backup.path" end end describe :cleanup do - it "should have test" + before(:each) do + @local = local + @files = [4,1,3,2].to_a.map { |i| "aaaaa#{i}" } + stub(Dir).[](anything) {@files} + stub(File).file?(anything) {true} + stub(File).size(anything) {1} + stub(File).unlink + end + + it "should check [:keep, :local]" do + @local.config[:keep][:local] = nil + dont_allow(Dir).[] + @local.send :cleanup + end + + it "should delete extra files" do + mock(File).unlink("aaaaa1") + mock(File).unlink("aaaaa2") + @local.send :cleanup + end end end