public
Description: Webrat - Ruby Acceptance Testing for Web applications
Homepage: http://gitrdoc.com/brynary/webrat/tree/master/
Clone URL: git://github.com/brynary/webrat.git
Adding two tests for Rails integration
brynary (author)
Sun Dec 28 22:30:26 -0800 2008
commit  add38820e58cba6a7e1ee62155c29480a9d1d913
tree    6ce4514085d58fd3de6220a4018b532d923e47f0
parent  39e0200608ea9fc6b6e5f015b2b1592da8154c85
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
 
 
 
43
...
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
3
4
5
6
0
@@ -1,43 +1,6 @@
0
 ActionController::Routing::Routes.draw do |map|
0
-  # The priority is based upon order of creation: first created -> highest priority.
0
-
0
-  # Sample of regular route:
0
-  #   map.connect 'products/:id', :controller => 'catalog', :action => 'view'
0
-  # Keep in mind you can assign values other than :controller and :action
0
-
0
-  # Sample of named route:
0
-  #   map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
0
-  # This route can be invoked with purchase_url(:id => product.id)
0
-
0
-  # Sample resource route (maps HTTP verbs to controller actions automatically):
0
-  #   map.resources :products
0
-
0
-  # Sample resource route with options:
0
-  #   map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
0
-
0
-  # Sample resource route with sub-resources:
0
-  #   map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
0
-  
0
-  # Sample resource route with more complex sub-resources
0
-  #   map.resources :products do |products|
0
-  #     products.resources :comments
0
-  #     products.resources :sales, :collection => { :recent => :get }
0
-  #   end
0
-
0
-  # Sample resource route within a namespace:
0
-  #   map.namespace :admin do |admin|
0
-  #     # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
0
-  #     admin.resources :products
0
-  #   end
0
-
0
-  # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
0
-  # map.root :controller => "welcome"
0
-
0
-  # See how all your routes lay out with "rake routes"
0
-
0
-  # Install the default routes as the lowest priority.
0
-  # Note: These default routes make all actions in every controller accessible via GET requests. You should
0
-  # consider removing the them or commenting them out if you're using named routes and resources.
0
-  map.connect ':controller/:action/:id'
0
-  map.connect ':controller/:action/:id.:format'
0
+  map.with_options :controller => "webrat" do |webrat|
0
+    webrat.submit "/submit",  :action => "submit"
0
+    webrat.root               :action => "form"
0
+  end
0
 end
...
1
2
3
4
5
 
 
 
 
 
 
 
 
 
 
 
 
6
7
...
1
2
3
 
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
0
@@ -1,7 +1,17 @@
0
 require 'test_helper'
0
 
0
 class WebratTest < ActionController::IntegrationTest
0
-  test "should pass" do
0
-    assert true
0
+  test "should visit pages" do
0
+    visit root_path
0
+    assert_tag "Webrat Form"
0
+    assert response.body.include?("Webrat Form")
0
+  end
0
+  
0
+  test "should submit forms" do
0
+    visit root_path
0
+    fill_in "Text field", :with => "Hello"
0
+    check "TOS"
0
+    select "January"
0
+    click_button "Test"
0
   end
0
 end
...
1
2
3
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
23
24
25
26
27
28
29
30
31
32
33
34
35
 
 
 
36
37
 
 
 
 
38
 
 
 
 
 
39
...
1
2
3
4
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
7
 
 
 
 
 
 
 
 
 
 
 
 
8
9
10
11
 
12
13
14
15
16
17
18
19
20
21
22
0
@@ -1,38 +1,21 @@
0
 ENV["RAILS_ENV"] = "test"
0
 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
0
 require 'test_help'
0
+require "redgreen"
0
 
0
-class Test::Unit::TestCase
0
-  # Transactional fixtures accelerate your tests by wrapping each test method
0
-  # in a transaction that's rolled back on completion.  This ensures that the
0
-  # test database remains unchanged so your fixtures don't have to be reloaded
0
-  # between every test method.  Fewer database queries means faster tests.
0
-  #
0
-  # Read Mike Clark's excellent walkthrough at
0
-  #   http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
0
-  #
0
-  # Every Active Record database supports transactions except MyISAM tables
0
-  # in MySQL.  Turn off transactional fixtures in this case; however, if you
0
-  # don't care one way or the other, switching from MyISAM to InnoDB tables
0
-  # is recommended.
0
-  #
0
-  # The only drawback to using transactional fixtures is when you actually 
0
-  # need to test transactions.  Since your test is bracketed by a transaction,
0
-  # any transactions started in your code will be automatically rolled back.
0
-  self.use_transactional_fixtures = true
0
+require "webrat"
0
 
0
-  # Instantiated fixtures are slow, but give you @david where otherwise you
0
-  # would need people(:david).  If you don't want to migrate your existing
0
-  # test cases which use the @david style and don't mind the speed hit (each
0
-  # instantiated fixtures translates to a database query per test method),
0
-  # then set this back to true.
0
-  self.use_instantiated_fixtures  = false
0
-
0
-  # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
0
-  #
0
-  # Note: You'll currently still have to declare fixtures explicitly in integration tests
0
-  # -- they do not yet inherit this setting
0
-  fixtures :all
0
+Webrat.configure do |config|
0
+  config.mode = :rails
0
+end
0
 
0
-  # Add more helper methods to be used by all tests here...
0
+ActionController::Base.class_eval do
0
+  def perform_action
0
+    perform_action_without_rescue
0
+  end
0
 end
0
+Dispatcher.class_eval do
0
+  def self.failsafe_response(output, status, exception = nil)
0
+    raise exception
0
+  end
0
+end
0
\ No newline at end of file

Comments