Sha256: 5129e2e215686204c4010d9468da21b3d6faf02a23f58e43c08629cdaa113432

Contents?: true

Size: 1.49 KB

Versions: 7

Compression:

Stored size: 1.49 KB

Contents

RSpec.describe Evil::Client::Middleware::StringifyMultipart::Part do
  let(:file)    { StringIO.new "Hello!" }
  let(:type)    { MIME::Types["text/html"].first }
  let(:charset) { "utf-8" }
  let(:part) do
    described_class.new(file: file, type: type, charset: charset)
  end

  subject { part.to_s }

  shared_examples :building_part do
    it "includes content disposition" do
      expect(subject).to include \
        'Content-Disposition: form-data; name="AttachedFile"; filename='
    end

    it "includes content type" do
      expect(subject).to include "Content-Type: text/html; charset=utf-8"
    end

    it "includes content" do
      expect(subject).to include "Hello!"
    end
  end

  context "with a name" do
    let(:part) { described_class.new(file: file, name: "UploadedFile") }

    it "includes part name" do
      expect(subject).to include 'name="UploadedFile"'
    end
  end

  context "with a filename" do
    let(:part) { described_class.new(file: file, filename: "weird_thing.json") }

    it "includes part name" do
      expect(subject).to include 'filename="weird_thing.json"'
    end
  end

  context "from file" do
    let(:file) { instance_double ::File, path: "foo/bar.html", read: "Hello!" }
    it_behaves_like :building_part

    it "includes filename" do
      expect(subject).to include 'filename="bar.html"'
    end
  end

  context "from io" do
    it_behaves_like :building_part
  end

  context "from text" do
    let(:file) { "Hello!" }
    it_behaves_like :building_part
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
evil-client-0.3.3 spec/unit/evil/client/middleware/stringify_multipart/part_spec.rb
evil-client-0.3.2 spec/unit/evil/client/middleware/stringify_multipart/part_spec.rb
evil-client-0.3.1 spec/unit/evil/client/middleware/stringify_multipart/part_spec.rb
evil-client-0.3.0 spec/unit/evil/client/middleware/stringify_multipart/part_spec.rb
evil-client-0.2.3 spec/unit/evil/client/middleware/stringify_multipart/part_spec.rb
evil-client-0.2.2 spec/unit/evil/client/middleware/stringify_multipart/part_spec.rb
evil-client-0.2.1 spec/unit/evil/client/middleware/stringify_multipart/part_spec.rb