2008-10-23 04:21:25 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
|
|
|
|
|
|
|
2008-10-25 16:15:16 +00:00
|
|
|
describe "field_labeled" do
|
2008-10-23 04:21:25 +00:00
|
|
|
class << self
|
|
|
|
def using_this_html html
|
|
|
|
before(:each) do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html(html)
|
2008-10-23 04:21:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-23 05:22:49 +00:00
|
|
|
def field_labeled(label)
|
2008-10-23 04:21:25 +00:00
|
|
|
@label = label
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
|
|
|
|
def should_return_a type, opts
|
|
|
|
it "should return a textfield" do
|
2008-11-23 05:22:49 +00:00
|
|
|
field_labeled(opts[:for]).should be_an_instance_of(type)
|
2008-10-23 04:21:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def with_an_id_of id, opts
|
|
|
|
it "should return an element with the correct id" do
|
2008-11-23 05:22:49 +00:00
|
|
|
field_labeled(opts[:for]).should match_id(id)
|
2008-10-23 04:21:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def should_raise_error_matching regexp, opts
|
|
|
|
it "should raise with wrong label" do
|
|
|
|
lambda {
|
2008-11-23 05:22:49 +00:00
|
|
|
field_labeled(opts[:for])
|
2008-10-23 04:21:25 +00:00
|
|
|
}.should raise_error(regexp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def match_id(id)
|
|
|
|
simple_matcher "element with id #{id.inspect}" do |element, matcher|
|
|
|
|
element.matches_id? id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "finding a text field" do
|
2008-11-07 03:09:16 +00:00
|
|
|
using_this_html <<-HTML
|
2008-10-23 04:21:25 +00:00
|
|
|
<form>
|
|
|
|
<label for="element_42">The Label</label>
|
|
|
|
<input type="text" id="element_42">
|
|
|
|
</form>
|
2008-11-07 03:09:16 +00:00
|
|
|
HTML
|
2008-10-23 04:21:25 +00:00
|
|
|
|
|
|
|
should_return_a Webrat::TextField, :for => "The Label"
|
|
|
|
with_an_id_of "element_42", :for => "The Label"
|
|
|
|
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
|
|
|
end
|
|
|
|
|
2008-11-07 03:09:16 +00:00
|
|
|
describe "finding a hidden field" do
|
|
|
|
using_this_html <<-HTML
|
2008-10-23 04:21:25 +00:00
|
|
|
<form>
|
|
|
|
<label for="element_42">The Label</label>
|
|
|
|
<input type="hidden" id="element_42">
|
|
|
|
</form>
|
2008-11-07 03:09:16 +00:00
|
|
|
HTML
|
2008-10-23 04:21:25 +00:00
|
|
|
|
|
|
|
should_return_a Webrat::HiddenField, :for => "The Label"
|
|
|
|
with_an_id_of "element_42", :for => "The Label"
|
|
|
|
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "finding a checkbox" do
|
2008-11-07 03:09:16 +00:00
|
|
|
using_this_html <<-HTML
|
2008-10-23 04:21:25 +00:00
|
|
|
<form>
|
|
|
|
<label for="element_42">The Label</label>
|
|
|
|
<input type="checkbox" id="element_42">
|
|
|
|
</form>
|
2008-11-07 03:09:16 +00:00
|
|
|
HTML
|
2008-10-23 04:21:25 +00:00
|
|
|
|
|
|
|
should_return_a Webrat::CheckboxField, :for => "The Label"
|
|
|
|
with_an_id_of "element_42", :for => "The Label"
|
|
|
|
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "finding a radio button" do
|
2008-11-07 03:09:16 +00:00
|
|
|
using_this_html <<-HTML
|
2008-10-23 04:21:25 +00:00
|
|
|
<form>
|
|
|
|
<label for="element_42">The Label</label>
|
|
|
|
<input type="radio" id="element_42">
|
|
|
|
</form>
|
2008-11-07 03:09:16 +00:00
|
|
|
HTML
|
2008-10-23 04:21:25 +00:00
|
|
|
|
|
|
|
should_return_a Webrat::RadioField, :for => "The Label"
|
|
|
|
with_an_id_of "element_42", :for => "The Label"
|
|
|
|
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
describe "finding a text area" do
|
2008-11-07 03:09:16 +00:00
|
|
|
using_this_html <<-HTML
|
2008-10-23 04:21:25 +00:00
|
|
|
<form>
|
|
|
|
<label for="element_42">The Label</label>
|
|
|
|
<textarea id="element_42"></textarea>
|
|
|
|
</form>
|
2008-11-07 03:09:16 +00:00
|
|
|
HTML
|
2008-10-23 04:21:25 +00:00
|
|
|
|
|
|
|
should_return_a Webrat::TextareaField, :for => "The Label"
|
|
|
|
with_an_id_of "element_42", :for => "The Label"
|
|
|
|
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
|
|
|
end
|
2008-11-13 14:00:24 +00:00
|
|
|
|
|
|
|
describe "finding a field with it's label containing newlines" do
|
|
|
|
using_this_html <<-HTML
|
|
|
|
<form>
|
|
|
|
<label for="element_42">
|
|
|
|
A label with
|
|
|
|
<a>a link on it's own line</a>
|
|
|
|
</label>
|
|
|
|
<input type="text" id="element_42">
|
|
|
|
</form>
|
|
|
|
HTML
|
|
|
|
|
|
|
|
should_return_a Webrat::TextField, :for => "A label with a link on it's own line"
|
|
|
|
with_an_id_of "element_42", :for => "A label with a link on it's own line"
|
|
|
|
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
|
|
|
|
end
|
|
|
|
|
2008-10-23 04:21:25 +00:00
|
|
|
end
|