Sha256: 21420eaac72553e60f27f86ed31f7353713c4db2be50aa1e3815121e5673b39e

Contents?: true

Size: 1.59 KB

Versions: 40

Compression:

Stored size: 1.59 KB

Contents

require "spec_helper"

describe Manticore::StubbedResponse do
  subject {
    Manticore::StubbedResponse.stub(
      body: "test body",
      code: 200,
      headers: {
        "Content-Type" => "text/plain",
        "Set-Cookie" => ["k=v; path=/; domain=localhost", "k=v; path=/sub; domain=sub.localhost", "k2=v2;2 path=/; domain=localhost"],
      },
      cookies: {"test" => Manticore::Cookie.new(name: "test", value: "something", path: "/")},
    ).call
  }

  it { is_expected.to be_a Manticore::Response }
  its(:body) { is_expected.to eq "test body" }
  its(:code) { is_expected.to eq 200 }

  it "persists the set headers" do
    expect(subject.headers["content-type"]).to eq "text/plain"
  end

  it "sets content-length from the body" do
    expect(subject.headers["content-length"]).to eq "9"
  end

  it "persists cookies passed as explicit cookie objects" do
    expect(subject.cookies["test"].first.value).to eq "something"
  end

  it "calls on_success handlers" do
    called = false
    Manticore::StubbedResponse.stub.on_success { |resp| called = true }.call
    expect(called).to be true
  end

  it "should persist cookies passed in set-cookie" do
    expect(subject.cookies["k"].map(&:value)).to match_array ["v", "v"]
    expect(subject.cookies["k"].map(&:path)).to match_array ["/", "/sub"]
    expect(subject.cookies["k"].map(&:domain)).to match_array ["localhost", "sub.localhost"]
    expect(subject.cookies["k2"].first.value).to eq "v2"
  end

  it "passes bodies to blocks for streaming reads" do
    total = ""; subject.body { |chunk| total << chunk }
    expect(total).to eq("test body")
  end
end

Version data entries

40 entries across 40 versions & 5 rubygems

Version Path
manticore-0.9.1-java spec/manticore/stubbed_response_spec.rb
manticore-0.9.0-java spec/manticore/stubbed_response_spec.rb
manticore-0.8.0-java spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/spec/manticore/stubbed_response_spec.rb
manticore-0.7.1-java spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/spec/manticore/stubbed_response_spec.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/spec/manticore/stubbed_response_spec.rb