The HTML page is supposed to have the following code:
<div class="user-image" style="background-image:url(/images/user_image.jpg)">
How would you check for this using Capybara and RSpec?
Presumably, you are trying to verify that this div uses the specified background image. I would probably do something like this:
it "has a user image" do
page.should have_selector('div.user-image')
end
it "displays the user image" do
page.find('div.user-image')['style'].should == 'background-image:url(/images/user_image.jpg)'
end
RSpec, however, is likely the wrong tool for the job. Consider using Cucumber for tests like this.
Capybara and Selenium allow to run javascript in the browser and return the result
here is how:
page.execute_script 'return $("div.user-image").css("background-image");'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With