1

I am building a test using rspec. I have an image tag generated automatically, but I need to run the test by comparing if the URL generated by my helper is the one I need. it is an URL from googlemaps' API.

Here is my code:

within ("data-hook.product_map") do
    should have_css('img src.http://maps.google.com/maps/api/staticmap?size=338x244&maptype=roadmap&sensor=false&markers=23.129,-82.38&center=23.129,-82.38&zoom=9')
end

The error I get when I run the test is:

Nokogiri::CSS::SyntaxError: unexpected '//' after ':'

Is there a way I can compare this string, or a way around this? Of course I need to run the tests anyway.

the Tin Man
  • 155,156
  • 41
  • 207
  • 295
aledustet
  • 973
  • 2
  • 13
  • 39

1 Answers1

1

have_css expects a valid css selector, according to w3schools the format is:

Style <a> elements with a target="_blank":

a[target=_blank]
{ 
  background-color:yellow;
}

so try:

within ("data-hook.product_map") do
    should have_css('img[src=http://maps.google.com/maps/api/staticmap?size=338x244&maptype=roadmap&sensor=false&markers=23.129,-82.38,blue&center=23.129,-82.38&zoom=9]')
end

Edit

According to CSS attribute selectors: The rules on quotes (", ' or none?) you should put quotes around the value:

within ("data-hook.product_map") do
    should have_css('img[src="http://maps.google.com/maps/api/staticmap?size=338x244&maptype=roadmap&sensor=false&markers=23.129,-82.38,blue&center=23.129,-82.38&zoom=9"]')
end
Community
  • 1
  • 1
Uri Agassi
  • 36,078
  • 12
  • 73
  • 92
  • It throws another error now the equal in the hash doesn't belongs there **Nokogiri::CSS::SyntaxError: unexpected ':' after '[:equal, "http"]'** is the error now – aledustet Mar 04 '14 at 20:32
  • Now we are talking, worked like a charm, thank you for your time – aledustet Mar 05 '14 at 15:41