2008-07-26 16:17:00 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
|
|
|
|
|
|
describe "within" do
|
|
|
|
before do
|
|
|
|
@session = Webrat::TestSession.new
|
|
|
|
end
|
|
|
|
|
2008-11-07 06:09:00 +00:00
|
|
|
it "should work when nested" do
|
|
|
|
@session.response_body = <<-EOS
|
2008-11-22 21:46:03 +00:00
|
|
|
<html>
|
2008-11-07 06:09:00 +00:00
|
|
|
<div>
|
|
|
|
<a href="/page1">Link</a>
|
|
|
|
</div>
|
|
|
|
<div id="container">
|
|
|
|
<div><a href="/page2">Link</a></div>
|
|
|
|
</div>
|
2008-11-22 21:46:03 +00:00
|
|
|
</html>
|
2008-11-07 06:09:00 +00:00
|
|
|
EOS
|
|
|
|
|
|
|
|
@session.should_receive(:get).with("/page2", {})
|
|
|
|
@session.within "#container" do
|
|
|
|
@session.within "div" do
|
|
|
|
@session.click_link "Link"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-07-26 16:17:00 +00:00
|
|
|
it "should click links within a scope" do
|
|
|
|
@session.response_body = <<-EOS
|
2008-11-22 21:46:03 +00:00
|
|
|
<html>
|
2008-07-27 16:41:52 +00:00
|
|
|
<a href="/page1">Link</a>
|
|
|
|
<div id="container">
|
|
|
|
<a href="/page2">Link</a>
|
|
|
|
</div>
|
2008-11-22 21:46:03 +00:00
|
|
|
</html>
|
2008-07-26 16:17:00 +00:00
|
|
|
EOS
|
|
|
|
|
|
|
|
@session.should_receive(:get).with("/page2", {})
|
2008-11-07 03:19:02 +00:00
|
|
|
@session.within "#container" do
|
|
|
|
@session.click_link "Link"
|
2008-07-26 16:17:00 +00:00
|
|
|
end
|
|
|
|
end
|
2008-07-27 16:41:52 +00:00
|
|
|
|
|
|
|
it "should submit forms within a scope" do
|
|
|
|
@session.response_body = <<-EOS
|
2008-11-22 21:46:03 +00:00
|
|
|
<html>
|
2008-07-27 16:41:52 +00:00
|
|
|
<form id="form1" action="/form1">
|
|
|
|
<label>Email: <input type="text" name="email" />
|
|
|
|
<input type="submit" value="Add" />
|
|
|
|
</form>
|
|
|
|
<form id="form2" action="/form2">
|
|
|
|
<label>Email: <input type="text" name="email" />
|
|
|
|
<input type="submit" value="Add" />
|
|
|
|
</form>
|
2008-11-22 21:46:03 +00:00
|
|
|
</html>
|
2008-07-27 16:41:52 +00:00
|
|
|
EOS
|
|
|
|
|
|
|
|
@session.should_receive(:get).with("/form2", "email" => "test@example.com")
|
2008-11-07 03:19:02 +00:00
|
|
|
@session.within "#form2" do
|
|
|
|
@session.fill_in "Email", :with => "test@example.com"
|
|
|
|
@session.click_button
|
2008-07-27 16:41:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not find buttons outside of the scope" do
|
|
|
|
@session.response_body = <<-EOS
|
2008-11-22 21:46:03 +00:00
|
|
|
<html>
|
2008-07-27 16:41:52 +00:00
|
|
|
<form action="/form1">
|
|
|
|
<input type="submit" value="Add" />
|
|
|
|
</form>
|
|
|
|
<form id="form2" action="/form2">
|
|
|
|
</form>
|
2008-11-22 21:46:03 +00:00
|
|
|
</html>
|
2008-07-27 16:41:52 +00:00
|
|
|
EOS
|
|
|
|
|
2008-11-07 03:19:02 +00:00
|
|
|
@session.within "#form2" do
|
2008-07-27 16:41:52 +00:00
|
|
|
lambda {
|
2008-11-07 03:19:02 +00:00
|
|
|
@session.click_button
|
2008-07-27 16:41:52 +00:00
|
|
|
}.should raise_error
|
|
|
|
end
|
|
|
|
end
|
2008-07-26 16:17:00 +00:00
|
|
|
end
|