diff --git a/lib/webrat/field.rb b/lib/webrat/field.rb index 491b202..34b70bd 100644 --- a/lib/webrat/field.rb +++ b/lib/webrat/field.rb @@ -237,6 +237,7 @@ module Webrat selected_options = @element / "option[@selected='selected']" selected_options = @element / "option:first" if selected_options.empty? selected_options.map do |option| + return "" if option.nil? option["value"] || option.innerHTML end end diff --git a/test/selects_test.rb b/test/selects_test.rb index feef07a..05576c4 100644 --- a/test/selects_test.rb +++ b/test/selects_test.rb @@ -56,6 +56,17 @@ class SelectsTest < Test::Unit::TestCase @session.selects "January", :from => "month" @session.clicks_button end + + def test_should_work_with_empty_select_lists + @response.stubs(:body).returns(<<-EOS) +
+ + +
+ EOS + @session.expects(:post_via_redirect).with("/login", 'month' => '') + @session.clicks_button + end def test_should_work_without_specifying_the_field_name_or_label @response.stubs(:body).returns(<<-EOS)