Overactive Vocabulary

When In Doubt, Ameliorate

RSS

Enabling Fields With Capybara's Rack-test Driver

I was writing a Cucumber test for Spreedly today, and was getting frustrated when the fields I was filling in were silently being ignored. It turns out that when using the rack-test driver with Capybara, it (rightly so) will not submit any form fields marked as disabled. This is great and all, but since these form fields are normally enabled via Javascript as the form is interacted with, I was stumped. How to get them to be passed without monkeying around with a driver that does full Javascript?

Turns out it is possible, but you have to dig pretty deeply into Capybara’s guts to make it work. If you’re using Cucumber, just drop this into your support directory:

Then use it by calling it within a step definition with whatever fields you want enabled.

It should also adapt easily to non-Cucumber environments; just make it accessible and call it alongside the code that attempts to set the fields.

Hopefully this saves someone else some time; I’ll never get that half-hour back myself!