2011-02-18 22:53:06 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'capybara/driver/webkit'
|
|
|
|
|
|
|
|
describe Capybara::Driver::Webkit do
|
|
|
|
let(:hello_app) do
|
|
|
|
lambda do |env|
|
|
|
|
body = <<-HTML
|
|
|
|
<html><body>
|
|
|
|
<script type="text/javascript">
|
2011-02-25 00:15:08 -05:00
|
|
|
document.write("<p id='greeting'>he" + "llo</p>");
|
2011-02-18 22:53:06 -05:00
|
|
|
</script>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { Capybara::Driver::Webkit.new(hello_app) }
|
2011-02-24 23:22:56 -05:00
|
|
|
before { subject.visit("/hello") }
|
2011-02-18 22:53:06 -05:00
|
|
|
after { subject.reset! }
|
|
|
|
|
|
|
|
it "finds content after loading a URL" do
|
|
|
|
subject.find("//*[contains(., 'hello')]").should_not be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has an empty page after reseting" do
|
|
|
|
subject.reset!
|
|
|
|
subject.find("//*[contains(., 'hello')]").should be_empty
|
|
|
|
end
|
2011-02-24 23:22:56 -05:00
|
|
|
|
|
|
|
it "raises an error for an invalid xpath query" do
|
|
|
|
expect { subject.find("totally invalid salad") }.
|
|
|
|
to raise_error(Capybara::Driver::Webkit::WebkitError, /xpath/i)
|
|
|
|
end
|
2011-02-25 00:15:08 -05:00
|
|
|
|
|
|
|
it "returns an attribute's value" do
|
|
|
|
subject.find("//p").first["id"].should == "greeting"
|
|
|
|
end
|
2011-02-18 22:53:06 -05:00
|
|
|
end
|
|
|
|
|