Below you can see that I'm calling File.open
only once but rspec is telling me it received it 3 times.
def self.import_file(filename)
current_file = filename.split('/').last
destroy_all(["filename = ?",current_file])
unpack_format = "A#{INPUT_FILE_FORMAT.map{|element| element[1]}.join("A")}"
debugger
File.open(filename, 'r').each do |line|
hash_created = create_hash(line, unpack_format).merge({:filename=>current_file})
create(hash_created)
end
end
it "should delete previous records with the same filename" do
Payrec.should_receive(:destroy_all).with(["filename = ?", "testfile.txt"])
File.should_receive(:open).and_return([@file_line])
Payrec.import_file "testfile.txt"
end
The output is
<File (class)> expected :open with (any args) once, but received it 3 times