File: form_data_spec.rb

package info (click to toggle)
ruby-http-form-data 1.0.1%2Bgemwatch-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 176 kB
  • ctags: 46
  • sloc: ruby: 366; makefile: 3
file content (48 lines) | stat: -rw-r--r-- 1,420 bytes parent folder | download
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
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(:gemspec) { HTTP::FormData::File.new "gemspec" }
      let(:params)  { { :foo => :bar, :baz => gemspec } }
      it { is_expected.to be_a HTTP::FormData::Multipart }
    end

    context "when form has file in an array param" do
      let(:gemspec) { HTTP::FormData::File.new "gemspec" }
      let(:params)  { { :foo => :bar, :baz => [gemspec] } }
      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