Adding two tests for Rails integration
This commit is contained in:
parent
39e0200608
commit
add38820e5
10
spec/integration/rails/app/controllers/webrat_controller.rb
Normal file
10
spec/integration/rails/app/controllers/webrat_controller.rb
Normal file
@ -0,0 +1,10 @@
|
||||
class WebratController < ApplicationController
|
||||
|
||||
def form
|
||||
end
|
||||
|
||||
def submit
|
||||
render :text => "OK"
|
||||
end
|
||||
|
||||
end
|
17
spec/integration/rails/app/views/webrat/form.html.erb
Normal file
17
spec/integration/rails/app/views/webrat/form.html.erb
Normal file
@ -0,0 +1,17 @@
|
||||
<h1>Webrat Form</h1>
|
||||
|
||||
<% form_tag submit_path do %>
|
||||
<label>
|
||||
Text field <%= text_field_tag "text_field" %>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
TOS <%= check_box_tag "tos" %>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
<%= select_tag "month", "<option></option><option>January</option>" %>
|
||||
</label>
|
||||
|
||||
<%= submit_tag "Test" %>
|
||||
<% end %>
|
@ -1,43 +1,6 @@
|
||||
ActionController::Routing::Routes.draw do |map|
|
||||
# The priority is based upon order of creation: first created -> highest priority.
|
||||
|
||||
# Sample of regular route:
|
||||
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
|
||||
# Keep in mind you can assign values other than :controller and :action
|
||||
|
||||
# Sample of named route:
|
||||
# map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
|
||||
# This route can be invoked with purchase_url(:id => product.id)
|
||||
|
||||
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
||||
# map.resources :products
|
||||
|
||||
# Sample resource route with options:
|
||||
# map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
|
||||
|
||||
# Sample resource route with sub-resources:
|
||||
# map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
|
||||
|
||||
# Sample resource route with more complex sub-resources
|
||||
# map.resources :products do |products|
|
||||
# products.resources :comments
|
||||
# products.resources :sales, :collection => { :recent => :get }
|
||||
# end
|
||||
|
||||
# Sample resource route within a namespace:
|
||||
# map.namespace :admin do |admin|
|
||||
# # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
|
||||
# admin.resources :products
|
||||
# end
|
||||
|
||||
# You can have the root of your site routed with map.root -- just remember to delete public/index.html.
|
||||
# map.root :controller => "welcome"
|
||||
|
||||
# See how all your routes lay out with "rake routes"
|
||||
|
||||
# Install the default routes as the lowest priority.
|
||||
# Note: These default routes make all actions in every controller accessible via GET requests. You should
|
||||
# consider removing the them or commenting them out if you're using named routes and resources.
|
||||
map.connect ':controller/:action/:id'
|
||||
map.connect ':controller/:action/:id.:format'
|
||||
map.with_options :controller => "webrat" do |webrat|
|
||||
webrat.submit "/submit", :action => "submit"
|
||||
webrat.root :action => "form"
|
||||
end
|
||||
end
|
||||
|
@ -1,7 +1,17 @@
|
||||
require 'test_helper'
|
||||
|
||||
class WebratTest < ActionController::IntegrationTest
|
||||
test "should pass" do
|
||||
assert true
|
||||
test "should visit pages" do
|
||||
visit root_path
|
||||
assert_tag "Webrat Form"
|
||||
assert response.body.include?("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
|
||||
end
|
||||
|
@ -1,38 +1,21 @@
|
||||
ENV["RAILS_ENV"] = "test"
|
||||
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
||||
require 'test_help'
|
||||
require "redgreen"
|
||||
|
||||
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
|
||||
require "webrat"
|
||||
|
||||
# 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.
|
||||
#
|
||||
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
||||
# -- they do not yet inherit this setting
|
||||
fixtures :all
|
||||
|
||||
# Add more helper methods to be used by all tests here...
|
||||
Webrat.configure do |config|
|
||||
config.mode = :rails
|
||||
end
|
||||
|
||||
ActionController::Base.class_eval do
|
||||
def perform_action
|
||||
perform_action_without_rescue
|
||||
end
|
||||
end
|
||||
Dispatcher.class_eval do
|
||||
def self.failsafe_response(output, status, exception = nil)
|
||||
raise exception
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user