Sha256: a6352f96abb8343ebc99b2c4db10ea502b89f79bfbe671bcba7056b0a5d1102a

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

RSpec.describe Evil::Client::Middleware::StringifyJson do
  def update!(result)
    @result = result
  end

  let(:app) { double :app }

  before  { allow(app).to receive(:call) { |env| update!(env) } }
  subject { described_class.new(app).call(env) }

  context "with a body:" do
    let(:env) { { format: "json", body: { foo: :bar } } }

    it "stringifies a body" do
      subject
      expect(@result[:body_string]).to eq '{"foo":"bar"}'
    end

    it "sets content-type" do
      subject
      expect(@result[:headers]).to eq "content-type" => "application/json"
    end
  end

  context "when format is not json:" do
    let(:env) { { format: "form", body: { foo: :bar } } }

    it "does nothing" do
      subject
      expect(@result).to eq env
    end
  end

  context "with empty body:" do
    let(:env) { { format: "json", body: {} } }

    it "stringifies an empty body" do
      subject
      expect(@result[:body_string]).to eq "{}"
    end

    it "sets content-type" do
      subject
      expect(@result[:headers]).to eq "content-type" => "application/json"
    end
  end

  context "without a body:" do
    let(:env) { { format: "json" } }

    it "stringifies an empty body" do
      subject
      expect(@result[:body_string]).to eq "{}"
    end

    it "sets content-type" do
      subject
      expect(@result[:headers]).to eq "content-type" => "application/json"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
evil-client-0.3.1 spec/unit/evil/client/middleware/stringify_json_spec.rb
evil-client-0.3.0 spec/unit/evil/client/middleware/stringify_json_spec.rb
evil-client-0.2.3 spec/unit/evil/client/middleware/stringify_json_spec.rb
evil-client-0.2.2 spec/unit/evil/client/middleware/stringify_json_spec.rb
evil-client-0.2.1 spec/unit/evil/client/middleware/stringify_json_spec.rb