Added page to DSL for more expressive tests

e.g. page.should have_content('foo')
or   assert page.has_content?('foo')
This commit is contained in:
Jonas Nicklas and Kevin Fitzpatrick 2009-11-14 13:51:52 +01:00 committed by Jonas Nicklas
parent f10e5b4f06
commit 2c86723ea2
2 changed files with 14 additions and 1 deletions

View File

@ -30,6 +30,9 @@ module Webcat
extend(self)
def page
Webcat.current_session
end
SESSION_METHODS = [
:visit, :body, :click_link, :click_button, :fill_in, :choose,
@ -38,7 +41,7 @@ module Webcat
SESSION_METHODS.each do |method|
class_eval <<-RUBY, __FILE__, __LINE__+1
def #{method}(*args, &block)
Webcat.current_session.#{method}(*args, &block)
page.#{method}(*args, &block)
end
RUBY
end

View File

@ -104,6 +104,16 @@ describe Webcat do
foo.click_link('ullamco')
foo.body.should include('Another World')
end
it "should provide a 'page' shortcut for more expressive tests" do
klass = Class.new do
include Webcat
end
foo = klass.new
foo.page.visit('/with_html')
foo.page.click_link('ullamco')
foo.page.body.should include('Another World')
end
end
end