Maybe it’s because we’re using Capybara not Webrat, or maybe it’s because we did something wrong, but we couldn’t get HolyGrail to work right. However, a quick peek at the source code gave us a few clues. We pulled out and tweaked the following:
def js(code) @__page ||= Harmony::Page.new(page.body.to_s) @__page.execute_js(code) end
Then /^the page is titled "([^\"]*)"$/ do |title| js('document.title').should == title end
It was actually pretty exciting when we first saw that working! On to something more meaningful …
Ensuring the box disappears was a little more tricky. For the moment we’re just checking that the contents becomes empty.
Then 'the box should be hidden' do js("$('.hide_box')").html.should be_nil end
Sure enough, when we plug in the unobtrusive jQuery code to bind the click and remove the box, the feature passes! Alright, this is a very small step down a long road, but to me it is very exciting indeed!
@__page cached copy gets refreshed.
An important next step is make it a proper integration test, interacting with the full stack, such as clicking something which triggers an AJAX request to the server which must run a bit of code and send the response back to the page. I can foresee this presenting some challenges, we’ll see!
Exciting things are happening, and this is just the beginning! Web development these days is all about standing on the shoulders of giants. This is only possible thanks to the great work already being done by Harmony, Johnson and SpiderMonkey. I’m hoping that other people will become inspired by the possibilities and take this further. Watch this space for more news!