Sha256: 7006e760be23ba0128f302f29a37de8f358f2dce697c5780bd676555a910ec81

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true
require "test_helper"

class ExecuteTest < Minitest::Test
  let(:request) { stub_everything }

  test "delegates to Request" do
    options = {}

    expected = {
      request_method: "get",
      url: "URL",
      data: "DATA",
      headers: "HEADERS",
      options: options.merge(Aitch.config.to_h)
    }

    Aitch::Request.expects(:new).with(expected).returns(request)

    Aitch.get("URL", "DATA", "HEADERS", options)
  end

  test "performs request" do
    Aitch::Request.stubs(:new).returns(request)
    request.expects(:perform)

    Aitch.get("URL")
  end
end

class ExecuteBangTest < Minitest::Test
  test "returns response when successful" do
    response = stub(error?: false)
    Aitch::Request.any_instance.stubs(:perform).returns(response)

    assert_equal response, Aitch.get!("URL")
  end

  test "raises when has errors" do
    response = stub(error?: true, error: "ERROR")
    Aitch::Request.any_instance.stubs(:perform).returns(response)

    assert_raises("ERROR") { Aitch.get!("URL") }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aitch-1.0.2 test/aitch/execute_test.rb
aitch-1.0.1 test/aitch/execute_test.rb
aitch-1.0.0 test/aitch/execute_test.rb