spec/fbo/remote_file_spec.rb in fbo-0.0.3 vs spec/fbo/remote_file_spec.rb in fbo-0.1.0
- old
+ new
@@ -1,55 +1,59 @@
require 'spec_helper'
describe FBO::RemoteFile do
- let(:date) { Date.parse("2013-03-31") }
+ let(:date) { Date.parse('2013-03-31') }
let(:filename) { FBO::RemoteFile.filename_for_date(date) }
- let(:tmp_dir) { File.join(File.dirname(__FILE__), "..", "fixtures") }
- let(:ftp) { mock("Net::FTP", login: nil, getbinaryfile: nil, close: nil) }
+ let(:tmp_dir) { File.join(File.dirname(__FILE__), '..', 'fixtures') }
+ let(:ftp) { mock('Net::FTP') }
before do
- Net::FTP.stub(:new).and_return(ftp)
+ ftp.stubs(login: nil, getbinaryfile: nil, close: nil)
+ Net::FTP.stubs(:new).returns(ftp)
end
- describe "class methods" do
- describe "for_date" do
- it "should raise an error if no date is given" do
- expect { FBO::RemoteFile.for_date(nil) }.to raise_error
+ describe 'class methods' do
+ subject { FBO::RemoteFile }
+
+ describe 'for_date' do
+ it 'should raise an error if no date is given' do
+ proc { subject.for_date(nil) }.must_raise ArgumentError
end
- it "should return an instance of FBO::RemoteFile" do
- remote_file = FBO::RemoteFile.for_date(date, tmp_dir: tmp_dir)
- remote_file.should be_an FBO::RemoteFile
+ it 'should return an instance of FBO::RemoteFile' do
+ remote_file = subject.for_date(date, tmp_dir: tmp_dir)
+ remote_file.must_be_instance_of FBO::RemoteFile
end
end
end
- context "everything is great" do
+ context 'everything is great' do
subject { FBO::RemoteFile.new(filename, tmp_dir: tmp_dir) }
- it "should attempt to fetch the file via FTP" do
- ftp.should_receive(:login).ordered
- ftp.should_receive(:getbinaryfile).ordered
- ftp.should_receive(:close).ordered
+ it 'should attempt to fetch the file via FTP' do
+ ftp_session = sequence('ftp_session')
+ ftp.expects(:login).in_sequence(ftp_session)
+ ftp.expects(:getbinaryfile).with(filename, File.join(tmp_dir, filename)).in_sequence(ftp_session)
+ ftp.expects(:close).in_sequence(ftp_session)
subject
end
- it "should be possible to open the file and read its contents" do
- subject.readline.should_not be_nil
+ it 'should to open the file and read its contents' do
+ subject.readline.wont_be_nil
end
end
context "temporary directory doesn't exist" do
- subject { FBO::RemoteFile.new(filename, tmp_dir: "foo/bar") }
+ subject { FBO::RemoteFile.new(filename, tmp_dir: 'foo/bar') }
before do
- Dir.stub(:exists?).and_return(false)
- Dir.stub(:mkdir)
- File.stub(:new)
+ Dir.stubs(:exists?).returns(false)
+ Dir.stubs(:mkdir)
+ File.stubs(:new)
end
- it "should create the temporary directory" do
- Dir.should_receive(:mkdir).with("foo/bar")
+ it 'should create the temporary directory' do
+ Dir.expects(:mkdir).with('foo/bar')
subject
end
end
end