-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathapplication.rb
53 lines (47 loc) · 1.36 KB
/
application.rb
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
require 'uri'
#
# Returns the full application URL given a path relative to the application's base URL
#
def applicationURL(relativePath)
return URI.join(Capybara.app_host, relativePath).to_s
end
#
# Returns the default application user id
#
def applicationUserID()
return ENV["APPLICATION_USERID"]
end
#
# Returns the default application password
#
def applicationPassword()
return ENV["APPLICATION_PASSWORD"]
end
#
# Retries a method while catching errors.
#
# Example: retryMethod( method( :yourFunction ), 1, 5 )
#
# Calls yourFunction(). If it encounters an error it
# will wait 5 seconds and retry once.
#
def retryMethod(function, retries, delay, *args)
for i in (1..retries)
begin
# Make an attempt at the method call, catching errors.
function.call(*args)
return # Success.
rescue RSpec::Expectations::ExpectationNotMetError => e
printf("retryMethod: %s\n" % [e.message])
printf("** Sleeping %d seconds before retrying.\n" % [delay])
#printf("page source:\n%s\n" % page.html) if page
sleep delay
rescue StandardError => e
printf("retryMethod: %s\n" % [e.message])
printf("** Sleeping %d seconds before retrying.\n" % [delay])
sleep delay
end
end
# Allow this to throw an error.
function.call(*args)
end