Use Case
RSpec Fixtures with MockHero
spec_helper.rb
require "net/http"
require "json"
RSpec.configure do |config|
config.before(:suite) do
body = {
seed: 1,
tables: [
{ name: "users", count: 20, fields: [
{ name: "id", type: "uuid" },
{ name: "email", type: "email" }
]},
{ name: "orders", count: 80, fields: [
{ name: "id", type: "uuid" },
{ name: "user_id", type: "ref", ref: "users.id" },
{ name: "total", type: "price" }
]}
]
}
res = Net::HTTP.post(
URI("https://api.mockhero.dev/api/v1/generate"),
body.to_json,
"Content-Type" => "application/json",
"x-api-key" => ENV["MOCKHERO_API_KEY"]
)
data = JSON.parse(res.body)
User.insert_all(data["users"])
Order.insert_all(data["orders"])
end
end
Get Started
M
MockHero Team
Guides and tutorials for generating realistic test data with the MockHero API.
Start generating test data for free
1,000 rows/month on the free tier. No credit card required.
Get Your API Key