I have a function with several File.exists? calls:
def create(one_filename, other_filename)
raise Error, "One error" if File.exists?(one_filename)
raise Error, "Other error" unless File.exist?(other_filename)
.....
end
But I don't know the way to stub the second error. The spec is something as:
it "should not create an existing file" do
File.stub(:exists?).and_return(true)
expect {
subject.create('whatever')
}.to raise_error("One error")
end
it "should has to exists the other filename" do
File.stub(:exists?).and_return(false)
expect {
subject.create('whatever.yaml')
}.to raise_error("Other error")
end
For the second spec (it "should has to exists the other filename") the File exists? stub raises the first check.
What is the best way to spec the two raises?