Skip to content

Instantly share code, notes, and snippets.

@vangberg
Created Jan 16, 2009
Embed
What would you like to do?
require 'rubygems'
require 'sinatra'
get '/no-hidden' do
erb :no_hidden
end
get '/hidden' do
erb :hidden
end
get '/hidden-sans-content' do
erb :with_hidden_sans_content
end
use_in_file_templates!
__END__
@@ layout
<html>
<body>
<%= yield %>
</body>
</html>
@@ layout
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>the lil' time tracker</title>
</head>
<body>
<%= yield %>
</body>
</html
@@ no_hidden
<div id='content'>
<div class='project'>
<a class='name'>Blue Train</a>
<form action='/track/blue-train' method='post'>
<input alt='Track' src='/images/clock.png' type='image' />
</form>
</div>
</div>
@@ hidden
<div id='content'>
<div class='project'>
<a class='name'>Blue Train</a>
<form action='/track/blue-train' method='post'>
<input type='hidden' name='_method' value='post'>
<input alt='Track' src='/images/clock.png' type='image' />
</form>
</div>
</div>
@@ with_hidden_sans_content
<div class='project'>
<a class='name'>Blue Train</a>
<form action='/track/blue-train' method='post'>
<input type='hidden' name='_method' value='post'>
<input alt='Track' src='/images/clock.png' type='image' />
</form>
</div>
require 'rubygems'
require 'test/unit'
require 'webrat/sinatra'
require 'app'
Webrat.configure do |config|
config.mode = :sinatra
end
class Test::Unit::TestCase
include Webrat::Methods
end
class TestApp < Test::Unit::TestCase
def test_click_button_without_hidden_field
visit '/no-hidden'
within ".project:contains('Blue Train')" do |scope|
scope.click_button 'Track'
end
end
def test_click_button_with_hidden_field
visit '/hidden'
within ".project:contains('Blue Train')" do |scope|
scope.click_button 'Track'
end
end
def test_click_button_with_hidden_field_and_without_content_div
visit '/hidden-sans-content'
within ".project:contains('Blue Train')" do |scope|
scope.click_button 'Track'
end
end
end
There's some weird edge case here (or I have fucked up big time):
1) without hidden it's fine,
2) with hidden field it breaks
3) with hidden field but without the #content div it's fine aswell.
~/c/webrat_within_click_button master> ruby test.rb
Loaded suite test
Started
E..
Finished in 0.022578 seconds.
1) Error:
test_click_button_with_hidden_field(TestApp):
NoMethodError: undefined method `xpath' for nil:NilClass
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/xml.rb:97:in `xpath_search'
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/xml.rb:95:in `map'
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/xml.rb:95:in `xpath_search'
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/locators/field_named_locator.rb:19:in `field_elements'
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/locators/field_named_locator.rb:13:in `field_element'
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/locators/field_named_locator.rb:9:in `locate'
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/elements/form.rb:24:in `field_named'
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/elements/field.rb:201:in `to_param'
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/elements/form.rb:45:in `params'
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/elements/form.rb:44:in `each'
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/elements/form.rb:44:in `params'
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/elements/form.rb:20:in `submit'
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/elements/field.rb:186:in `click'
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/scope.rb:257:in `click_button'
test.rb:25:in `test_click_button_with_hidden_field'
/Users/h/.gems/gems/webrat-0.3.2.2/lib/webrat/core/session.rb:160:in `within'
(eval):2:in `within'
test.rb:24:in `test_click_button_with_hidden_field'
3 tests, 0 assertions, 0 failures, 1 errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment