1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
# 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
|