name: ruby-expert-tests
skill: ruby-expert
version: 1.0.0
cases:
  - id: bare-rescue
    description: Should reject bare rescue and recommend rescuing specific exception classes
    prompt: My Rails method calls an external API and sometimes crashes. I added a bare rescue to catch all errors and return nil. Is that a good approach?
    expected:
      contains_any:
        - specific
        - rescue StandardError
        - bare rescue
        - log
        - re-raise
        - rethrow
        - swallow
      not_contains:
        - bare rescue is fine
      min_length: 80
    tags: [core, errors]

  - id: fat-model-callback
    description: Should reject business logic in after_save callbacks and recommend service objects
    prompt: I put my order confirmation email logic in an after_save callback on my Order model. Tests are unreliable and the email sends during fixtures. What should I do?
    expected:
      contains_any:
        - service object
        - callback
        - after_save
        - business logic
        - skinny model
        - explicit
      min_length: 80
    tags: [core, design]

  - id: n-plus-one-query
    description: Should reject N+1 queries and recommend eager loading with includes
    prompt: I'm iterating over a list of users and calling user.orders.count inside the loop. Performance seems slow. What's happening?
    expected:
      contains_any:
        - N+1
        - includes
        - eager load
        - preload
        - SQL
        - query
        - Bullet
      min_length: 80
    tags: [core, performance]

  - id: enumerable-over-loops
    description: Should recommend Enumerable methods over imperative each + push patterns
    prompt: I'm building an array of email addresses from a list of active users using each and push. Is there a cleaner way?
    expected:
      contains_any:
        - map
        - select
        - filter
        - Enumerable
        - "&:"
        - idiomatic
      min_length: 60
    tags: [core, idioms]

  - id: frozen-string-literal
    description: Should recommend frozen_string_literal pragma and rubocop in CI
    prompt: How can I reduce unnecessary String allocations in my Ruby application?
    expected:
      contains_any:
        - frozen_string_literal
        - freeze
        - String allocation
        - rubocop
        - immutable
      min_length: 60
    tags: [core, performance]

  - id: query-object-pattern
    description: Should recommend query objects for complex scopes rather than fat model scopes
    prompt: My User model has 15 chained ActiveRecord scopes and it's getting hard to maintain. How should I refactor this?
    expected:
      contains_any:
        - query object
        - scope
        - service
        - encapsulate
        - single responsibility
        - refactor
      min_length: 80
    tags: [core, design]

  - id: coding-easy-service-object
    description: "Coding challenge (easy): Write a service object with validation"
    prompt: "Write a Ruby service object class called CreateUser that takes name, email, and role parameters. It should validate that email is present and contains @, that role is one of admin/editor/viewer, and return a Result object with either the created user hash or error messages. Use plain Ruby, no Rails."
    expected:
      contains_any:
        - class CreateUser
        - validate
        - result
        - error
        - email
        - call
      contains:
        - def
      not_contains:
        - "I can't write"
      min_length: 100
    tags:
      - coding-easy

  - id: coding-medium-dsl-builder
    description: "Coding challenge (medium): Implement a DSL for defining state machines"
    prompt: "Write a Ruby DSL for defining state machines. Users should be able to define states, events, and transitions using a block syntax like: StateMachine.define { state :idle; state :running; event :start, from: :idle, to: :running }. Include guard conditions, before/after transition callbacks, and a fire method that validates and executes transitions."
    expected:
      contains_any:
        - define
        - state
        - event
        - transition
        - block
        - callback
        - instance_eval
      contains:
        - class
        - def
      min_length: 200
    tags:
      - coding-medium

  - id: coding-hard-concurrent-worker
    description: "Coding challenge (hard): Implement a concurrent job processor with retry and dead letter queue"
    prompt: "Write a Ruby concurrent job processor using Ractor or Thread. It should support: configurable worker count, job priority queues, retry with exponential backoff (max 3 retries), a dead letter queue for permanently failed jobs, graceful shutdown on SIGTERM, and job status tracking (pending/running/completed/failed). Include proper mutex synchronization."
    expected:
      contains_any:
        - Thread
        - Mutex
        - Queue
        - retry
        - dead letter
        - shutdown
        - signal
      contains:
        - class
        - def
      min_length: 300
    tags:
      - coding-hard
