Skip to content

Instantly share code, notes, and snippets.

@fidothe
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fidothe/cbb1f0d7b484d0e414d7 to your computer and use it in GitHub Desktop.
Save fidothe/cbb1f0d7b484d0e414d7 to your computer and use it in GitHub Desktop.
Capybara CSS / XPath selector spec problem
source "https://rubygems.org/"
gem "capybara"
gem "rspec"
GEM
remote: https://rubygems.org/
specs:
capybara (2.4.3)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
diff-lcs (1.2.5)
mime-types (2.3)
mini_portile (0.6.0)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.4)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.1)
rspec-support (~> 3.1.0)
rspec-support (3.1.0)
xpath (2.0.0)
nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
capybara
rspec
require 'capybara/rspec'
RSpec.configure do |config|
config.include(Capybara::RSpecMatchers)
end
describe "Capybara selectors not working as expected" do
let(:html) { "<html><head><title>t</title></head><body><p>p</p></body>" }
context "css" do
it "should report that the document has an html tag" do
expect(html).to have_css('html')
end
it "should report that the document has a head tag" do
expect(html).to have_css('head')
end
it "should report that the document has a head tag descendant of html" do
expect(html).to have_css('html head')
end
it "should report that the document has a head tag child of html" do
expect(html).to have_css('html > head')
end
end
context "xpath" do
it "should report that the document has an html tag" do
expect(html).to have_xpath('/html')
end
it "should report that the document has a head tag" do
expect(html).to have_xpath('//head')
end
it "should report that the document has a head tag child of html" do
expect(html).to have_xpath('/html/head')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment