Skip to content

Instantly share code, notes, and snippets.

@gstark
Forked from CoryFoy/gist:2369535
Created April 12, 2012 23:44
Show Gist options
  • Save gstark/2371940 to your computer and use it in GitHub Desktop.
Save gstark/2371940 to your computer and use it in GitHub Desktop.
#
# Having #process dependent on File.open
# *and* #read, separate the processing to allow a
# more general IO processing and another method
# that handles the opening to get the IO and delegate
#
describe "Processing XML file" do
it "Reads from a file and processes the contents" do
file_path = "/some/path/to.xml"
stub_io = stub
# still dependent on File#read
File.should_receive(:read).with(file_path).and_return(stub_io)
Parser.should_receive(:process).with(stub_io)
Parser.process_file_path(file_path)
end
it "Processes from an IO" do
xml = "<xml>bleh</xml>"
io = stub(:read => xml)
Parse.should_receive(:process_xml).with(xml)
Parser.process(io)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment