Merge branch 'lh_120_tests_with_selenium' of git@github.com:gaffo/webrat into lh_82
Conflicts: spec/integration/rails/test/integration/webrat_test.rb
This commit is contained in:
commit
2c9b546a83
9
Rakefile
9
Rakefile
@ -111,7 +111,14 @@ namespace :spec do
|
|||||||
desc "Run the Rails integration specs"
|
desc "Run the Rails integration specs"
|
||||||
task :rails do
|
task :rails do
|
||||||
Dir.chdir "spec/integration/rails" do
|
Dir.chdir "spec/integration/rails" do
|
||||||
result = system "rake test:integration"
|
result = system "rake test_unit_webrat"
|
||||||
|
raise "Rails integration tests failed" unless result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
task :rails_selenium do
|
||||||
|
Dir.chdir "spec/integration/rails" do
|
||||||
|
result = system "rake test_unit_selenium"
|
||||||
raise "Rails integration tests failed" unless result
|
raise "Rails integration tests failed" unless result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -89,6 +89,7 @@ module ActionController #:nodoc:
|
|||||||
IntegrationTest.class_eval do
|
IntegrationTest.class_eval do
|
||||||
include Webrat::Methods
|
include Webrat::Methods
|
||||||
include Webrat::Selenium::Methods
|
include Webrat::Selenium::Methods
|
||||||
|
# include Webrat::Matchers
|
||||||
include Webrat::Selenium::Matchers
|
include Webrat::Selenium::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
4
spec/integration/rails/.gitignore
vendored
4
spec/integration/rails/.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
vendor/plugins/webrat
|
vendor/plugins/webrat
|
||||||
|
tmp/pids/*.pid
|
||||||
|
log/*.log
|
||||||
|
@ -8,3 +8,35 @@ require 'rake/testtask'
|
|||||||
require 'rake/rdoctask'
|
require 'rake/rdoctask'
|
||||||
|
|
||||||
require 'tasks/rails'
|
require 'tasks/rails'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace :test_unit do
|
||||||
|
desc "runs the test::unit based tests in webrat mode"
|
||||||
|
task :rails do
|
||||||
|
ENV['WEBRAT_INTEGRATION_MODE'] = 'rails'
|
||||||
|
Rake::Task['test_unit:rails_test'].execute
|
||||||
|
end
|
||||||
|
|
||||||
|
Rake::TestTask.new(:rails_test => "db:test:prepare") do |t|
|
||||||
|
t.libs << "test"
|
||||||
|
t.pattern = 'test/integration/**/*_test.rb'
|
||||||
|
t.verbose = true
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "runs the test::unit based tests in selenium mode"
|
||||||
|
task :selenium do
|
||||||
|
ENV['WEBRAT_INTEGRATION_MODE'] = 'selenium'
|
||||||
|
Rake::Task['test_unit:selenium_test'].execute
|
||||||
|
end
|
||||||
|
|
||||||
|
Rake::TestTask.new(:selenium_test => "db:test:prepare") do |t|
|
||||||
|
t.libs << "test"
|
||||||
|
t.pattern = 'test/selenium/**/*_test.rb'
|
||||||
|
t.verbose = true
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "run both selenium and rails mode Test::Unit suites"
|
||||||
|
task :all => [:rails, :selenium]
|
||||||
|
end
|
||||||
|
@ -10,7 +10,7 @@ class WebratController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def submit
|
def submit
|
||||||
render :text => "OK"
|
render :text => "OK <a href='/' id='link_id'>Test Link Text</a>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def internal_redirect
|
def internal_redirect
|
||||||
|
@ -1,75 +1,12 @@
|
|||||||
# Be sure to restart your server when you modify this file
|
|
||||||
|
|
||||||
# Uncomment below to force Rails into production mode when
|
|
||||||
# you don't control web/app server and can't set it the proper way
|
|
||||||
# ENV['RAILS_ENV'] ||= 'production'
|
|
||||||
|
|
||||||
# Specifies gem version of Rails to use when vendor/rails is not present
|
|
||||||
RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION
|
RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION
|
||||||
|
|
||||||
# Bootstrap the Rails environment, frameworks, and default configuration
|
|
||||||
require File.join(File.dirname(__FILE__), 'boot')
|
require File.join(File.dirname(__FILE__), 'boot')
|
||||||
|
|
||||||
Rails::Initializer.run do |config|
|
Rails::Initializer.run do |config|
|
||||||
# Settings in config/environments/* take precedence over those specified here.
|
|
||||||
# Application configuration should go into files in config/initializers
|
|
||||||
# -- all .rb files in that directory are automatically loaded.
|
|
||||||
# See Rails::Configuration for more options.
|
|
||||||
|
|
||||||
# Skip frameworks you're not going to use. To use Rails without a database
|
|
||||||
# you must remove the Active Record framework.
|
|
||||||
config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
|
config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
|
||||||
|
|
||||||
# Specify gems that this application depends on.
|
|
||||||
# They can then be installed with "rake gems:install" on new installations.
|
|
||||||
# You have to specify the :lib option for libraries, where the Gem name (sqlite3-ruby) differs from the file itself (sqlite3)
|
|
||||||
# config.gem "bj"
|
|
||||||
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
|
|
||||||
# config.gem "sqlite3-ruby", :lib => "sqlite3"
|
|
||||||
# config.gem "aws-s3", :lib => "aws/s3"
|
|
||||||
|
|
||||||
# Only load the plugins named here, in the order given. By default, all plugins
|
|
||||||
# in vendor/plugins are loaded in alphabetical order.
|
|
||||||
# :all can be used as a placeholder for all plugins not explicitly named
|
|
||||||
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
|
||||||
|
|
||||||
# Add additional load paths for your own custom dirs
|
|
||||||
# config.load_paths += %W( #{RAILS_ROOT}/extras )
|
|
||||||
|
|
||||||
# Force all environments to use the same logger level
|
|
||||||
# (by default production uses :info, the others :debug)
|
|
||||||
# config.log_level = :debug
|
|
||||||
|
|
||||||
# Make Time.zone default to the specified zone, and make Active Record store time values
|
|
||||||
# in the database in UTC, and return them converted to the specified local zone.
|
|
||||||
# Run "rake -D time" for a list of tasks for finding time zone names. Comment line to use default local time.
|
|
||||||
config.time_zone = 'UTC'
|
config.time_zone = 'UTC'
|
||||||
|
|
||||||
# The internationalization framework can be changed to have another default locale (standard is :en) or more load paths.
|
|
||||||
# All files from config/locales/*.rb,yml are added automatically.
|
|
||||||
# config.i18n.load_path << Dir[File.join(RAILS_ROOT, 'my', 'locales', '*.{rb,yml}')]
|
|
||||||
# config.i18n.default_locale = :de
|
|
||||||
|
|
||||||
# Your secret key for verifying cookie session data integrity.
|
|
||||||
# If you change this key, all old sessions will become invalid!
|
|
||||||
# Make sure the secret is at least 30 characters and all random,
|
|
||||||
# no regular words or you'll be exposed to dictionary attacks.
|
|
||||||
config.action_controller.session = {
|
config.action_controller.session = {
|
||||||
:session_key => '_rails_app_session',
|
:session_key => '_rails_app_session',
|
||||||
:secret => '81f33872c27349e86f1dc2cd6708995b9c26578e6e2d8992e567cd64d96e844343149f6e2f44bf178304141db9ce39e741e0e60699867c29c51c6d7ef7dc9556'
|
:secret => '81f33872c27349e86f1dc2cd6708995b9c26578e6e2d8992e567cd64d96e844343149f6e2f44bf178304141db9ce39e741e0e60699867c29c51c6d7ef7dc9556'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Use the database for sessions instead of the cookie-based default,
|
|
||||||
# which shouldn't be used to store highly confidential information
|
|
||||||
# (create the session table with "rake db:sessions:create")
|
|
||||||
# config.action_controller.session_store = :active_record_store
|
|
||||||
|
|
||||||
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
|
||||||
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
|
||||||
# like if you have constraints or database-specific column types
|
|
||||||
# config.active_record.schema_format = :sql
|
|
||||||
|
|
||||||
# Activate observers that should always be running
|
|
||||||
# Please note that observers generated using script/generate observer need to have an _observer suffix
|
|
||||||
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
|
||||||
end
|
end
|
||||||
|
22
spec/integration/rails/config/environments/selenium.rb
Normal file
22
spec/integration/rails/config/environments/selenium.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Settings specified here will take precedence over those in config/environment.rb
|
||||||
|
|
||||||
|
# The test environment is used exclusively to run your application's
|
||||||
|
# test suite. You never need to work with it otherwise. Remember that
|
||||||
|
# your test database is "scratch space" for the test suite and is wiped
|
||||||
|
# and recreated between test runs. Don't rely on the data there!
|
||||||
|
config.cache_classes = true
|
||||||
|
|
||||||
|
# Log error messages when you accidentally call methods on nil.
|
||||||
|
config.whiny_nils = true
|
||||||
|
|
||||||
|
# Show full error reports and disable caching
|
||||||
|
config.action_controller.consider_all_requests_local = true
|
||||||
|
config.action_controller.perform_caching = false
|
||||||
|
|
||||||
|
# Disable request forgery protection in test environment
|
||||||
|
config.action_controller.allow_forgery_protection = false
|
||||||
|
|
||||||
|
# Tell Action Mailer not to deliver emails to the real world.
|
||||||
|
# The :test delivery method accumulates sent emails in the
|
||||||
|
# ActionMailer::Base.deliveries array.
|
||||||
|
config.action_mailer.delivery_method = :test
|
@ -6,11 +6,10 @@ class WebratTest < ActionController::IntegrationTest
|
|||||||
visit root_url(:host => "chunkybacon.example.com")
|
visit root_url(:host => "chunkybacon.example.com")
|
||||||
assert_equal "chunkybacon", request.subdomains.first
|
assert_equal "chunkybacon", request.subdomains.first
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should visit pages" do
|
test "should visit pages" do
|
||||||
visit root_path
|
visit root_path
|
||||||
assert_tag "Webrat Form"
|
assert_contain("Webrat Form")
|
||||||
assert response.body.include?("Webrat Form")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should submit forms" do
|
test "should submit forms" do
|
||||||
@ -25,26 +24,46 @@ class WebratTest < ActionController::IntegrationTest
|
|||||||
visit "/"
|
visit "/"
|
||||||
assert field_labeled("Prefilled").value, "text"
|
assert field_labeled("Prefilled").value, "text"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should not carry params through redirects" do
|
test "should not carry params through redirects" do
|
||||||
visit before_redirect_form_path
|
visit before_redirect_form_path
|
||||||
fill_in "Text field", :with => "value"
|
fill_in "Text field", :with => "value"
|
||||||
click_button
|
click_button
|
||||||
|
|
||||||
assert response.body !~ /value/
|
assert response.body !~ /value/
|
||||||
assert response.body =~ /custom_param/
|
assert response.body =~ /custom_param/
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should follow internal redirects" do
|
test "should follow internal redirects" do
|
||||||
visit internal_redirect_path
|
visit internal_redirect_path
|
||||||
|
|
||||||
assert !response.redirect?
|
assert !response.redirect?
|
||||||
assert response.body.include?("OK")
|
assert response.body.include?("OK")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should not follow external redirects" do
|
test "should not follow external redirects" do
|
||||||
visit external_redirect_path
|
visit external_redirect_path
|
||||||
assert response.redirect?
|
assert response.redirect?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should click link by text" do
|
||||||
|
visit internal_redirect_path
|
||||||
|
click_link "Test Link Text"
|
||||||
|
assert_contain("Webrat Form")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should click link by id" do
|
||||||
|
visit internal_redirect_path
|
||||||
|
click_link "link_id"
|
||||||
|
assert_contain("Webrat Form")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should be able to assert xpath" do
|
||||||
|
visit root_path
|
||||||
|
assert_have_xpath "//h1"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should be able to assert selector" do
|
||||||
|
visit root_path
|
||||||
|
assert_have_selector "h1"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
48
spec/integration/rails/test/selenium/webrat_test.rb
Normal file
48
spec/integration/rails/test/selenium/webrat_test.rb
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class WebratTest < ActionController::IntegrationTest
|
||||||
|
test "should visit pages" do
|
||||||
|
visit root_path
|
||||||
|
assert_contain("Webrat Form")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should submit forms" do
|
||||||
|
visit root_path
|
||||||
|
fill_in "Text field", :with => "Hello"
|
||||||
|
check "TOS"
|
||||||
|
select "January"
|
||||||
|
click_button "Test"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should follow internal redirects" do
|
||||||
|
visit internal_redirect_path
|
||||||
|
assert response_body.include?("OK")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should not follow external redirects" do
|
||||||
|
visit external_redirect_path
|
||||||
|
assert response.redirect?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should click link by text" do
|
||||||
|
visit internal_redirect_path
|
||||||
|
click_link "Test Link Text"
|
||||||
|
assert_contain("Webrat Form")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should click link by id" do
|
||||||
|
visit internal_redirect_path
|
||||||
|
click_link "link_id"
|
||||||
|
assert_contain("Webrat Form")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should be able to assert xpath" do
|
||||||
|
visit root_path
|
||||||
|
assert_have_xpath "//h1"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should be able to assert selector" do
|
||||||
|
visit root_path
|
||||||
|
assert_have_selector "h1"
|
||||||
|
end
|
||||||
|
end
|
@ -6,7 +6,7 @@ require "redgreen"
|
|||||||
require File.dirname(__FILE__) + "/../../../../lib/webrat"
|
require File.dirname(__FILE__) + "/../../../../lib/webrat"
|
||||||
|
|
||||||
Webrat.configure do |config|
|
Webrat.configure do |config|
|
||||||
config.mode = :rails
|
config.mode = ENV['WEBRAT_INTEGRATION_MODE'].to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
ActionController::Base.class_eval do
|
ActionController::Base.class_eval do
|
||||||
|
0
spec/integration/rails/tmp/pids/placeholder.txt
Normal file
0
spec/integration/rails/tmp/pids/placeholder.txt
Normal file
0
spec/integration/rails/tmp/placeholder.txt
Normal file
0
spec/integration/rails/tmp/placeholder.txt
Normal file
Loading…
Reference in New Issue
Block a user