Created
September 5, 2012 04:30
-
-
Save mkocher/3630468 to your computer and use it in GitHub Desktop.
Fakes in Ruby
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
class FileTransferJob | |
def initialize(ftp_service = FtpService.new) | |
@ftp_service = ftp_service | |
end | |
def do_the_needful | |
@ftp_service.put("/tmp/the_file_to_send", "/tmp/the_destination") | |
end | |
end | |
describe FileTransferJob do | |
class FakeFtpService | |
attr_accessor :transfers | |
def put(file, destination) | |
self.transfers ||= [] | |
transfers << {:file => file, :destination => destination} | |
end | |
end | |
let(:ftp_service) { FakeFtpService.new } | |
let(:job) { FileTransferJob.new(ftp_service) } | |
it "sends the file" do | |
job.do_the_needful | |
ftp_service.transfers.first[:file].should == "/tmp/the_file_to_send" | |
ftp_service.transfers.first[:destination].should == "/tmp/the_destination" | |
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
Matthews-MacBook-Air:lobot (ubuntu) $ rspec ~/Desktop/fake.rb | |
FileTransferJob | |
sends the file | |
Finished in 0.00058 seconds | |
1 example, 0 failures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment