Testing the multi-subdomain Rails app
Robb Shecter Jun 8 Originally published at dogsnog.blog on Jun 08, 2018
I saw that, and understood the frustration. Integration tests (“request specs” or “feature specs“) are built on a stack of frequently changing libraries and shifting API’s. And the recipe for subdomain-aware testing isn’t documented in any particular tool’s notes. So here’s my working configuration for Rails 5.2.0, in mid-2018.
The goal: feature- and request-specs to specific hostnames
I’m creating a set of sites with laws for each state:
And there’s one “organizational home site”:
…with pages like About and Contact Us. I want to write request specs like these:
...and feature specs like this:
Spec helpers: get_path and visit_path
I’ve written two helpers, seen in the examples above:
get_path for request specs, and
visit_path for feature specs.
get_path turned out to need very little code. However, it was difficult to figure out because it required reaching through RSpec, the Rails “integration” test support (to get the
headers: parameter) and Rails APIs to determine that
host: is the correct header to supply:
The equivalent code for feature specs, which are based on Capybara, requires a bit more work:
I simply place these helpers in my
This week I want to talk about something that I have used for a excuse quite a few times. Before I finally started getting a schedule going. And that is saying the excuse I don’t have time to learn blank.