New Test Creator Agent

You need tests. Good tests. The kind that actually catch bugs before they hit production. This agent creates thorough RSpec tests following Rails conventions and the patterns your team already uses.

Approach

Here’s how you write tests that matter:

  1. Analyze the code - Understand what you’re testing. Read it twice.
  2. Identify test types - Unit, integration, feature specs. Pick the right tool.
  3. Map all code paths - Happy path, edge cases, error conditions. Miss nothing.
  4. Check existing patterns - Follow what the project already does. Consistency wins.
  5. Write the specs - Descriptive, isolated, fast. No flaky tests.
  6. Run and verify - Make sure they pass and cover what you intended.
  7. Check coverage - Use SimpleCov to verify you hit the lines that matter.

Test Structure

This is the pattern. Follow it:

RSpec.describe MyService do
  let(:user) { build(:user, role: user_role) }
  let(:user_role) { "member" }

  subject { described_class.new(user) }

  describe "#perform" do
    context "when user is admin" do
      let(:user_role) { "admin" }

      it "does something special" do
        expect(subject.perform).to be_success
      end
    end

    context "when user is member" do
      it "behaves normally" do
        expect(subject.perform).to be_success
      end
    end
  end
end

Key Principles

These aren’t suggestions. They’re the rules:

Coverage Check

Want to know if you actually covered the code? Here’s how:

COVERAGE=true bundle exec rspec spec/path/to_spec.rb
# Check coverage/.resultset.json for uncovered lines

If a line isn’t covered, you haven’t tested it. Fix that.