Sha256: e97a5203d3dbb5e1241d298831af27992a439d7f89dddf2203db023db91d1f7c

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

RSpec.describe "operation with path" do
  # see Test::Client definition in `/spec/support/test_client.rb`
  before do
    class Test::Client < Evil::Client
      operation do
        http_method :get
        path { "users" }
        response 200
      end

      operation :find_users

      operation :find_user do
        path { |id:, **| "users/#{id}" }
      end

      operation :login do |settings|
        path { "login/#{settings.token}" }
      end
    end

    stub_request :get, //
  end

  let(:client) { Test::Client.new "foo", user: "bar", version: 3, token: "baz" }

  it "uses default path" do
    client.operations[:find_users].call

    expect(a_request(:get, "https://foo.example.com/api/v3/users"))
      .to have_been_made
  end

  it "uses request options" do
    client.operations[:find_user].call(id: 42)

    expect(a_request(:get, "https://foo.example.com/api/v3/users/42"))
      .to have_been_made
  end

  it "uses settings" do
    client.operations[:login].call

    expect(a_request(:get, "https://foo.example.com/api/v3/login/baz"))
      .to have_been_made
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
evil-client-0.2.3 spec/features/operation_with_path_spec.rb
evil-client-0.2.2 spec/features/operation_with_path_spec.rb
evil-client-0.2.1 spec/features/operation_with_path_spec.rb