Skip to content

Instantly share code, notes, and snippets.

@aokolish
Created January 27, 2012 02:53
Show Gist options
  • Save aokolish/1686664 to your computer and use it in GitHub Desktop.
Save aokolish/1686664 to your computer and use it in GitHub Desktop.
testing elements that are revealed with css :hover
source 'http://rubygems.org'
gem 'rake'
gem 'rspec'
gem 'capybara'
gem 'selenium-webdriver'
gem 'capybara-webkit'
# download gist
# cd into it
# bundle to install dependancies
# run "rspec spec.rb" to run the spec
require 'rspec'
require 'capybara'
require 'capybara/dsl'
require 'capybara-webkit'
RSpec.configure do |config|
config.include Capybara::DSL
Capybara.run_server = false
Capybara.current_driver = :webkit
end
describe "The nav", :js => true do
it "hovering does not make dropdowns visible", :js => true do
visit "https://statraptor.com/"
page.should_not have_content "Logout"
add_logout
page.should have_content "Logout"
page.find('#nav li.last > a').trigger(:mouseover)
# unfortunately, the logout link is not "visible"
page.find("ul.drop li > a").visible?.should eq(false)
end
it "but you can interact with the elements", :js => true do
within ("#nav") do
click_link "Logout"
end
page.should have_content "Logout successful!"
end
def add_logout
# add the logout link with js because we're not really logged in
page.execute_script('$("#nav li.last > a").after("<ul class=\"drop\"><li><a href=\"/logout\"><span>Logout</span></a></li></ul>")')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment