Skip to content

Commit

Permalink
first steps towards webrat testing for twitplot
Browse files Browse the repository at this point in the history
  • Loading branch information
atmos committed Feb 15, 2009
1 parent ef287e2 commit 25567fa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 30 deletions.
8 changes: 0 additions & 8 deletions test/functional/home_controller_test.rb

This file was deleted.

22 changes: 22 additions & 0 deletions test/integration/visiting_twitplot_test.rb
Original file line number Diff line number Diff line change
@@ -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
48 changes: 26 additions & 22 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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


0 comments on commit 25567fa

Please sign in to comment.