2008-07-26 16:17:00 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
|
|
|
|
|
|
describe "within" do
|
2008-11-07 06:09:00 +00:00
|
|
|
it "should work when nested" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
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-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:get).with("/page2", {})
|
2008-11-23 05:22:49 +00:00
|
|
|
within "#container" do
|
|
|
|
within "div" do
|
|
|
|
click_link "Link"
|
2008-11-07 06:09:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-07-26 16:17:00 +00:00
|
|
|
it "should click links within a scope" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
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-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:get).with("/page2", {})
|
2008-11-23 05:22:49 +00:00
|
|
|
within "#container" do
|
|
|
|
click_link "Link"
|
2008-07-26 16:17:00 +00:00
|
|
|
end
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-07-27 16:41:52 +00:00
|
|
|
it "should submit forms within a scope" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-22 21:46:03 +00:00
|
|
|
<html>
|
2008-11-28 07:02:17 +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-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:get).with("/form2", "email" => "test@example.com")
|
2008-11-23 05:22:49 +00:00
|
|
|
within "#form2" do
|
|
|
|
fill_in "Email", :with => "test@example.com"
|
|
|
|
click_button
|
2008-07-27 16:41:52 +00:00
|
|
|
end
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-12-26 03:53:23 +00:00
|
|
|
it "should work when the scope is inside the form" do
|
2009-01-17 22:03:31 +00:00
|
|
|
with_html <<-HTML
|
|
|
|
<html>
|
|
|
|
<form id="form2" action="/form2">
|
|
|
|
<div class="important">
|
|
|
|
<label>Email: <input type="text" class="email2" name="email" /></label>
|
|
|
|
</div>
|
|
|
|
<input type="submit" value="Add" />
|
|
|
|
</form>
|
|
|
|
</html>
|
|
|
|
HTML
|
|
|
|
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:get).with("/form2", "email" => "test@example.com")
|
2009-01-17 22:03:31 +00:00
|
|
|
within ".important" do
|
|
|
|
fill_in "Email", :with => "test@example.com"
|
|
|
|
end
|
|
|
|
|
|
|
|
submit_form "form2"
|
2009-01-17 21:59:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should work when the form submission occurs inside a scope" do
|
|
|
|
with_html <<-HTML
|
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
<div>
|
|
|
|
<form id="form2" action="/form2">
|
|
|
|
<label for="email">Email</label><input id="email" type="text" class="email2" name="email" />
|
|
|
|
<input type="submit" value="Add" />
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
HTML
|
|
|
|
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:get).with("/form2", "email" => "test@example.com")
|
2009-04-08 00:30:12 +00:00
|
|
|
within "form[@action='/form2']" do
|
2009-01-17 21:59:12 +00:00
|
|
|
fill_in "Email", :with => "test@example.com"
|
|
|
|
click_button "Add"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should work when there are multiple forms with the same label text" do
|
|
|
|
with_html <<-HTML
|
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
<div>
|
|
|
|
<form id="form1" action="/form1">
|
|
|
|
<label for="email1">Email</label><input id="email1" type="text" class="email1" name="email1" />
|
|
|
|
<input type="submit" value="Add" />
|
|
|
|
</form>
|
|
|
|
<form id="form2" action="/form2">
|
|
|
|
<label for="email2">Email</label><input id="email2" type="text" class="email2" name="email2" />
|
|
|
|
<input type="submit" value="Add" />
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
HTML
|
|
|
|
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:get).with("/form2", "email2" => "test@example.com")
|
2009-04-08 00:30:12 +00:00
|
|
|
within "form[@action='/form2']" do
|
2009-01-17 21:59:12 +00:00
|
|
|
fill_in "Email", :with => "test@example.com"
|
|
|
|
click_button "Add"
|
2008-12-26 03:53:23 +00:00
|
|
|
end
|
|
|
|
end
|
2009-01-19 16:50:54 +00:00
|
|
|
|
|
|
|
it "should not find fields outside of the scope" do
|
|
|
|
with_html <<-HTML
|
|
|
|
<html>
|
|
|
|
<form id="form1" action="/form1">
|
|
|
|
<label for="email">Email</label><input id="email" type="text" name="email" />
|
|
|
|
<input type="submit" value="Add" />
|
|
|
|
</form>
|
|
|
|
<form id="form2" action="/form2">
|
|
|
|
<label for="email">Email</label><input id="email" type="text" name="email" />
|
|
|
|
<input type="submit" value="Add" />
|
|
|
|
</form>
|
|
|
|
</html>
|
|
|
|
HTML
|
|
|
|
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:get).with("/form2", "email" => "test@example.com")
|
2009-01-19 16:50:54 +00:00
|
|
|
within "#form2" do
|
|
|
|
fill_in "Email", :with => "test@example.com"
|
|
|
|
click_button "Add"
|
|
|
|
end
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-07-27 16:41:52 +00:00
|
|
|
it "should not find buttons outside of the scope" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
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-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-11-23 05:22:49 +00:00
|
|
|
within "#form2" do
|
2008-07-27 16:41:52 +00:00
|
|
|
lambda {
|
2008-11-23 05:22:49 +00:00
|
|
|
click_button
|
|
|
|
}.should raise_error(Webrat::NotFoundError)
|
2008-07-27 16:41:52 +00:00
|
|
|
end
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2009-01-17 18:27:32 +00:00
|
|
|
it "should raise a Webrat::NotFounderror error when the scope doesn't exist" do
|
|
|
|
with_html <<-HTML
|
|
|
|
<html>
|
|
|
|
</html>
|
|
|
|
HTML
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2009-01-17 18:27:32 +00:00
|
|
|
lambda {
|
|
|
|
within "#form2" do
|
|
|
|
end
|
|
|
|
}.should raise_error(Webrat::NotFoundError)
|
|
|
|
end
|
2008-07-26 16:17:00 +00:00
|
|
|
end
|