Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
155605d
commit 1fbf802
Showing
6 changed files
with
78 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
source 'http://rubygems.org' | ||
|
||
group :development do | ||
gem 'rspec', '~> 1.3.0' | ||
gem 'rspec', '>= 2.0.0.beta.17' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
rspec (1.3.0) | ||
diff-lcs (1.1.2) | ||
rspec (2.0.0.beta.17) | ||
rspec-core (= 2.0.0.beta.17) | ||
rspec-expectations (= 2.0.0.beta.17) | ||
rspec-mocks (= 2.0.0.beta.17) | ||
rspec-core (2.0.0.beta.17) | ||
rspec-expectations (2.0.0.beta.17) | ||
diff-lcs (>= 1.1.2) | ||
rspec-mocks (2.0.0.beta.17) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
rspec (~> 1.3.0) | ||
rspec (>= 2.0.0.beta.17) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
require 'net/ftp' | ||
require 'mock_ftp/core_ext/string' | ||
|
||
module MockFTP | ||
def mock_ftp | ||
autoload :File, 'mock_ftp/file' | ||
autoload :Folder, 'mock_ftp/folder' | ||
|
||
module Net | ||
autoload :FTP, 'mock_ftp/net_ftp' | ||
end | ||
|
||
def mock_ftp(root_path = '', &block) | ||
@original_net_ftp = ::Net.__send__ :remove_const, :FTP | ||
::Net.const_set :FTP, MockFTP::Net::FTP | ||
|
||
MockFTP::Folder.root(root_path, &block) | ||
|
||
::Net.__send__ :remove_const, :FTP | ||
::Net.const_set :FTP, @original_net_ftp | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,43 @@ | ||
require 'spec_helper' | ||
|
||
describe MockFTP do | ||
pending 'YES!' | ||
describe '#nlst' do | ||
it 'should list mocked files' do | ||
mock_ftp do |f| | ||
f.file 'file 1' | ||
f.file 'file 2' | ||
|
||
open_ftp do |ftp| | ||
ftp.nlst.should == [ 'file 1', 'file 2' ] | ||
end | ||
end | ||
end | ||
|
||
context 'within a folder' do | ||
it 'should list mocked files with prefixed folder name' do | ||
mock_ftp do |f| | ||
f.folder 'folder' do |f| | ||
f.file 'file 1' | ||
f.file 'file 2' | ||
end | ||
|
||
open_ftp do |ftp| | ||
ftp.nlst('/folder').should == [ '/folder/file 1', '/folder/file 2' ] | ||
end | ||
end | ||
end | ||
end | ||
|
||
context 'without a folder' do | ||
it 'should raise an error' do | ||
mock_ftp do |f| | ||
open_ftp do |ftp| | ||
expect { | ||
ftp.nlst('blah') | ||
}.to raise_error(Net::FTPPermError) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters