spec/hayabusa_spec.rb in hayabusa-0.0.17 vs spec/hayabusa_spec.rb in hayabusa-0.0.18

- old
+ new

@@ -87,31 +87,44 @@ # end #end it "should be able to upload files" do $testmodes.each do |tdata| - fpath = "#{File.realpath(File.dirname(__FILE__))}/../pages/spec_thread_joins.rhtml" + fpaths = { + "fpath1" => "#{File.realpath(File.dirname(__FILE__))}/../pages/spec_thread_joins.rhtml", + "fpath2" => "#{File.realpath(File.dirname(__FILE__))}/test_upload.xlsx" + } res = tdata[:http].post_multipart(:url => "#{tdata[:path_pre]}spec_vars_post_fileupload.rhtml", :post => { - "testfile" => { + "testfile1" => { :filename => "spec_thread_joins.rhtml", - :fpath => fpath + :fpath => fpaths["fpath1"] + }, + "testfile2" => { + :filename => "test_upload.xlsx", + :fpath => fpaths["fpath2"] } }) - data = JSON.parse(res.body) - - if data["testfile"] != File.read(fpath) - File.open("/tmp/hayabusa_spec_testfile1", "w") do |fp| - fp.puts("Class: #{data["testfile"].class.name}") - fp.write(data["testfile"]) - end + 1.upto(2) do |count| + data = Marshal.load(res.body) - File.open("/tmp/hayabusa_spec_testfile2", "w") do |fp| - fp.write(File.read(fpath)) + if count != 2 + if data["testfile#{count}"]["val"] != File.read(fpaths["fpath#{count}"]) + File.open("/tmp/hayabusa_spec_testfile#{count}_1", "w") do |fp| + fp.puts("Class: #{data["testfile#{count}"].class.name}") + fp.write(data["testfile#{count}"]) + end + + File.open("/tmp/hayabusa_spec_testfile#{count}_2", "w") do |fp| + fp.write(File.read(fpaths["fpath#{count}"])) + end + + raise "Expected uploaded data for mode '#{tdata[:name]}' to be the same but it wasnt:\n\"#{data["testfile#{count}"]}\"\n\n\"#{File.read(fpaths["fpath#{count}"])}\"" + end end - raise "Expected uploaded data for mode '#{tdata[:name]}' to be the same but it wasnt:\n\"#{data["testfile"]}\"\n\n\"#{File.read(fpath)}\"" + raise "Expected 'testfile' class to be 'Hayabusa::Http_session::Post_multipart::File_upload' in mode '#{tdata[:name]}' but it wasnt: '#{data["testfile#{count}"]["class"]}'." if data["testfile#{count}"]["class"] != "Hayabusa::Http_session::Post_multipart::File_upload" end end end if false