# frozen_string_literal: true # spec/spec_helper.rb ENV['RACK_ENV'] = 'test' # Set environment to test, important for Sinatra config require 'rack/test' require 'rspec' # For RSpec require 'json' # Required if you're testing JSON responses # --- CRITICAL APP LOADING --- # Adjust this path if your app.rb is NOT directly in the parent directory of 'spec/' # Example: If app.rb is in `src/app.rb`, use `require_relative '../src/app.rb'` require_relative '../app' # Configure Rack::Test RSpec.configure do |config| config.include Rack::Test::Methods # Include Rack::Test methods # This is *THE* most critical part for Sinatra tests. # It must return the instance of your Sinatra application. def app # Option 1: For classic style Sinatra apps (most common for small apps) # where you just have `get '/' do ... end` directly in app.rb Sinatra::Application # Option 2: For modular Sinatra apps (if your app.rb defines a class) # class MyApp < Sinatra::Base; ... end # If this is your case, uncomment the line below and replace 'MyApp' # MyApp.new end end