[rspec-users] The problem with learning RSpec

Bill Kocik bkocik at gmail.com
Thu Jun 18 14:05:40 EDT 2009

Thanks for the encouragement, Ben. :)

On Thu, Jun 18, 2009 at 1:36 PM, Ben Mabey <ben at benmabey.com> wrote:

>> Then /^I should find "(.+)" in JSON/ do |xpath|
>>  json_hash = JSON.parse(@response.body.gsub(/^#{JSON_CALLBACK}\((.*)\)/, '\1'))
>>  xmldoc = Nokogiri::XML(json_hash.to_xml)
>>  xpath.gsub!('_', '-') # in XML, underscores will be dashes.
>>  xpath = "./hash" + xpath unless xpath =~ /^\/\//
>>  assert !xmldoc.xpath(xpath).blank?
>> end
> I probably would of done this in RSpec instead of Cucumber.  Then I would manually tested in a browser.. since you are going to want to do that anyways.  I take this stance quite a bit as I feel adding Selenium (or another automated browser solution) can potentially add much more of a maintenance burden than webrat in :rails mode.

In this particular project, all the JS is written by my partner (I'm
completely JS-clueless). Having a bunch of lines in my cucumber tests
validating everything that should be in the JSON structure my
controllers generate in order for the JS to work (and I have a lot of
them) is the best way for me to be able to tell if I've broken
something (and if I have, in what way I broke it). If the page doesn't
work, I will likely have difficulty figuring out why - unless Cucumber
is there to tell me it didn't find "/response/statusCode" in the JSON
like it should have, then I know what to fix. :)

Though I suppose there's probably no reason RSpec couldn't have done
the same thing. I haven't used it yet in this project.

Bill Kocik


More information about the rspec-users mailing list