edbond (owner)

Fork Of

gist: 34167 by cavalle cucumber + webrat + seleniu...

Revisions

gist: 72847 Download_button fork
public
Public Clone URL: git://gist.github.com/72847.git
Embed All Files: show embed
Ruby #
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#
# cucumber.yml
#
 
# Filter which features are run with each profile by the file extension
webrat: --require features/steps/common --require features/support/webrat_env.rb --exclude selenium.feature --format progress
selenium: --require features/steps/common --require features/support/selenium_env.rb --exclude webrat.feature --format progress
 
#
# features/support/env.rb
#
 
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
 
require 'cucumber/rails/world'
require 'cucumber/rails/rspec'
require 'webrat/rspec-rails'
 
#
# features/support/webrat_env.rb
#
 
require File.expand_path(File.dirname(__FILE__) + '/env.rb')
require 'webrat/rails'
require File.expand_path(File.dirname(__FILE__) + '/../../lib/webrat_hacks.rb')
 
Cucumber::Rails.use_transactional_fixtures
 
#
# features/support/selenium_env.rb
#
 
require File.expand_path(File.dirname(__FILE__) + '/env.rb')
require 'webrat/selenium'
require File.expand_path(File.dirname(__FILE__) + '/../../lib/webrat_hacks.rb')
 
World do
  Webrat::Selenium::Rails::World.new
end
 
def empty_database
  connection = ActiveRecord::Base.connection
  connection.tables.each do |table|
    connection.execute "DELETE FROM #{table}"
  end
end
 
Before do
  empty_database
  selenium.delete_all_visible_cookies
  ActionMailer::Base.deliveries = []
end
 
at_exit do
  empty_database
end
 
#
# lib/webrat_hacks.rb
#
 
class Webrat::RailsSession
  
  # This method returns the current location of the current page even if
  # a redirection has ocurred. Not sure if there is already a method doing the same
  # thing in webrat API.
  #
  # Useful to implement steps like: "Then I should have been redirected to the home page"
  def request_path
    integration_session.request.path
  end
  
end
 
class Webrat::SeleniumSession
 
  # Selenium version of request_path
  def request_path
    selenium.get_location.gsub("http://127.0.0.1:3001", "")
  end
  
end
 
# Make the request_path method available to the steps
Webrat::Methods.delegate_to_session :request_path
 
module Webrat
  
  # Start the app server using Polonium to enable access to ActionMailer.deliveries
  # from acceptance tests while using Selenium, which is not possible if the
  # server is started manually or the way webrat start it by default
  def self.start_app_server
    Polonium::Configuration.instance.app_server_runner.start
  end
  
  def self.stop_app_server
    Polonium::Configuration.instance.app_server_runner.stop
  end
  
  # We prefer to start selenium server manually and keep it running to make
  # the execution of features faster (especially using --browserSessionReuse)
  def self.start_selenium_server
    nil
  end
  
  def self.stop_selenium_server
    nil
  end
  
end
 
# Polonium configuration and initialization
Polonium::Configuration.instance.app_server_engine = :mongrel
Polonium::Configuration.instance.internal_app_server_port = 3001
Polonium::Configuration.instance.create_app_server_runner