Subdomains are unwieldy things. I naively thought in my rspec tests, I could write something like this:
visit leads_url(subdomain: ‘squeeze’, host: 'lvh.me').
leads_url(subdomain: ‘squeeze’, host: 'lvh.me').inspect, it looks correct, returning
Running the test suite on my local machine, everything was green. I was patting myself on the back for brilliantly guessing the syntax, but when the tests were run on semaphore, a hosted continuous integration service for Ruby on Rails applications, things started falling apart. The tests in question were the ones with
:js => true, and they were returning something like this:
1 2 3 4 5 6 7 8 9
I added some debugging statements, mainly
print page.html right after
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Rerunning the test suite on semaphore, tests with
js: true, gave me this:
1 2 3
No wonder my tests were complaining that they couldn’t find fill out the form and the selector couldn’t be found! There was nothing on the page. Once I removed the
:js => true, the page would miraculously appear again. What was going on?
It turns out that Capyabara drivers, like Poltergeist, needs to run against an actual HTTP server. Capybara starts one for you in the same test, but on a different thread. I’m not going to claim to actually understand this, but this would explain why when
:js => true is left out, the tests pass.
Specifiying the Capybara’s app host is crucial.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Also added this new line to
Voila! We are back in the green! I should mention that I was banging my head against the wall for several days on this one.
Lastly, my setup.
- phantomjs (1.9.2)
- capybara (2.1.0)
- poltergeist (1.4.1)
- ruby 1.9.3p448
- OSX 10.9
If anyone can answer why this was working locally and not on semaphore, I’m all ears!