-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathspec_helper.rb
More file actions
127 lines (109 loc) · 3.97 KB
/
spec_helper.rb
File metadata and controls
127 lines (109 loc) · 3.97 KB
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
119
120
121
122
123
124
125
126
127
require 'rubygems'
require 'rack/test'
require 'rspec'
require 'rspec/its'
#require 'spec/autorun'
#require 'spec/interop/test'
require 'logger'
require 'ostruct'
require 'webmock/rspec'
require 'capybara'
require 'capybara/dsl'
require 'casserver/authenticators/base'
require 'casserver/core_ext.rb'
CASServer::Authenticators.autoload :LDAP, 'casserver/authenticators/ldap.rb'
CASServer::Authenticators.autoload :ActiveDirectoryLDAP, 'casserver/authenticators/active_directory_ldap.rb'
CASServer::Authenticators.autoload :SQL, 'casserver/authenticators/sql.rb'
CASServer::Authenticators.autoload :SQLEncrypted, 'lib/casserver/authenticators/sql_encrypted.rb'
CASServer::Authenticators.autoload :Google, 'casserver/authenticators/google.rb'
CASServer::Authenticators.autoload :ActiveResource, 'casserver/authenticators/active_resource.rb'
CASServer::Authenticators.autoload :Test, 'casserver/authenticators/test.rb'
# require builder because it doesn't pull in the version
# info automatically...
begin
require 'builder'
require 'builder/version'
rescue LoadError
puts "builder not found, testing ActiveRecord 2.3?"
end
if Dir.getwd =~ /\/spec$/
# Avoid potential weirdness by changing the working directory to the CASServer root
FileUtils.cd('..')
end
def silence_warnings
old_verbose, $VERBOSE = $VERBOSE, nil
yield
ensure
$VERBOSE = old_verbose
end
# Ugly monkeypatch to allow us to test for correct redirection to
# external services.
#
# This will likely break in the future when Capybara or RackTest are upgraded.
class Capybara::RackTest::Browser
def current_url
if @redirected_to_external_url
@redirected_to_external_url
else
request.url rescue ""
end
end
def follow_redirects!
if last_response.redirect? && last_response['Location'] =~ /^http[s]?:/
@redirected_to_external_url = last_response['Location']
else
5.times do
follow_redirect! if last_response.redirect?
end
raise Capybara::InfiniteRedirectError, "redirected more than 5 times, check for infinite redirects." if last_response.redirect?
end
end
end
# This called in specs' `before` block.
# Due to the way Sinatra applications are loaded,
# we're forced to delay loading of the server code
# until the start of each test so that certain
# configuraiton options can be changed (e.g. `uri_path`)
def load_server(config_file = 'default_config')
ENV['CONFIG_FILE'] = File.join(File.dirname(__FILE__),'config',"#{config_file}.yml")
silence_warnings do
load File.dirname(__FILE__) + '/../lib/casserver/server.rb'
end
# set test environment
CASServer::Server.set :environment, :test
CASServer::Server.set :run, false
CASServer::Server.set :raise_errors, true
CASServer::Server.set :logging, false
CASServer::Server.enable(:raise_errors)
CASServer::Server.disable(:show_exceptions)
#Capybara.current_driver = :selenium
Capybara.app = CASServer::Server
def app
CASServer::Server
end
end
# Deletes the sqlite3 database specified in the app's config
# and runs the db:migrate rake tasks to rebuild the database schema.
def reset_spec_database
raise "Cannot reset the spec database because config[:database][:database] is not defined." unless
CASServer::Server.config[:database] && CASServer::Server.config[:database][:database]
FileUtils.rm_f(CASServer::Server.config[:database][:database])
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.logger.level = Logger::ERROR
ActiveRecord::Migration.verbose = false
ActiveRecord::Migrator.migrate("db/migrate")
end
def get_ticket_for(service, username = 'spec_user', password = 'spec_password')
visit "/login?service=#{CGI.escape(service)}"
fill_in 'username', :with => username
fill_in 'password', :with => password
click_button 'login-submit'
page.current_url.match(/ticket=(.*)$/)[1]
end
def gem_available?(name)
if Gem::Specification.methods.include?(:find_all_by_name)
not Gem::Specification.find_all_by_name(name).empty?
else
Gem.available?(name)
end
end