Cheers Graham. This is brilliant. Many thanks for taking the time for a comprehensive reply :)
Exactly what you say on the rigidity of the test. That it's a CSV and has a certain number of rows should suffice right now. Hopefully this is another hurdle knocked out of the way towards keeping good test coverage, and who knows might even help others here with luck. Shows that there's plenty of helpful people here if there's others with questions I guess too? > > Given that the ActiveAdmin 'controller' method 'export' exports a csv > > and it has been called in a http request, > > And I'm using TestUnit > > As A Developer, I want to assert that the file 'export.txt' is created > > and sent as a http response > > You'll probably use `send_data` inside your controller action. It'll set > a Content-Type header, so check for that. > > No need to couple yourself to the implementation, check files on disk, > etc. Try and check what the action is supposed to do, not that it's done > half the job. > > test 'should export a CSV file' do > # appropriate setup to create a collection_of_stuff > get :export, appropriate: params, go: here > assert 'text/csv', response.header['Content-Type'] > rows = CSV.parse(response.body) > assert_equal collection_of_stuff.size, rows.size > assert_equal 'Contents of column 1', rows.first[0] > end > > Don't get too rigid with what your asserts check for; I'd just check that > it looked like the right kind of data was in it (i.e. number of rows, and > probably just that the right stuff was in the first column; detailed > testing of what's in the CSV is something I'd only unit test at the model > level, and only then if it was complicated [i.e. only if I was likely to > get it wrong without testing it]). -- You received this message because you are subscribed to the Google Groups "NWRUG" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/nwrug-members. For more options, visit https://groups.google.com/groups/opt_out.
