I 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 :
1 2 3 4 5 6 7 8 9 10 |
# 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.