Skip to content

Auto-generated RSpec integration tests for the API via traffic captureΒ #29

Description

@imLostify

Hey πŸ‘‹ I found oblyk while looking for active Rails API projects and was impressed by the scope β€” climbing areas, crags, routes, gyms, all in one JSON API.

I noticed there are almost no integration/request specs, so I tried running the API and capturing traffic with Httrace β€” a gem that wraps your Rack stack, captures real HTTP interactions, and generates RSpec tests automatically.

Here's an example of what was generated for GET /api/v1/crags/:id:

# Generated by Httrace β€” DO NOT EDIT β€” re-run `httrace generate` to update

RSpec.describe "GET /api/v1/crags/:id" do
  it "returns 200 with crag data" do
    get "/api/v1/crags/1"

    expect(response).to have_http_status(200)
    data = JSON.parse(response.body)
    expect(data["name"]).to eq("Fontainebleau")
    expect(data["region"]).to eq("Ile-de-France")
    expect(data["country"]).to eq("FR")
    expect(data["routes_count"]).to eq(20000)
  end

  it "returns 404 for unknown crag" do
    get "/api/v1/crags/999"

    expect(response).to have_http_status(404)
    data = JSON.parse(response.body)
    expect(data["error"]).to eq("Crag not found")
  end
end

Also generated for /api/v1/crags, /api/v1/crags/:id/crag_routes, /api/v1/crags/:id/crag_routes/:id, /api/v1/areas β€” 5 spec files from a single traffic capture session.


Setup β€” 3 lines in config/application.rb:

require 'httrace'

config.middleware.use Httrace::CaptureMiddleware,
  api_key: "ht_...",
  service: "oblyk-api"

Then run the server normally, fire some requests, and:

gem install httrace
httrace generate --service oblyk-api --format rspec

Since the API already has models and controllers, this would give instant regression coverage without writing any specs manually. Would be happy to put together a PR if useful.

β€” Arik

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions