capybara-webkit/spec/integration/session_spec.rb

88 lines
2.3 KiB
Ruby
Raw Normal View History

2011-04-19 09:07:42 +00:00
# -*- encoding: UTF-8 -*-
2011-02-26 22:02:00 +00:00
require 'spec_helper'
require 'capybara-webkit'
describe Capybara::Session do
subject { Capybara::Session.new(:reusable_webkit, @app) }
after { subject.reset! }
context "slow javascript app" do
before(:all) do
@app = lambda do |env|
body = <<-HTML
<html><body>
<form action="/next" id="submit_me"><input type="submit" value="Submit" /></form>
<p id="change_me">Hello</p>
<script type="text/javascript">
var form = document.getElementById('submit_me');
form.addEventListener("submit", function (event) {
event.preventDefault();
setTimeout(function () {
document.getElementById("change_me").innerHTML = 'Good' + 'bye';
}, 500);
});
</script>
</body></html>
HTML
[200,
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
[body]]
end
end
before do
@default_wait_time = Capybara.default_wait_time
Capybara.default_wait_time = 1
end
after { Capybara.default_wait_time = @default_wait_time }
it "waits for a request to load" do
subject.visit("/")
subject.find_button("Submit").click
subject.should have_content("Goodbye");
end
end
context "simple app" do
before(:all) do
@app = lambda do |env|
body = <<-HTML
<html><body>
<strong>Hello</strong>
2011-04-19 09:07:42 +00:00
<span>UTF8文字列</span>
</body></html>
HTML
[200,
2011-04-19 09:07:42 +00:00
{ 'Content-Type' => 'text/html; charset=UTF-8', 'Content-Length' => body.length.to_s },
[body]]
end
end
2011-04-19 09:07:42 +00:00
before do
subject.visit("/")
2011-04-19 09:07:42 +00:00
end
it "inspects nodes" do
subject.all(:xpath, "//strong").first.inspect.should include("strong")
end
2011-04-19 09:07:42 +00:00
it "utf8 string" do
utf8str = subject.all(:xpath, "//span").first.text
utf8str = utf8str.dup.force_encoding('UTF-8') if Kernel.const_defined?(:Encoding) # for Ruby 1.9
utf8str.should eq('UTF8文字列')
end
end
end
describe Capybara::Session, "with TestApp" do
2011-02-26 22:02:00 +00:00
before do
@session = Capybara::Session.new(:reusable_webkit, TestApp)
2011-02-26 22:02:00 +00:00
end
# it_should_behave_like "session"
# it_should_behave_like "session with javascript support"
end