30 lines
1 KiB
Ruby
30 lines
1 KiB
Ruby
|
|
# frozen_string_literal: true
|
||
|
|
|
||
|
|
# test/test_helper.rb
|
||
|
|
ENV['RACK_ENV'] = 'test' # Set environment to test, important for Sinatra config
|
||
|
|
|
||
|
|
require 'rack/test'
|
||
|
|
require 'minitest/autorun' # For Minitest
|
||
|
|
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 'test/'
|
||
|
|
# Example: If app.rb is in `src/app.rb`, use `require_relative '../src/app.rb'`
|
||
|
|
require_relative '../app'
|
||
|
|
|
||
|
|
# Configure Rack::Test
|
||
|
|
module Rack::Test::Methods
|
||
|
|
def app
|
||
|
|
# This is *THE* most critical part for Sinatra tests.
|
||
|
|
# It must return the instance of your Sinatra application.
|
||
|
|
|
||
|
|
# 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
|