I have this sinatra app test where I downloaded a file by hand from the app and stored it in the test area. I then have my test program download the same file, save it and compare the two. The test seems to fail because the one downloaded by hand has newlines of the form "\r\n" whereas the one that the test program downloads using rack/test has newlines of the form "\r\r\n" Any obvious insights from my test code below ? Thanks .. require ''fileutils'' require ''test/unit'' require ''rack/test'' class MyAppTest < Test::Unit::TestCase include Rack::Test::Methods def app Sinatra::Application end def test_recreate_csv csv_path = File.dirname(__FILE__) + ''/csv_files/web_test_file.csv'' csf = File.open(csv_path,''w''){|f| f.write(last_response.body)} downloaded_csv_path = File.dirname(__FILE__) + ''/csv_files/ downloaded_file.csv'' assert FileUtils.identical?(csv_path, downloaded_csv_path) end end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Luis Lavena
2012-May-07 14:27 UTC
Re: not sure why download csv file test fails on windows
Hello, On Monday, May 7, 2012 10:48:35 AM UTC-3, Jedrin wrote:> > > The test seems to fail because the one downloaded by hand has > newlines of the form > "\r\n" whereas the one that the test program downloads using rack/test > has newlines of the form > "\r\r\n" > >If you want identical files then you should tell Ruby to open your file in a binary mode.> Any obvious insights from my test code below ? > > Thanks .. >> csf = File.open(csv_path,''w''){|f| f.write(last_response.body)} > >Change the mode from ''w'' to ''wb'' (write binary) Also, don''t forget to close the file (csf.close) as you keep that open in your test, leaking file handlers. -- Luis Lavena -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/oyWnXIhZVRgJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.