davidtrogers-webrat 0.4.4.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/.gitignore +3 -1
  2. data/Gemfile +19 -0
  3. data/History.txt +99 -9
  4. data/Rakefile +141 -207
  5. data/Thorfile +118 -0
  6. data/lib/webrat.rb +10 -23
  7. data/lib/webrat/{mechanize.rb → adapters/mechanize.rb} +6 -2
  8. data/lib/webrat/adapters/merb.rb +11 -0
  9. data/lib/webrat/adapters/rack.rb +25 -0
  10. data/lib/webrat/{rails.rb → adapters/rails.rb} +5 -37
  11. data/lib/webrat/adapters/sinatra.rb +9 -0
  12. data/lib/webrat/core.rb +0 -1
  13. data/lib/webrat/core/configuration.rb +22 -18
  14. data/lib/webrat/core/elements/area.rb +2 -2
  15. data/lib/webrat/core/elements/element.rb +3 -3
  16. data/lib/webrat/core/elements/field.rb +113 -31
  17. data/lib/webrat/core/elements/form.rb +4 -4
  18. data/lib/webrat/core/elements/label.rb +4 -4
  19. data/lib/webrat/core/elements/link.rb +8 -7
  20. data/lib/webrat/core/elements/select_option.rb +15 -2
  21. data/lib/webrat/core/locators.rb +1 -1
  22. data/lib/webrat/core/locators/area_locator.rb +3 -3
  23. data/lib/webrat/core/locators/button_locator.rb +6 -6
  24. data/lib/webrat/core/locators/field_by_id_locator.rb +3 -3
  25. data/lib/webrat/core/locators/field_labeled_locator.rb +2 -2
  26. data/lib/webrat/core/locators/field_named_locator.rb +3 -3
  27. data/lib/webrat/core/locators/form_locator.rb +1 -1
  28. data/lib/webrat/core/locators/label_locator.rb +2 -2
  29. data/lib/webrat/core/locators/link_locator.rb +16 -8
  30. data/lib/webrat/core/locators/select_option_locator.rb +5 -5
  31. data/lib/webrat/core/logging.rb +4 -5
  32. data/lib/webrat/core/matchers/have_content.rb +3 -8
  33. data/lib/webrat/core/matchers/have_xpath.rb +3 -28
  34. data/lib/webrat/core/methods.rb +5 -4
  35. data/lib/webrat/core/mime.rb +11 -22
  36. data/lib/webrat/core/save_and_open_page.rb +7 -29
  37. data/lib/webrat/core/scope.rb +17 -2
  38. data/lib/webrat/core/session.rb +31 -19
  39. data/lib/webrat/core/xml.rb +41 -84
  40. data/lib/webrat/integrations/merb.rb +10 -0
  41. data/lib/webrat/integrations/rails.rb +25 -0
  42. data/lib/webrat/integrations/rspec-rails.rb +11 -0
  43. data/lib/webrat/integrations/selenium.rb +11 -0
  44. data/lib/webrat/rspec-rails.rb +2 -13
  45. data/lib/webrat/selenium.rb +0 -11
  46. data/lib/webrat/selenium/application_server_factory.rb +40 -0
  47. data/lib/webrat/selenium/application_servers.rb +5 -0
  48. data/lib/webrat/selenium/application_servers/base.rb +46 -0
  49. data/lib/webrat/selenium/application_servers/external.rb +26 -0
  50. data/lib/webrat/selenium/application_servers/merb.rb +50 -0
  51. data/lib/webrat/selenium/application_servers/rails.rb +44 -0
  52. data/lib/webrat/selenium/application_servers/sinatra.rb +37 -0
  53. data/lib/webrat/selenium/location_strategy_javascript/label.js +30 -3
  54. data/lib/webrat/selenium/location_strategy_javascript/webrat.js +1 -0
  55. data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +24 -4
  56. data/lib/webrat/selenium/matchers/have_content.rb +22 -10
  57. data/lib/webrat/selenium/matchers/have_selector.rb +8 -0
  58. data/lib/webrat/selenium/matchers/have_xpath.rb +8 -0
  59. data/lib/webrat/selenium/selenium_rc_server.rb +8 -6
  60. data/lib/webrat/selenium/selenium_session.rb +43 -14
  61. data/lib/webrat/selenium/silence_stream.rb +2 -2
  62. data/spec/fakes/{test_session.rb → test_adapter.rb} +4 -5
  63. data/spec/integration/mechanize/Rakefile +7 -0
  64. data/spec/integration/mechanize/config.ru +2 -0
  65. data/spec/integration/mechanize/sample_app.rb +20 -0
  66. data/spec/integration/mechanize/spec/mechanize_spec.rb +22 -0
  67. data/spec/integration/mechanize/spec/spec_helper.rb +29 -0
  68. data/spec/integration/merb/app/controllers/testing.rb +9 -0
  69. data/spec/integration/merb/app/views/testing/upload.html.erb +9 -0
  70. data/spec/integration/merb/config/router.rb +1 -0
  71. data/spec/integration/merb/spec/spec_helper.rb +2 -0
  72. data/spec/integration/merb/spec/webrat_spec.rb +7 -0
  73. data/spec/integration/rack/app.rb +89 -0
  74. data/spec/integration/rack/test/helper.rb +21 -0
  75. data/spec/integration/rack/test/webrat_rack_test.rb +57 -51
  76. data/spec/integration/rails/app/controllers/{application.rb → application_controller.rb} +0 -0
  77. data/spec/integration/rails/app/controllers/webrat_controller.rb +16 -9
  78. data/spec/integration/rails/app/views/buttons/show.html.erb +0 -2
  79. data/spec/integration/rails/app/views/links/show.html.erb +2 -1
  80. data/spec/integration/rails/app/views/webrat/buttons.html.erb +0 -2
  81. data/spec/integration/rails/app/views/webrat/within.html.erb +3 -0
  82. data/spec/integration/rails/config/environment.rb +1 -1
  83. data/spec/integration/rails/config/routes.rb +2 -0
  84. data/spec/integration/rails/test/integration/button_click_test.rb +12 -26
  85. data/spec/integration/rails/test/integration/fill_in_test.rb +1 -1
  86. data/spec/integration/rails/test/integration/link_click_test.rb +8 -2
  87. data/spec/integration/rails/test/integration/webrat_test.rb +53 -5
  88. data/spec/integration/rails/test/test_helper.rb +7 -5
  89. data/spec/integration/sinatra/test/test_helper.rb +3 -2
  90. data/spec/private/core/configuration_spec.rb +8 -27
  91. data/spec/private/core/field_spec.rb +14 -16
  92. data/spec/private/core/link_spec.rb +1 -1
  93. data/spec/private/core/session_spec.rb +23 -26
  94. data/spec/private/mechanize/{mechanize_session_spec.rb → mechanize_adapter_spec.rb} +4 -12
  95. data/spec/private/nokogiri_spec.rb +2 -2
  96. data/spec/private/rails/{rails_session_spec.rb → rails_adapter_spec.rb} +11 -42
  97. data/spec/private/selenium/application_servers/rails_spec.rb +26 -0
  98. data/spec/public/basic_auth_spec.rb +13 -2
  99. data/spec/public/click_button_spec.rb +10 -12
  100. data/spec/public/click_link_spec.rb +21 -0
  101. data/spec/public/fill_in_spec.rb +15 -0
  102. data/spec/public/matchers/contain_spec.rb +12 -19
  103. data/spec/public/matchers/have_selector_spec.rb +6 -2
  104. data/spec/public/matchers/have_xpath_spec.rb +3 -3
  105. data/spec/public/save_and_open_spec.rb +15 -17
  106. data/spec/public/select_spec.rb +232 -26
  107. data/spec/public/selenium/application_server_factory_spec.rb +49 -0
  108. data/spec/public/selenium/application_servers/external_spec.rb +12 -0
  109. data/spec/public/selenium/selenium_session_spec.rb +37 -0
  110. data/spec/spec_helper.rb +5 -1
  111. data/vendor/selenium-server.jar +0 -0
  112. metadata +119 -69
  113. data/.dotest/0001 +0 -34
  114. data/.dotest/0002 +0 -34
  115. data/.dotest/binary +0 -1
  116. data/.dotest/final-commit +0 -1
  117. data/.dotest/head-name +0 -1
  118. data/.dotest/info +0 -5
  119. data/.dotest/keep +0 -1
  120. data/.dotest/last +0 -1
  121. data/.dotest/msg +0 -0
  122. data/.dotest/msg-clean +0 -0
  123. data/.dotest/next +0 -1
  124. data/.dotest/onto +0 -1
  125. data/.dotest/orig-head +0 -1
  126. data/.dotest/patch +0 -29
  127. data/.dotest/sign +0 -1
  128. data/.dotest/utf8 +0 -1
  129. data/.dotest/whitespace +0 -1
  130. data/VERSION +0 -1
  131. data/lib/webrat/core/xml/hpricot.rb +0 -19
  132. data/lib/webrat/core/xml/nokogiri.rb +0 -76
  133. data/lib/webrat/core/xml/rexml.rb +0 -24
  134. data/lib/webrat/merb_session.rb +0 -65
  135. data/lib/webrat/rack.rb +0 -24
  136. data/lib/webrat/rack_test.rb +0 -32
  137. data/lib/webrat/selenium/application_server.rb +0 -73
  138. data/lib/webrat/selenium/merb_application_server.rb +0 -48
  139. data/lib/webrat/selenium/rails_application_server.rb +0 -42
  140. data/lib/webrat/selenium/sinatra_application_server.rb +0 -35
  141. data/lib/webrat/sinatra.rb +0 -44
  142. data/spec/integration/rack/rack_app.rb +0 -16
  143. data/spec/integration/rack/test/test_helper.rb +0 -20
  144. data/spec/private/core/logging_spec.rb +0 -10
  145. data/spec/private/merb/merb_session_spec.rb +0 -42
@@ -13,21 +13,30 @@ module Webrat
13
13
  end
14
14
 
15
15
  def self.session_class
16
+ if Webrat.configuration.mode == :selenium
17
+ SeleniumSession
18
+ else
19
+ Session
20
+ end
21
+ end
22
+
23
+ def self.adapter_class
16
24
  case Webrat.configuration.mode
17
25
  when :rails
18
- RailsSession
26
+ RailsAdapter
19
27
  when :merb
20
- MerbSession
21
- when :selenium
22
- SeleniumSession
28
+ MerbAdapter
23
29
  when :rack
24
- RackSession
30
+ RackAdapter
31
+ when :rack_test
32
+ warn("The :rack_test mode is deprecated. Please use :rack instead")
33
+ require "webrat/rack"
34
+ RackAdapter
25
35
  when :sinatra
26
- SinatraSession
36
+ warn("The :sinatra mode is deprecated. Please use :rack instead")
37
+ SinatraAdapter
27
38
  when :mechanize
28
- MechanizeSession
29
- when :rack_test
30
- RackTestSession
39
+ MechanizeAdapter
31
40
  else
32
41
  raise WebratError.new(<<-STR)
33
42
  Unknown Webrat mode: #{Webrat.configuration.mode.inspect}
@@ -50,16 +59,22 @@ For example:
50
59
  extend Forwardable
51
60
  include Logging
52
61
  include SaveAndOpenPage
62
+
63
+ attr_accessor :adapter
64
+
53
65
  attr_reader :current_url
54
66
  attr_reader :elements
55
67
 
56
- def initialize(context = nil) #:nodoc:
68
+ def_delegators :@adapter, :response, :response_code, :response_body,
69
+ :response_body=, :response_code=,
70
+ :get, :post, :put, :delete
71
+
72
+ def initialize(adapter = nil)
73
+ @adapter = adapter
57
74
  @http_method = :get
58
75
  @data = {}
59
76
  @default_headers = {}
60
77
  @custom_headers = {}
61
- @context = context
62
-
63
78
  reset
64
79
  end
65
80
 
@@ -77,10 +92,6 @@ For example:
77
92
  page
78
93
  end
79
94
 
80
- def doc_root #:nodoc:
81
- nil
82
- end
83
-
84
95
  def header(key, value)
85
96
  @custom_headers[key] = value
86
97
  end
@@ -90,7 +101,7 @@ For example:
90
101
  end
91
102
 
92
103
  def basic_auth(user, pass)
93
- encoded_login = ["#{user}:#{pass}"].pack("m*")
104
+ encoded_login = ["#{user}:#{pass}"].pack("m*").gsub(/\n/, '')
94
105
  header('HTTP_AUTHORIZATION', "Basic #{encoded_login}")
95
106
  end
96
107
 
@@ -144,7 +155,7 @@ For example:
144
155
  end
145
156
 
146
157
  def redirect? #:nodoc:
147
- response_code / 100 == 3
158
+ (response_code / 100).to_i == 3
148
159
  end
149
160
 
150
161
  def internal_redirect?
@@ -245,6 +256,7 @@ For example:
245
256
  def_delegators :current_scope, :uncheck, :unchecks
246
257
  def_delegators :current_scope, :choose, :chooses
247
258
  def_delegators :current_scope, :select, :selects
259
+ def_delegators :current_scope, :unselect, :unselects
248
260
  def_delegators :current_scope, :select_datetime, :selects_datetime
249
261
  def_delegators :current_scope, :select_date, :selects_date
250
262
  def_delegators :current_scope, :select_time, :selects_time
@@ -273,7 +285,7 @@ For example:
273
285
  end
274
286
 
275
287
  def current_host
276
- URI.parse(current_url).host || "www.example.com"
288
+ URI.parse(current_url).host || @custom_headers["Host"] || "www.example.com"
277
289
  end
278
290
 
279
291
  def response_location_host
@@ -1,115 +1,72 @@
1
- require "webrat/core/xml/nokogiri"
2
- require "webrat/core/xml/hpricot"
3
- require "webrat/core/xml/rexml"
1
+ require "webrat/core_extensions/meta_class"
4
2
 
5
3
  module Webrat #:nodoc:
6
4
  module XML #:nodoc:
7
5
 
8
6
  def self.document(stringlike) #:nodoc:
9
- if Webrat.configuration.parse_with_nokogiri?
10
- Webrat.nokogiri_document(stringlike)
7
+ return stringlike.dom if stringlike.respond_to?(:dom)
8
+
9
+ if Nokogiri::HTML::Document === stringlike
10
+ stringlike
11
+ elsif Nokogiri::XML::NodeSet === stringlike
12
+ stringlike
13
+ elsif stringlike.respond_to?(:body)
14
+ Nokogiri::HTML(stringlike.body.to_s)
11
15
  else
12
- Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
16
+ Nokogiri::HTML(stringlike.to_s)
13
17
  end
14
18
  end
15
19
 
16
20
  def self.html_document(stringlike) #:nodoc:
17
- if Webrat.configuration.parse_with_nokogiri?
18
- Webrat.html_nokogiri_document(stringlike)
21
+ return stringlike.dom if stringlike.respond_to?(:dom)
22
+
23
+ if Nokogiri::HTML::Document === stringlike
24
+ stringlike
25
+ elsif Nokogiri::XML::NodeSet === stringlike
26
+ stringlike
27
+ elsif stringlike.respond_to?(:body)
28
+ Nokogiri::HTML(stringlike.body.to_s)
19
29
  else
20
- Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
30
+ Nokogiri::HTML(stringlike.to_s)
21
31
  end
22
32
  end
23
33
 
24
34
  def self.xml_document(stringlike) #:nodoc:
25
- if Webrat.configuration.parse_with_nokogiri?
26
- Webrat.xml_nokogiri_document(stringlike)
35
+ return stringlike.dom if stringlike.respond_to?(:dom)
36
+
37
+ if Nokogiri::HTML::Document === stringlike
38
+ stringlike
39
+ elsif Nokogiri::XML::NodeSet === stringlike
40
+ stringlike
41
+ elsif stringlike.respond_to?(:body)
42
+ Nokogiri::XML(stringlike.body.to_s)
27
43
  else
28
- Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
44
+ Nokogiri::XML(stringlike.to_s)
29
45
  end
30
46
  end
31
47
 
32
- def self.to_html(element)
33
- if Webrat.configuration.parse_with_nokogiri?
34
- element.to_html
35
- else
36
- element.to_s
48
+ def self.define_dom_method(object, dom) #:nodoc:
49
+ object.meta_class.send(:define_method, :dom) do
50
+ dom
37
51
  end
38
52
  end
39
53
 
40
- def self.inner_html(element)
41
- if Webrat.configuration.parse_with_nokogiri?
42
- element.inner_html
43
- else
44
- element.text
45
- end
46
- end
47
-
48
- def self.all_inner_text(element)
49
- if Webrat.configuration.parse_with_nokogiri?
50
- element.inner_text
51
- else
52
- Hpricot(element.to_s).children.first.inner_text
53
- end
54
- end
54
+ end
55
+ end
55
56
 
56
- def self.inner_text(element)
57
- if Webrat.configuration.parse_with_nokogiri?
58
- element.inner_text
59
- else
60
- if defined?(Hpricot::Doc) && element.is_a?(Hpricot::Doc)
61
- element.inner_text
62
- else
63
- element.text
64
- end
65
- end
66
- end
57
+ module Nokogiri #:nodoc:
58
+ module CSS #:nodoc:
59
+ class XPathVisitor #:nodoc:
67
60
 
68
- def self.xpath_to(element)
69
- if Webrat.configuration.parse_with_nokogiri?
70
- element.path
71
- else
72
- element.xpath
61
+ def visit_pseudo_class_text(node) #:nodoc:
62
+ "@type='text'"
73
63
  end
74
- end
75
-
76
- def self.attribute(element, attribute_name)
77
- return element[attribute_name] if element.is_a?(Hash)
78
64
 
79
- if Webrat.configuration.parse_with_nokogiri?
80
- element[attribute_name]
81
- else
82
- element.attributes[attribute_name]
65
+ def visit_pseudo_class_password(node) #:nodoc:
66
+ "@type='password'"
83
67
  end
84
- end
85
-
86
- def self.xpath_at(*args)
87
- xpath_search(*args).first
88
- end
89
-
90
- def self.css_at(*args)
91
- css_search(*args).first
92
- end
93
-
94
- def self.xpath_search(element, *searches)
95
- searches.flatten.map do |search|
96
- if Webrat.configuration.parse_with_nokogiri?
97
- element.xpath(search)
98
- else
99
- REXML::XPath.match(element, search)
100
- end
101
- end.flatten.compact
102
- end
103
68
 
104
- def self.css_search(element, *searches) #:nodoc:
105
- xpath_search(element, css_to_xpath(*searches))
106
69
  end
107
-
108
- def self.css_to_xpath(*selectors)
109
- selectors.map do |rule|
110
- Nokogiri::CSS.xpath_for(rule, :prefix => ".//")
111
- end.flatten.uniq
112
- end
113
-
114
70
  end
115
71
  end
72
+
@@ -0,0 +1,10 @@
1
+ module Merb #:nodoc:
2
+ module Test #:nodoc:
3
+ module RequestHelper #:nodoc:
4
+ def request(uri, env = {})
5
+ @_webrat_session ||= Webrat::MerbAdapter.new
6
+ @_webrat_session.response = @_webrat_session.request(uri, env)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ require "action_controller"
2
+ require "action_controller/integration"
3
+
4
+ module ActionController #:nodoc:
5
+ IntegrationTest.class_eval do
6
+ include Webrat::Methods
7
+ include Webrat::Matchers
8
+
9
+ # The Rails version of within supports passing in a model and Webrat
10
+ # will apply a scope based on Rails' dom_id for that model.
11
+ #
12
+ # Example:
13
+ # within User.last do
14
+ # click_link "Delete"
15
+ # end
16
+ def within(selector_or_object, &block)
17
+ if selector_or_object.is_a?(String)
18
+ super
19
+ else
20
+ super('#' + RecordIdentifier.dom_id(selector_or_object), &block)
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ # Supports using the matchers in controller, helper, and view specs if you're
2
+ # using rspec-rails. Just add a require statement to spec/spec_helper.rb or env.rb:
3
+ #
4
+ # require 'webrat/integrations/rspec-rails'
5
+ #
6
+ require "nokogiri"
7
+ require "webrat/core/matchers"
8
+
9
+ Spec::Runner.configure do |config|
10
+ config.include(Webrat::Matchers, :type => [:controller, :helper, :view])
11
+ end
@@ -0,0 +1,11 @@
1
+ require "webrat/selenium"
2
+
3
+ if defined?(ActionController::IntegrationTest)
4
+ module ActionController #:nodoc:
5
+ IntegrationTest.class_eval do
6
+ include Webrat::Methods
7
+ include Webrat::Selenium::Methods
8
+ include Webrat::Selenium::Matchers
9
+ end
10
+ end
11
+ end
@@ -1,13 +1,2 @@
1
- # Supports using the matchers in controller, helper, and view specs if you're
2
- # using rspec-rails. Just add a require statement to spec/spec_helper.rb or env.rb:
3
- #
4
- # require 'webrat/rspec-rails'
5
- #
6
- require "webrat/core/matchers"
7
-
8
- Spec::Runner.configure do |config|
9
- # rspec should support :type => [:controller, :helper, :view] - but until it does ...
10
- config.include(Webrat::Matchers, :type => :controller)
11
- config.include(Webrat::Matchers, :type => :helper)
12
- config.include(Webrat::Matchers, :type => :view)
13
- end
1
+ warn("Requiring 'webrat/rspec-rails' is deprecated. Please require 'webrat/integrations/rspec-rails' instead")
2
+ require "webrat/integrations/rspec-rails"
@@ -1,5 +1,4 @@
1
1
  require "webrat"
2
- gem "selenium-client", ">=1.2.14"
3
2
  require "selenium/client"
4
3
  require "webrat/selenium/silence_stream"
5
4
  require "webrat/selenium/selenium_session"
@@ -69,13 +68,3 @@ module Webrat
69
68
  end
70
69
  end
71
70
  end
72
-
73
- if defined?(ActionController::IntegrationTest)
74
- module ActionController #:nodoc:
75
- IntegrationTest.class_eval do
76
- include Webrat::Methods
77
- include Webrat::Selenium::Methods
78
- include Webrat::Selenium::Matchers
79
- end
80
- end
81
- end
@@ -0,0 +1,40 @@
1
+ module Webrat
2
+ module Selenium
3
+
4
+ class ApplicationServerFactory
5
+
6
+ def self.app_server_instance
7
+ case Webrat.configuration.application_framework
8
+ when :sinatra
9
+ require "webrat/selenium/application_servers/sinatra"
10
+ return Webrat::Selenium::ApplicationServers::Sinatra.new
11
+ when :merb
12
+ require "webrat/selenium/application_servers/merb"
13
+ return Webrat::Selenium::ApplicationServers::Merb.new
14
+ when :rails
15
+ require "webrat/selenium/application_servers/rails"
16
+ return Webrat::Selenium::ApplicationServers::Rails.new
17
+ when :external
18
+ require "webrat/selenium/application_servers/external"
19
+ return Webrat::Selenium::ApplicationServers::External.new
20
+ else
21
+ raise WebratError.new(<<-STR)
22
+ Unknown Webrat application_framework: #{Webrat.configuration.application_framework.inspect}
23
+
24
+ Please ensure you have a Webrat configuration block that specifies an application_framework
25
+ in your test_helper.rb, spec_helper.rb, or env.rb (for Cucumber).
26
+
27
+ For example:
28
+
29
+ Webrat.configure do |config|
30
+ # ...
31
+ config.application_framework = :rails
32
+ end
33
+ STR
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ require "webrat/selenium/application_servers/base"
2
+ require "webrat/selenium/application_servers/sinatra"
3
+ require "webrat/selenium/application_servers/merb"
4
+ require "webrat/selenium/application_servers/rails"
5
+ require "webrat/selenium/application_servers/external"
@@ -0,0 +1,46 @@
1
+ require "webrat/selenium/silence_stream"
2
+
3
+ module Webrat
4
+ module Selenium
5
+ module ApplicationServers
6
+ class Base
7
+ include Webrat::Selenium::SilenceStream
8
+
9
+ def boot
10
+ start
11
+ wait
12
+ stop_at_exit
13
+ end
14
+
15
+ def stop_at_exit
16
+ at_exit do
17
+ stop
18
+ end
19
+ end
20
+
21
+ def wait
22
+ $stderr.print "==> Waiting for #{Webrat.configuration.application_framework} application server on port #{Webrat.configuration.application_port}... "
23
+ wait_for_socket
24
+ $stderr.print "Ready!\n"
25
+ end
26
+
27
+ def wait_for_socket
28
+ silence_stream(STDOUT) do
29
+ TCPSocket.wait_for_service_with_timeout \
30
+ :host => "0.0.0.0",
31
+ :port => Webrat.configuration.application_port.to_i,
32
+ :timeout => 30 # seconds
33
+ end
34
+ rescue SocketError
35
+ fail
36
+ end
37
+
38
+ def prepare_pid_file(file_path, pid_file_name)
39
+ FileUtils.mkdir_p File.expand_path(file_path)
40
+ File.expand_path("#{file_path}/#{pid_file_name}")
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end