Skip to content

feat: access Roda routes directly in console via Rack Test #953

@jaredcwhite

Description

@jaredcwhite

We have a --server-config option for the console command to load the full Roda stack, but we don't actually have an obvious way of testing routes in the console. I spent some time playing around with getting Rack Test loaded, and it turns out to be surprisingly easy!

gem "rack-test" # add this to your Gemfile

# then when you run `bin/bridgetown console --server-config`:

require "rack/test"
IRB::ExtendCommandBundle.include Rack::Test::Methods
def app = RodaApp.app

get '/'

doc = Nokolexbor::Document.parse get("/").body
doc.query_selector("h2").inner_html # inspect your response

get("/preview/docs/_docs%2Findex.md").body # => test a dynamic server route

I think what we should do is add conditional code in the console command for the server boot where, if the "rack-test" gem is available, we set up these commands. If not, no worries! Then we can add documentation for folks to add "rack-test", and also it can be part of our overall Minitest bundled configuration aka #570.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions