A Cucumber step to test for a YM4R Google Map
27 07 2009I had some problems with a view in a Rails app that was conditionally hiding a Google Map that was generated using the YM4R plugin. I don’t usually test views in unit tests, and this logic depended on a particular situation with the data behind the view, so I decided that this would be a good candidate for a Cucumber feature.
Here’s the Cucumber step implementation I wrote.
Put this in a new file called features/step_definitions/ym4r_gm_steps.rb :
# Steps for use with the ym4r_gm plugin
Then /^I should see a Google Map$/i do
within 'head' do
['http://maps.google.com/maps', '/javascripts/ym4r-gm.js'].each do |js_url|
assert_have_xpath "//script[starts-with(@src, '#{js_url}')]"
end
end
assert_select '#map_div'
end
This assumes that you let the plugin installer put the .js file in the default location, and that you have your Google Map inside #map_div.





