title: rspec test result from csv.read mocking file
body: <p>I'm using ruby 1.9 and I'm trying to do BDD. My first test 'should read in the csv' works, but the second where I require a file object to be mocked doesn't.</p>
  
  <p>Here is my model spec:</p>
  
  <pre><code>require 'spec_helper'
  
  describe Person do
    describe "Importing data" do
      let(:person) { Person.new }
  
      let(:data) { "title\tsurname\tfirstname\t\rtitle2\tsurname2\tfirstname2\t\r"}
      let(:result) {[["title","surname","firstname"],["title2","surname2","firstname2"]] }
  
      it "should read in the csv" do
        CSV.should_receive(:read).
          with("filename", :row_sep =&gt; "\r", :col_sep =&gt; "\t")
        person.import("filename")
      end
  
      it "should have result" do
        filename = mock(File, :exists? =&gt; true, :read =&gt; data)
        person.import(filename).should eq(result)
      end
    end
  end
  </code></pre>
  
  <p>Here is the code so far:</p>
  
  <pre><code>class Person &lt; ActiveRecord::Base
    attr_accessor :import_file
  
    def import(filename)
      CSV.read(filename, :row_sep =&gt; "\r", :col_sep =&gt; "\t")
    end
  end
  </code></pre>
  
  <p>I basically want to mock a file so that when the CSV method tries to read from the file it returns my data variable. Then I can test if it equals my result variable.</p>