spec/shared_methods_spec.rb in vtools-1.0.0 vs spec/shared_methods_spec.rb in vtools-1.0.1
- old
+ new
@@ -138,11 +138,11 @@
it "returns config index" do
VTools::CONFIG[:test_index] = "test.value"
@class.config(:test_index).should == "test.value"
- @class.config(:nonexistent_index).should be nil
+ @class.config(:nonexistent_index).should_not be
end
end
context "#network_call" do
@@ -180,96 +180,138 @@
@class.should_receive(:log).once.and_return {|l| l.should == :error}
expect { @class.network_call("") }.to_not raise_error
end
end
- context "#generate_path" do
+ context "paths generator" do
- it "returns valid string" do
- VTools::CONFIG[:video_storage] = "test/path/"
- VTools::CONFIG[:thumb_storage] = "/thumb/path"
+ before do
+ VTools::CONFIG[:video_storage] = nil
+ VTools::CONFIG[:thumb_storage] = nil
+ VTools::CONFIG[:thumb_path_generator] = nil
+ VTools::CONFIG[:video_path_generator] = nil
+ end
- @class.generate_path("test.filename").should == "test/path"
- @class.generate_path("test.filename", "thumb").should == "/thumb/path"
+ context "#generate_path" do
- VTools::CONFIG[:thumb_storage] = ''
+ before do
+ File.stub(:exists?).and_return(true)
+ VTools::CONFIG[:PWD] = ""
+ end
- VTools::CONFIG[:PWD] = "test/pwd"
- @class.generate_path("test.filename", "thumb").should == "test/pwd"
+ context "using string path from" do
+ it "config storage" do
+ VTools::CONFIG[:video_storage] = "test/path/"
+ VTools::CONFIG[:thumb_storage] = "/thumb/path"
- VTools::CONFIG[:PWD] = nil
- VTools::CONFIG[:thumb_storage] = nil
+ @class.generate_path("test.filename").should == "test/path"
+ @class.generate_path("test.filename", "thumb").should == "/thumb/path"
+ end
- @class.generate_path("test.filename", "thumb").should == ""
- end
+ it "CONFIG[:PWD]" do
- it "executes block" do
- prc = proc do |file|
- file.should == "test.filename"
- self.class.should == Tested
- "test/path"
+ VTools::CONFIG[:thumb_storage] = ''
+ VTools::CONFIG[:PWD] = "test/pwd"
+ @class.generate_path("test.filename", "thumb").should == "test/pwd"
+ @class.generate_path("test.filename").should == "test/pwd"
+ end
+
+ it "empty set" do
+ @class.generate_path("test.filename").should == ""
+ end
end
- VTools::CONFIG[:video_storage] = '/root/'
- VTools::CONFIG[:video_path_generator] = prc
- @class.generate_path("test.filename", "video").should == "/root/test/path"
+ context "using callback" do
- VTools::CONFIG[:thumb_storage] = 'root'
- VTools::CONFIG[:thumb_path_generator] = prc
- @class.generate_path("test.filename", "thumb").should == "root/test/path"
- end
+ let(:failed_prc) { proc { CONFIG[:thumb_storage] } }
+ let(:prc) {
+ proc do |file|
+ file.should == "test.filename"
+ self.class.should == Tested
+ "test/path"
+ end
+ }
- it "raises exception on invalid block" do
- prc = proc do
- CONFIG[:thumb_storage]
+
+ it "executes block" do
+ VTools::CONFIG[:video_storage] = '/root/'
+ VTools::CONFIG[:video_path_generator] = prc
+ @class.generate_path("test.filename", "video").should == "/root/test/path"
+
+ VTools::CONFIG[:thumb_storage] = 'root'
+ VTools::CONFIG[:thumb_path_generator] = prc
+ @class.generate_path("test.filename", "thumb").should == "root/test/path"
+ end
+
+ it "raises exception on invalid block" do
+ VTools::CONFIG[:video_path_generator] = failed_prc
+ expect do
+ @class.generate_path("test.filename", "video")
+ end.to raise_error VTools::ConfigError, /Path generator error/
+ end
end
- VTools::CONFIG[:video_path_generator] = prc
- expect do
- @class.generate_path("test.filename", "video").should == "/root/test/path"
- end.to raise_error VTools::ConfigError, /Path generator error/
- end
- end
+ context "creates path" do
- context "#path_generator" do
+ before do
+ File.stub(:exists?).and_return(false)
+ VTools::CONFIG[:video_storage] = "/root/"
+ end
- before do
- VTools::CONFIG[:video_storage] = nil
- VTools::CONFIG[:thumb_storage] = nil
- VTools::CONFIG[:thumb_path_generator] = nil
- VTools::CONFIG[:video_path_generator] = nil
- end
+ it "successfull" do
+ FileUtils.should_receive(:mkdir_p).and_return(nil)
- let(:block) { proc { nil } }
+ expect do
+ @class.generate_path("test.filename").should == "/root"
+ end.to_not raise_error
+ end
- it "appends generator to thumbs" do
- @class.path_generator "thumb", &block
- VTools::CONFIG[:thumb_path_generator].should == block
- VTools::CONFIG[:video_path_generator].should be nil
- end
+ it "with error" do
+ FileUtils.should_receive(:mkdir_p).and_return do
+ raise Errno::EACCES, "Permission denied"
+ end
- it "appends generator to thumbs (invalid placeholedr given)" do
- @class.path_generator "invalid", &block
- VTools::CONFIG[:thumb_path_generator].should == block
- VTools::CONFIG[:video_path_generator].should be nil
+ expect do
+ @class.generate_path("test.filename")
+ end.to raise_error VTools::FileError, /Path generator error: /
+ end
+ end
end
- it "appends generator to video" do
- @class.path_generator "video", &block
- VTools::CONFIG[:video_path_generator].should == block
- VTools::CONFIG[:thumb_path_generator].should be nil
- end
+ context "#path_generator appended to" do
- it "appends generator to both (default)" do
- @class.path_generator &block
- VTools::CONFIG[:video_path_generator].should == block
- VTools::CONFIG[:thumb_path_generator].should == block
- end
+ let(:block_stub) { proc {nil} }
- it "skips generator appending" do
- @class.path_generator
- VTools::CONFIG[:video_path_generator].should be nil
- VTools::CONFIG[:thumb_path_generator].should be nil
+ it "thumbs only" do
+ @class.path_generator "thumbs path", &block_stub
+ VTools::CONFIG[:thumb_path_generator].should == block_stub
+ VTools::CONFIG[:video_path_generator].should_not be
+ end
+
+ it "thumbs path only (invalid placeholedr given)" do
+ @class.path_generator "invalid", &block_stub
+ VTools::CONFIG[:thumb_path_generator].should == block_stub
+ VTools::CONFIG[:video_path_generator].should_not be
+ end
+
+ it "video path" do
+ @class.path_generator "video", &block_stub
+ VTools::CONFIG[:video_path_generator].should == block_stub
+ VTools::CONFIG[:thumb_path_generator].should_not be
+ end
+
+ it "both paths (default)" do
+ @class.path_generator &block_stub
+ [:video_path_generator, :thumb_path_generator].each do |index|
+ VTools::CONFIG[index].should == block_stub
+ end
+ end
+
+ it "nothing" do
+ @class.path_generator
+ VTools::CONFIG[:video_path_generator].should_not be
+ VTools::CONFIG[:thumb_path_generator].should_not be
+ end
end
end
context "#fix_encoding" do