{"id":116,"date":"2009-07-27T21:34:46","date_gmt":"2009-07-28T03:34:46","guid":{"rendered":"http:\/\/www.pervasivecode.com\/blog\/?p=116"},"modified":"2009-07-27T22:58:52","modified_gmt":"2009-07-28T04:58:52","slug":"a-cucumber-step-to-test-for-a-ym4r-google-map","status":"publish","type":"post","link":"http:\/\/www.pervasivecode.com\/blog\/2009\/07\/27\/a-cucumber-step-to-test-for-a-ym4r-google-map\/","title":{"rendered":"A Cucumber step to test for a YM4R Google Map"},"content":{"rendered":"<p>I had some problems with a view in a Rails app that was conditionally hiding a Google Map that was generated using the <a href=\"http:\/\/ym4r.rubyforge.org\/\">YM4R<\/a> plugin. I don&#8217;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.<\/p>\n<p>Here&#8217;s the Cucumber step implementation I wrote.<br \/>\n<!--more--><br \/>\nPut this in a new file called features\/step_definitions\/ym4r_gm_steps.rb :<\/p>\n<pre>\r\n# Steps for use with the ym4r_gm plugin\r\n\r\nThen \/^I should see a Google Map$\/i do\r\n  within 'head' do\r\n    ['http:\/\/maps.google.com\/maps', '\/javascripts\/ym4r-gm.js'].each do |js_url|\r\n      assert_have_xpath \"\/\/script[starts-with(@src, '#{js_url}')]\"\r\n    end\r\n  end\r\n  assert_select '#map_div'\r\nend\r\n<\/pre>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;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 &hellip; <a href=\"http:\/\/www.pervasivecode.com\/blog\/2009\/07\/27\/a-cucumber-step-to-test-for-a-ym4r-google-map\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;A Cucumber step to test for a YM4R Google Map&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59,20,30],"tags":[],"class_list":["post-116","post","type-post","status-publish","format-standard","hentry","category-google-maps","category-ruby-on-rails","category-testing"],"_links":{"self":[{"href":"http:\/\/www.pervasivecode.com\/blog\/wp-json\/wp\/v2\/posts\/116"}],"collection":[{"href":"http:\/\/www.pervasivecode.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.pervasivecode.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.pervasivecode.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.pervasivecode.com\/blog\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":7,"href":"http:\/\/www.pervasivecode.com\/blog\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":145,"href":"http:\/\/www.pervasivecode.com\/blog\/wp-json\/wp\/v2\/posts\/116\/revisions\/145"}],"wp:attachment":[{"href":"http:\/\/www.pervasivecode.com\/blog\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.pervasivecode.com\/blog\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.pervasivecode.com\/blog\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}