Merge branch 'lh_82' of git@github.com:gaffo/webrat
This commit is contained in:
commit
cbddebd01c
15
Rakefile
15
Rakefile
@ -109,13 +109,24 @@ namespace :spec do
|
|||||||
|
|
||||||
namespace :integration do
|
namespace :integration do
|
||||||
desc "Run the Rails integration specs"
|
desc "Run the Rails integration specs"
|
||||||
task :rails do
|
task :rails => ['rails:webrat','rails:selenium']
|
||||||
|
|
||||||
|
namespace :rails do
|
||||||
|
task :selenium do
|
||||||
Dir.chdir "spec/integration/rails" do
|
Dir.chdir "spec/integration/rails" do
|
||||||
result = system "rake test:integration"
|
result = system "rake test_unit:selenium"
|
||||||
raise "Rails integration tests failed" unless result
|
raise "Rails integration tests failed" unless result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
task :webrat do
|
||||||
|
Dir.chdir "spec/integration/rails" do
|
||||||
|
result = system "rake test_unit:rails"
|
||||||
|
raise "Rails integration tests failed" unless result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
desc "Run the Merb integration specs"
|
desc "Run the Merb integration specs"
|
||||||
task :merb do
|
task :merb do
|
||||||
Dir.chdir "spec/integration/merb" do
|
Dir.chdir "spec/integration/merb" do
|
||||||
|
@ -26,7 +26,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.start_app_server #:nodoc:
|
def self.start_app_server #:nodoc:
|
||||||
pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid")
|
pid_file = prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium.pid")
|
||||||
system("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &")
|
system("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &")
|
||||||
TCPSocket.wait_for_service :host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i
|
TCPSocket.wait_for_service :host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i
|
||||||
end
|
end
|
||||||
@ -36,6 +36,11 @@ module Webrat
|
|||||||
system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
|
system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.prepare_pid_file(file_path, pid_file_name)
|
||||||
|
FileUtils.mkdir_p File.expand_path(file_path)
|
||||||
|
File.expand_path("#{file_path}/#{pid_file_name}")
|
||||||
|
end
|
||||||
|
|
||||||
# To use Webrat's Selenium support, you'll need the selenium-client gem installed.
|
# To use Webrat's Selenium support, you'll need the selenium-client gem installed.
|
||||||
# Activate it with (for example, in your <tt>env.rb</tt>):
|
# Activate it with (for example, in your <tt>env.rb</tt>):
|
||||||
#
|
#
|
||||||
|
2
spec/integration/rails/.gitignore
vendored
2
spec/integration/rails/.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
vendor/plugins/webrat
|
vendor/plugins/webrat
|
||||||
|
tmp/pids/*.pid
|
||||||
|
log/*.log
|
||||||
|
@ -8,3 +8,23 @@ 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:integration'].execute
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "runs the test::unit based tests in selenium mode"
|
||||||
|
task :selenium do
|
||||||
|
ENV['WEBRAT_INTEGRATION_MODE'] = 'selenium'
|
||||||
|
Rake::Task['test:integration'].execute
|
||||||
|
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
|
@ -1,17 +0,0 @@
|
|||||||
require 'test_helper'
|
|
||||||
|
|
||||||
class WebratTest < ActionController::IntegrationTest
|
|
||||||
|
|
||||||
test "should scope within an object" do
|
|
||||||
visit root_path
|
|
||||||
|
|
||||||
within FakeModel.new do
|
|
||||||
fill_in "Object field", :with => "Test"
|
|
||||||
|
|
||||||
assert_raise Webrat::NotFoundError do
|
|
||||||
check "TOS"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
@ -9,8 +9,7 @@ class WebratTest < ActionController::IntegrationTest
|
|||||||
|
|
||||||
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
|
||||||
@ -37,7 +36,6 @@ class WebratTest < ActionController::IntegrationTest
|
|||||||
|
|
||||||
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
|
||||||
@ -47,4 +45,25 @@ class WebratTest < ActionController::IntegrationTest
|
|||||||
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
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
ENV["RAILS_ENV"] = "test"
|
ENV["RAILS_ENV"] = "test"
|
||||||
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
||||||
require 'test_help'
|
require 'test_help'
|
||||||
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
|
||||||
|
@ -10,12 +10,19 @@ describe Webrat, "Selenium" do
|
|||||||
|
|
||||||
it "should start the app server with correct config options" do
|
it "should start the app server with correct config options" do
|
||||||
pid_file = "file"
|
pid_file = "file"
|
||||||
File.should_receive(:expand_path).with(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid").and_return pid_file
|
Webrat.should_receive(:prepare_pid_file).with("#{RAILS_ROOT}/tmp/pids","mongrel_selenium.pid").and_return pid_file
|
||||||
Webrat.should_receive(:system).with("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &")
|
Webrat.should_receive(:system).with("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &")
|
||||||
TCPSocket.should_receive(:wait_for_service).with(:host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i)
|
TCPSocket.should_receive(:wait_for_service).with(:host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i)
|
||||||
Webrat.start_app_server
|
Webrat.start_app_server
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'prepare_pid_file' do
|
||||||
|
File.should_receive(:expand_path).with('path').and_return('full_path')
|
||||||
|
FileUtils.should_receive(:mkdir_p).with 'full_path'
|
||||||
|
File.should_receive(:expand_path).with('path/name')
|
||||||
|
Webrat.prepare_pid_file 'path', 'name'
|
||||||
|
end
|
||||||
|
|
||||||
describe "start_selenium_server" do
|
describe "start_selenium_server" do
|
||||||
it "should not start the local selenium server if the selenium_server_address is set" do
|
it "should not start the local selenium server if the selenium_server_address is set" do
|
||||||
Webrat.configuration.selenium_server_address = 'foo address'
|
Webrat.configuration.selenium_server_address = 'foo address'
|
||||||
|
Loading…
Reference in New Issue
Block a user