Method: Mock5#mock

Defined in:
lib/mock5.rb

#mock(endpoint = nil) { ... } ⇒ Mock5::Api

Generates a new API

Examples:

my_mock_api = Mock5.mock("http://example.com") do
  get "posts" do
    [
      {id: 1, body: "a post body"},
      {id: 2, body: "another post body"}
    ].to_json
  end

  post "posts" do
    halt 201, "The post was created successfully"
  end
end

Parameters:

  • endpoint (String) (defaults to: nil)

    a url of the API service endpoint to mock. Should only include hostname and schema.

Yields:

  • a block to define behavior using Sinatra API

Returns:



40
41
42
# File 'lib/mock5.rb', line 40

def mock(endpoint=nil, &block)
  Api.new(endpoint, &block)
end