require 'test_helper' class CreateReportTest < ActionDispatch::IntegrationTest should "successfully create a report" do records = [ OpenStruct.new(:one => 'one', :two => 'two'), OpenStruct.new(:one => 'a', :two => 'b') ] flexmock(records).should_receive(:where).and_return(records) flexmock(records).should_receive(:order).once.and_return(records) report = BasicReport.create flexmock(report).should_receive(:records).once.and_return(records) report.generate_csv! assert report.reload.csv.present? file = File.open report.csv.path assert_equal "col1,col2\none,two\na,b\n", file.read end end