Sha256: 62c7f0d50eb5be61496ecc8247623c6b7b15f19ba1f08e10681d54c402d047df

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

RSpec.describe HTTP::FormData::Part do
  let(:body)     { "" }
  let(:opts)     { {} }
  subject(:part) { HTTP::FormData::Part.new(body, opts) }

  describe "#size" do
    subject { part.size }

    context "when body given as a String" do
      let(:body) { "привет мир!" }
      it { is_expected.to eq 20 }
    end
  end

  describe "#to_s" do
    subject! { part.to_s }

    context "when body given as String" do
      let(:body) { "привет мир!" }
      it { is_expected.to eq "привет мир!" }

      it "rewinds content" do
        content = part.read
        expect(part.to_s).to eq content
        expect(part.read).to eq content
      end
    end
  end

  describe "#read" do
    subject { part.read }

    context "when body given as String" do
      let(:body) { "привет мир!" }
      it { is_expected.to eq "привет мир!" }
    end
  end

  describe "#rewind" do
    context "when body given as String" do
      let(:body) { "привет мир!" }

      it "rewinds the underlying IO object" do
        part.read
        part.rewind
        expect(part.read).to eq "привет мир!"
      end
    end
  end

  describe "#filename" do
    subject { part.filename }

    it { is_expected.to eq nil }

    context "when it was given with options" do
      let(:opts) { { :filename => "foobar.txt" } }
      it { is_expected.to eq "foobar.txt" }
    end
  end

  describe "#content_type" do
    subject { part.content_type }

    it { is_expected.to eq nil }

    context "when it was given with options" do
      let(:opts) { { :content_type => "application/json" } }
      it { is_expected.to eq "application/json" }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
http-form_data-2.1.1 spec/lib/http/form_data/part_spec.rb
http-form_data-2.1.0 spec/lib/http/form_data/part_spec.rb