From 25567fadb4963d61308820ec7449df03b80c0d79 Mon Sep 17 00:00:00 2001 From: Corey Donohoe Date: Sun, 15 Feb 2009 14:22:59 -0700 Subject: [PATCH] first steps towards webrat testing for twitplot --- test/functional/home_controller_test.rb | 8 ---- test/integration/visiting_twitplot_test.rb | 22 ++++++++++ test/test_helper.rb | 48 ++++++++++++---------- 3 files changed, 48 insertions(+), 30 deletions(-) delete mode 100644 test/functional/home_controller_test.rb create mode 100644 test/integration/visiting_twitplot_test.rb diff --git a/test/functional/home_controller_test.rb b/test/functional/home_controller_test.rb deleted file mode 100644 index 5b3761b..0000000 --- a/test/functional/home_controller_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require File.expand_path(File.dirname(__FILE__)+'/../test_helper') - -class HomeControllerTest < ActionController::TestCase - # Replace this with your real tests. - test "the truth" do - assert true - end -end diff --git a/test/integration/visiting_twitplot_test.rb b/test/integration/visiting_twitplot_test.rb new file mode 100644 index 0000000..cf7bb17 --- /dev/null +++ b/test/integration/visiting_twitplot_test.rb @@ -0,0 +1,22 @@ +require File.expand_path(File.dirname(__FILE__)+'/../test_helper') + +class VisitingTwitplotTest < ActionController::IntegrationTest + # Replace this with your real tests. + test "the truth" do + visit '/' + assert_have_selector 'div#about' + assert_have_selector 'div#results' + assert_have_selector "form[action='/search']" + assert_have_selector "form input#location[name='location'][type='text'][value='Boulder, Co']" + assert_have_selector "form input#keyword[name='keyword'][type='text']" + assert_have_selector "form select#distance[name='distance']" + [10,25,50].each do |miles| + assert_have_selector "form select#distance option[value='#{miles}']:contains('#{miles}')" + end + + assert_have_selector "form input[type='submit'][name='commit'][value='search']" + + click_button 'search' + puts response_body + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 9f19269..04bfcf8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,31 +1,11 @@ ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' +require 'webrat' +require 'webrat/selenium' class Test::Unit::TestCase - # Transactional fixtures accelerate your tests by wrapping each test method - # in a transaction that's rolled back on completion. This ensures that the - # test database remains unchanged so your fixtures don't have to be reloaded - # between every test method. Fewer database queries means faster tests. - # - # Read Mike Clark's excellent walkthrough at - # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting - # - # Every Active Record database supports transactions except MyISAM tables - # in MySQL. Turn off transactional fixtures in this case; however, if you - # don't care one way or the other, switching from MyISAM to InnoDB tables - # is recommended. - # - # The only drawback to using transactional fixtures is when you actually - # need to test transactions. Since your test is bracketed by a transaction, - # any transactions started in your code will be automatically rolled back. self.use_transactional_fixtures = true - - # Instantiated fixtures are slow, but give you @david where otherwise you - # would need people(:david). If you don't want to migrate your existing - # test cases which use the @david style and don't mind the speed hit (each - # instantiated fixtures translates to a database query per test method), - # then set this back to true. self.use_instantiated_fixtures = false # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. @@ -36,3 +16,27 @@ class Test::Unit::TestCase # Add more helper methods to be used by all tests here... end +if ENV['SELENIUM'] + module ActionController #:nodoc: + IntegrationTest.class_eval do + include Webrat::Selenium::Methods + include Webrat::Selenium::Matchers + end + end +end + +Webrat.configure do |config| + if ENV['SELENIUM'] + module ActionController #:nodoc: + IntegrationTest.class_eval do + include Webrat::Selenium::Methods + include Webrat::Selenium::Matchers + end + end + config.mode = :selenium + else + config.mode = :rails + end +end + +