Merge commit 'dchelimsky/master'

This commit is contained in:
Bryan Helmkamp 2008-10-25 12:11:48 -04:00
commit 354c8c1f4e
6 changed files with 138 additions and 1 deletions

View File

@ -40,6 +40,7 @@ lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js
lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js
lib/webrat/selenium/selenium_session.rb lib/webrat/selenium/selenium_session.rb
lib/webrat/sinatra/sinatra_session.rb lib/webrat/sinatra/sinatra_session.rb
manifest.diff
mechanize_spike.rb mechanize_spike.rb
selenium_spike.rb selenium_spike.rb
spec/api/attaches_file_spec.rb spec/api/attaches_file_spec.rb
@ -61,12 +62,13 @@ spec/api/within_spec.rb
spec/fakes/test_session.rb spec/fakes/test_session.rb
spec/integration/rails_spec.rb spec/integration/rails_spec.rb
spec/rcov.opts spec/rcov.opts
spec/spec.opts
spec/spec_helper.rb spec/spec_helper.rb
spec/webrat/core/logging_spec.rb spec/webrat/core/logging_spec.rb
spec/webrat/core/session_spec.rb spec/webrat/core/session_spec.rb
spec/webrat/mechanize/mechanize_session_spec.rb spec/webrat/mechanize/mechanize_session_spec.rb
spec/webrat/merb/helper.rb spec/webrat/merb/helper.rb
spec/webrat/merb/indifferent_access_spec.rb
spec/webrat/merb/session_spec.rb
spec/webrat/rails/helper.rb spec/webrat/rails/helper.rb
spec/webrat/rails/rails_session_spec.rb spec/webrat/rails/rails_session_spec.rb
webrat.gemspec webrat.gemspec

View File

@ -199,6 +199,10 @@ module Webrat
raise_error_if_disabled raise_error_if_disabled
set(@element["value"] || "on") set(@element["value"] || "on")
end end
def checked?
@element["checked"] == "checked"
end
def uncheck def uncheck
raise_error_if_disabled raise_error_if_disabled

View File

@ -175,6 +175,10 @@ module Webrat
@dom ||= Hpricot(scoped_html) @dom ||= Hpricot(scoped_html)
end end
def element_labeled(label)
find_field(label, TextField, TextareaField, CheckboxField, RadioField, HiddenField)
end
protected protected
def scoped_html def scoped_html

View File

@ -161,5 +161,6 @@ module Webrat
def_delegators :current_scope, :click_button, :clicks_button def_delegators :current_scope, :click_button, :clicks_button
def_delegators :current_scope, :should_see def_delegators :current_scope, :should_see
def_delegators :current_scope, :should_not_see def_delegators :current_scope, :should_not_see
def_delegators :current_scope, :element_labeled
end end
end end

View File

@ -0,0 +1,111 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "element_labeled" do
class << self
def using_this_html html
before(:each) do
@session = Webrat::TestSession.new
@session.response_body = html
end
end
def element_labeled label
@label = label
yield
end
def should_return_a type, opts
it "should return a textfield" do
@session.element_labeled(opts[:for]).should be_an_instance_of(type)
end
end
def with_an_id_of id, opts
it "should return an element with the correct id" do
@session.element_labeled(opts[:for]).should match_id(id)
end
end
def should_raise_error_matching regexp, opts
it "should raise with wrong label" do
lambda {
@session.element_labeled(opts[:for])
}.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
using_this_html <<-EOS
<form>
<label for="element_42">The Label</label>
<input type="text" id="element_42">
</form>
EOS
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
describe "finding a text field" do
using_this_html <<-EOS
<form>
<label for="element_42">The Label</label>
<input type="hidden" id="element_42">
</form>
EOS
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
using_this_html <<-EOS
<form>
<label for="element_42">The Label</label>
<input type="checkbox" id="element_42">
</form>
EOS
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
using_this_html <<-EOS
<form>
<label for="element_42">The Label</label>
<input type="radio" id="element_42">
</form>
EOS
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
using_this_html <<-EOS
<form>
<label for="element_42">The Label</label>
<textarea id="element_42"></textarea>
</form>
EOS
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
end

15
spec/core/field_spec.rb Normal file
View File

@ -0,0 +1,15 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
module Webrat
describe CheckboxField do
it "should say it is checked if it is" do
checkbox = CheckboxField.new(nil, (Hpricot("<input type='checkbox' checked='checked'>")/'input').first)
checkbox.should be_checked
end
it "should say it is not checked if it is not" do
checkbox = CheckboxField.new(nil, (Hpricot("<input type='checkbox'>")/'input').first)
checkbox.should_not be_checked
end
end
end