From 0fe072c90a074478dbec7b6fb4b3614c6372eb5d Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 9 Sep 2019 16:49:06 +1000 Subject: [PATCH] fix: file upload spec --- .../consumer_with_file_upload_spec.rb | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/spec/features/consumer_with_file_upload_spec.rb b/spec/features/consumer_with_file_upload_spec.rb index 41687003..c8aa174b 100644 --- a/spec/features/consumer_with_file_upload_spec.rb +++ b/spec/features/consumer_with_file_upload_spec.rb @@ -32,12 +32,11 @@ let(:do_request) { connection.post { |req| req.body = payload } } - describe "when the content matches" do - - let(:body) do - "-------------RubyMultipartPost-05e76cbc2adb42ac40344eb9b35e98bc\r\nContent-Disposition: form-data; name=\"file\"; filename=\"text.txt\"\r\nContent-Length: 14\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\nThis is a file\r\n-------------RubyMultipartPost-05e76cbc2adb42ac40344eb9b35e98bc--\r\n\r\n" - end + let(:body) do + "-------------RubyMultipartPost-05e76cbc2adb42ac40344eb9b35e98bc\r\nContent-Disposition: form-data; name=\"file\"; filename=\"text.txt\"\r\nContent-Length: 14\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\n#{File.read(file_to_upload)}\r\n-------------RubyMultipartPost-05e76cbc2adb42ac40344eb9b35e98bc--\r\n" + end + describe "when the content matches" do it "returns the mocked response and verification passes" do file_upload_service. upon_receiving("a request to upload a file").with({ @@ -60,22 +59,15 @@ end describe "when the content does not match" do - - let(:body) do - "-------------RubyMultipartPost-05e76cbc2adb42ac40344eb9b35e98bc\r\nContent-Disposition: form-data; name=\"file\"; filename=\"TEXT.txt\"\r\nContent-Length: 14\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\nThis is a file\r\n-------------RubyMultipartPost-05e76cbc2adb42ac40344eb9b35e98bc--\r\n\r\n" - end - it "the verification fails" do file_upload_service. upon_receiving("a request to upload another file").with({ method: :post, path: '/files', - query: "foo=bar", - body: body, + body: body.gsub('text.txt', 'wrong.txt'), headers: { "Content-Type" => Pact.term(/multipart\/form\-data/, "multipart/form-data; boundary=-----------RubyMultipartPost-05e76cbc2adb42ac40344eb9b35e98bc"), - "Content-Length" => Pact.like("299"), - "Missing" => "header" + "Content-Length" => Pact.like("299") } }). will_respond_with({