Sha256: 1453a1badbed84006e296cfd609fd5b369e2c125686098f8b8d06ac06c988a36

Contents?: true

Size: 1.45 KB

Versions: 14

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

RSpec.describe HTTP::FormData do
  describe ".create" do
    subject { HTTP::FormData.create params }

    context "when form has no files" do
      let(:params) { { :foo => :bar } }
      it { is_expected.to be_a HTTP::FormData::Urlencoded }
    end

    context "when form has at least one file param" do
      let(:file) { HTTP::FormData::File.new(fixture("the-http-gem.info").to_s) }
      let(:params) { { :foo => :bar, :baz => file } }
      it { is_expected.to be_a HTTP::FormData::Multipart }
    end

    context "when form has file in an array param" do
      let(:file) { HTTP::FormData::File.new(fixture("the-http-gem.info").to_s) }
      let(:params) { { :foo => :bar, :baz => [file] } }
      it { is_expected.to be_a HTTP::FormData::Multipart }
    end
  end

  describe ".ensure_hash" do
    subject(:ensure_hash) { HTTP::FormData.ensure_hash data }

    context "when Hash given" do
      let(:data) { { :foo => :bar } }
      it { is_expected.to eq :foo => :bar }
    end

    context "when #to_h given" do
      let(:data) { double(:to_h => { :foo => :bar }) }
      it { is_expected.to eq :foo => :bar }
    end

    context "when nil given" do
      let(:data) { nil }
      it { is_expected.to eq({}) }
    end

    context "when neither Hash nor #to_h given" do
      let(:data) { double }
      it "fails with HTTP::FormData::Error" do
        expect { ensure_hash }.to raise_error HTTP::FormData::Error
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/http-form_data-2.3.0/spec/lib/http/form_data_spec.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/http-form_data-2.3.0/spec/lib/http/form_data_spec.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/http-form_data-2.3.0/spec/lib/http/form_data_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/http-form_data-2.3.0/spec/lib/http/form_data_spec.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/http-form_data-2.3.0/spec/lib/http/form_data_spec.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/http-form_data-2.3.0/spec/lib/http/form_data_spec.rb
direct7-0.0.11 vendor/bundle/ruby/2.7.0/gems/http-form_data-2.3.0/spec/lib/http/form_data_spec.rb
http-form_data-2.3.0 spec/lib/http/form_data_spec.rb
http-form_data-2.2.0 spec/lib/http/form_data_spec.rb
http-form_data-2.1.1 spec/lib/http/form_data_spec.rb
http-form_data-2.1.0 spec/lib/http/form_data_spec.rb
http-form_data-2.0.0 spec/lib/http/form_data_spec.rb
http-form_data-2.0.0.pre2 spec/lib/http/form_data_spec.rb
http-form_data-2.0.0.pre1 spec/lib/http/form_data_spec.rb