proxy_tester 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. data/.gitignore +22 -0
  2. data/.rdebugrc +7 -0
  3. data/.rspec +3 -0
  4. data/.simplecov +8 -0
  5. data/Gemfile +37 -0
  6. data/Gemfile.lock +199 -0
  7. data/LICENSE.txt +22 -0
  8. data/Procfile +1 -0
  9. data/README.md +582 -0
  10. data/Rakefile +64 -0
  11. data/bin/proxy_tester +11 -0
  12. data/db/migrate/20140314_create_environment.rb +8 -0
  13. data/files/config.yaml +1 -0
  14. data/files/example-config.erb +12 -0
  15. data/files/example-spec_helper.rb.erb +23 -0
  16. data/files/example-test_case.rb.erb +27 -0
  17. data/files/example-test_cases-gemfile.rb.erb +9 -0
  18. data/files/example-user_file.erb +4 -0
  19. data/lib/proxy_tester/actions/add_examples_to_test_cases_directory.rb +125 -0
  20. data/lib/proxy_tester/actions/clone_repository.rb +39 -0
  21. data/lib/proxy_tester/actions/create_directory.rb +33 -0
  22. data/lib/proxy_tester/actions/create_file.rb +55 -0
  23. data/lib/proxy_tester/actions/create_output.rb +36 -0
  24. data/lib/proxy_tester/actions/handle_error.rb +37 -0
  25. data/lib/proxy_tester/actions/initialize_application.rb +70 -0
  26. data/lib/proxy_tester/actions/show_config.rb +10 -0
  27. data/lib/proxy_tester/capybara_proxy.rb +54 -0
  28. data/lib/proxy_tester/capybara_proxy_pac.rb +62 -0
  29. data/lib/proxy_tester/cli/main.rb +59 -0
  30. data/lib/proxy_tester/config.rb +100 -0
  31. data/lib/proxy_tester/data.rb +23 -0
  32. data/lib/proxy_tester/database_session.rb +15 -0
  33. data/lib/proxy_tester/environment.rb +21 -0
  34. data/lib/proxy_tester/erb_generator.rb +34 -0
  35. data/lib/proxy_tester/error_handler.rb +107 -0
  36. data/lib/proxy_tester/error_messages.rb +82 -0
  37. data/lib/proxy_tester/exceptions.rb +53 -0
  38. data/lib/proxy_tester/git_file.rb +31 -0
  39. data/lib/proxy_tester/git_null_file.rb +32 -0
  40. data/lib/proxy_tester/git_repository.rb +120 -0
  41. data/lib/proxy_tester/handle_error.rb +37 -0
  42. data/lib/proxy_tester/locales/en-rails.yml +205 -0
  43. data/lib/proxy_tester/locales/en.yml +42 -0
  44. data/lib/proxy_tester/main.rb +46 -0
  45. data/lib/proxy_tester/models/user.rb +17 -0
  46. data/lib/proxy_tester/pac_result.rb +50 -0
  47. data/lib/proxy_tester/rspec/helper.rb +211 -0
  48. data/lib/proxy_tester/rspec_runner.rb +43 -0
  49. data/lib/proxy_tester/template_file.rb +19 -0
  50. data/lib/proxy_tester/template_repository.rb +22 -0
  51. data/lib/proxy_tester/ui_logger.rb +30 -0
  52. data/lib/proxy_tester/user_database.rb +24 -0
  53. data/lib/proxy_tester/version.rb +3 -0
  54. data/lib/proxy_tester.rb +54 -0
  55. data/proxy_tester.gemspec +34 -0
  56. data/script/acceptance_test +4 -0
  57. data/script/bootstrap +56 -0
  58. data/script/ci +3 -0
  59. data/script/console +14 -0
  60. data/script/release +3 -0
  61. data/script/test_web +22 -0
  62. data/script/unit_test +3 -0
  63. data/spec/actions/add_examples_to_test_cases_directory_spec.rb +52 -0
  64. data/spec/actions/clone_repository_spec.rb +83 -0
  65. data/spec/actions/create_directory_spec.rb +59 -0
  66. data/spec/actions/create_file_spec.rb +139 -0
  67. data/spec/actions/create_output_spec.rb +46 -0
  68. data/spec/actions/handle_error_spec.rb +74 -0
  69. data/spec/actions/initialize_application_spec.rb +40 -0
  70. data/spec/actions/show_config_spec.rb +22 -0
  71. data/spec/capybara_proxy_pac_spec.rb +42 -0
  72. data/spec/capybara_proxy_spec.rb +76 -0
  73. data/spec/config_spec.rb +86 -0
  74. data/spec/data_spec.rb +34 -0
  75. data/spec/environment_spec.rb +25 -0
  76. data/spec/erb_generator_spec.rb +31 -0
  77. data/spec/examples/proxy.pac +7 -0
  78. data/spec/factories.rb +8 -0
  79. data/spec/features/check_ssl_sites_spec.rb +8 -0
  80. data/spec/git_file_spec.rb +46 -0
  81. data/spec/git_repository_spec.rb +111 -0
  82. data/spec/main_spec.rb +25 -0
  83. data/spec/pac_result_spec.rb +20 -0
  84. data/spec/proxy_tester_spec_helper_spec.rb +137 -0
  85. data/spec/rspec_runner_spec.rb +29 -0
  86. data/spec/spec_helper.rb +15 -0
  87. data/spec/support/capybara.rb +11 -0
  88. data/spec/support/database_cleaner.rb +14 -0
  89. data/spec/support/debugging.rb +3 -0
  90. data/spec/support/environment.rb +33 -0
  91. data/spec/support/example.rb +16 -0
  92. data/spec/support/factory_girl.rb +15 -0
  93. data/spec/support/filesystem.rb +19 -0
  94. data/spec/support/helper_features.rb +31 -0
  95. data/spec/support/matcher.rb +17 -0
  96. data/spec/support/reporting.rb +1 -0
  97. data/spec/support/rspec.rb +5 -0
  98. data/spec/support/string.rb +2 -0
  99. data/spec/template_file_spec.rb +25 -0
  100. data/spec/template_repository_spec.rb +44 -0
  101. data/spec/user_database_spec.rb +63 -0
  102. data/spec/user_spec.rb +62 -0
  103. metadata +398 -0
@@ -0,0 +1,205 @@
1
+ en:
2
+ date:
3
+ abbr_day_names:
4
+ - Sun
5
+ - Mon
6
+ - Tue
7
+ - Wed
8
+ - Thu
9
+ - Fri
10
+ - Sat
11
+ abbr_month_names:
12
+ -
13
+ - Jan
14
+ - Feb
15
+ - Mar
16
+ - Apr
17
+ - May
18
+ - Jun
19
+ - Jul
20
+ - Aug
21
+ - Sep
22
+ - Oct
23
+ - Nov
24
+ - Dec
25
+ day_names:
26
+ - Sunday
27
+ - Monday
28
+ - Tuesday
29
+ - Wednesday
30
+ - Thursday
31
+ - Friday
32
+ - Saturday
33
+ formats:
34
+ default: ! '%d-%m-%Y'
35
+ long: ! '%d %B, %Y'
36
+ short: ! '%d %b'
37
+ month_names:
38
+ -
39
+ - January
40
+ - February
41
+ - March
42
+ - April
43
+ - May
44
+ - June
45
+ - July
46
+ - August
47
+ - September
48
+ - October
49
+ - November
50
+ - December
51
+ order:
52
+ - :day
53
+ - :month
54
+ - :year
55
+ datetime:
56
+ distance_in_words:
57
+ about_x_hours:
58
+ one: about 1 hour
59
+ other: about %{count} hours
60
+ about_x_months:
61
+ one: about 1 month
62
+ other: about %{count} months
63
+ about_x_years:
64
+ one: about 1 year
65
+ other: about %{count} years
66
+ almost_x_years:
67
+ one: almost 1 year
68
+ other: almost %{count} years
69
+ half_a_minute: half a minute
70
+ less_than_x_minutes:
71
+ one: less than a minute
72
+ other: less than %{count} minutes
73
+ less_than_x_seconds:
74
+ one: less than 1 second
75
+ other: less than %{count} seconds
76
+ over_x_years:
77
+ one: over 1 year
78
+ other: over %{count} years
79
+ x_days:
80
+ one: 1 day
81
+ other: ! '%{count} days'
82
+ x_minutes:
83
+ one: 1 minute
84
+ other: ! '%{count} minutes'
85
+ x_months:
86
+ one: 1 month
87
+ other: ! '%{count} months'
88
+ x_seconds:
89
+ one: 1 second
90
+ other: ! '%{count} seconds'
91
+ prompts:
92
+ day: Day
93
+ hour: Hour
94
+ minute: Minute
95
+ month: Month
96
+ second: Seconds
97
+ year: Year
98
+ errors: &errors
99
+ format: ! '%{attribute} %{message}'
100
+ messages:
101
+ accepted: must be accepted
102
+ blank: can't be blank
103
+ confirmation: doesn't match confirmation
104
+ empty: can't be empty
105
+ equal_to: must be equal to %{count}
106
+ even: must be even
107
+ exclusion: is reserved
108
+ greater_than: must be greater than %{count}
109
+ greater_than_or_equal_to: must be greater than or equal to %{count}
110
+ inclusion: is not included in the list
111
+ invalid: is invalid
112
+ less_than: must be less than %{count}
113
+ less_than_or_equal_to: must be less than or equal to %{count}
114
+ not_a_number: is not a number
115
+ not_an_integer: must be an integer
116
+ odd: must be odd
117
+ record_invalid: ! 'Validation failed: %{errors}'
118
+ taken: has already been taken
119
+ too_long:
120
+ one: is too long (maximum is 1 character)
121
+ other: is too long (maximum is %{count} characters)
122
+ too_short:
123
+ one: is too short (minimum is 1 character)
124
+ other: is too short (minimum is %{count} characters)
125
+ wrong_length:
126
+ one: is the wrong length (should be 1 character)
127
+ other: is the wrong length (should be %{count} characters)
128
+ template:
129
+ body: ! 'There were problems with the following fields:'
130
+ header:
131
+ one: 1 error prohibited this %{model} from being saved
132
+ other: ! '%{count} errors prohibited this %{model} from being saved'
133
+ helpers:
134
+ select:
135
+ prompt: Please select
136
+ submit:
137
+ create: Create %{model}
138
+ submit: Save %{model}
139
+ update: Update %{model}
140
+ number:
141
+ currency:
142
+ format:
143
+ delimiter: ! ','
144
+ format: ! '%u%n'
145
+ precision: 2
146
+ separator: .
147
+ significant: false
148
+ strip_insignificant_zeros: false
149
+ unit: £
150
+ format:
151
+ delimiter: ! ','
152
+ precision: 3
153
+ separator: .
154
+ significant: false
155
+ strip_insignificant_zeros: false
156
+ human:
157
+ decimal_units:
158
+ format: ! '%n %u'
159
+ units:
160
+ billion: Billion
161
+ million: Million
162
+ quadrillion: Quadrillion
163
+ thousand: Thousand
164
+ trillion: Trillion
165
+ unit: ''
166
+ format:
167
+ delimiter: ''
168
+ precision: 3
169
+ significant: true
170
+ strip_insignificant_zeros: true
171
+ storage_units:
172
+ format: ! '%n %u'
173
+ units:
174
+ byte:
175
+ one: Byte
176
+ other: Bytes
177
+ gb: GB
178
+ kb: KB
179
+ mb: MB
180
+ tb: TB
181
+ percentage:
182
+ format:
183
+ delimiter: ''
184
+ precision:
185
+ format:
186
+ delimiter: ''
187
+ support:
188
+ array:
189
+ last_word_connector: ! ', and '
190
+ two_words_connector: ! ' and '
191
+ words_connector: ! ', '
192
+ time:
193
+ am: am
194
+ formats:
195
+ default: ! '%a, %d %b %Y %H:%M:%S %z'
196
+ long: ! '%d %B, %Y %H:%M'
197
+ short: ! '%d %b %H:%M'
198
+ pm: pm
199
+ # remove these aliases after 'activemodel' and 'activerecord' namespaces are removed from Rails repository
200
+ activemodel:
201
+ errors:
202
+ <<: *errors
203
+ activerecord:
204
+ errors:
205
+ <<: *errors
@@ -0,0 +1,42 @@
1
+ ---
2
+ en:
3
+ errors:
4
+ default:
5
+ summary: Unexpected Error...
6
+ details: Sorry, but I cannot fullfill your request. An unexpected error occured. Please ask your administrator for support.
7
+ internal_error:
8
+ summary: Internal error...
9
+ details: 'Sorry, but I cannot fullfill your request. An internal error occured: "%{message}". Please notify the author of the software about the problem.'
10
+ user_error:
11
+ summary: User Error...
12
+ details: Sorry, but I cannot fullfill your request. An error occured. There should be a better error message displayed here. Please notify the author of the software about the problem.
13
+ unreadable_config_file:
14
+ summary: Unreadable config file...
15
+ details: 'Sorry, but I cannot fullfill your request. The config file "%{file}" given could not be read: "%{message}".'
16
+ invalid_proxy_user:
17
+ summary: Invalid proxy user...
18
+ details: 'Sorry, but you told me to use the user "#{user}" in your specs which does not exist in the user database. Please fix that and run the specs again.'
19
+ invalid_user_record:
20
+ summary: Invalid user record...
21
+ details: 'Sorry, but you told me to create a user resource from an invalid user record: "#{message}". Please fix that and run the specs again.'
22
+ unreadable_user_file:
23
+ summary: User file not found...
24
+ details: 'Sorry, but I cannot fullfill your request. I cannot find the user file "%{file}". Please fix that and run the specs again.'
25
+ request_timeout:
26
+ summary: Request timed out...
27
+ details: 'Sorry, but an error happend. A request timeout. Maybe the proxy or the web server is not reachable.'
28
+ invalid_synatx:
29
+ summary: Invalid syntax...
30
+ details: 'Sorry, but an error happend. The syntax used by you is invalid: %{message}.'
31
+ not_found_pac_file:
32
+ summary: Pac file not found...
33
+ details: 'Sorry, but I cannot fullfill your request. The pac file "%{file}" cannot be found.'
34
+ invalid_pac_result:
35
+ summary: Invalid result from pac file...
36
+ details: 'Sorry, but I cannot fullfill your request. The result "%{result}" of proxy.pac "%{file}" is invalid. Please fix the proxy.pac and try again.'
37
+ invalid_proxy_type:
38
+ summary: Invalid proxy type...
39
+ details: 'Sorry, but I cannot fullfill your request. You provided an invalid proxy type "%{type}". Allowed values are ":none", ":http" or ":socks5".'
40
+ views:
41
+ application:
42
+ title: Proxy Tester
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ module ProxyTester;
3
+ @environment = ProxyTester::Environment.new
4
+ @config = ProxyTester::Config.new
5
+ @ui_logger = ProxyTester::UiLogger.new
6
+ @session = ProxyTester::DatabaseSession.new
7
+
8
+ class << self
9
+ attr_accessor :session, :environment, :config, :ui_logger
10
+
11
+ def root_path
12
+ ::File.expand_path('../../..', __FILE__)
13
+ end
14
+
15
+ def enable_debug_mode
16
+ ProxyTester.ui_logger.info "Activating debug mode."
17
+
18
+ require 'pry'
19
+ require 'debugger'
20
+ rescue LoadError
21
+ ProxyTester.ui_logger.error "You tried to enable debug-mode, but either 'pry'- or 'debugger'-gem are not installed. Please fix that before using the debug-switch again."
22
+ end
23
+
24
+ def configure_i18n
25
+ I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
26
+ I18n.load_path = Dir[::File.join(ProxyTester.root_path, 'lib', 'proxy_tester', 'locales', '*.yml')]
27
+ I18n.backend.load_translations
28
+ I18n.enforce_available_locales = true
29
+ end
30
+
31
+ def load_user_database
32
+ User.load_from(UserDatabase.new)
33
+ end
34
+
35
+ def clear_environment
36
+ %w{
37
+ http_proxy
38
+ https_proxy
39
+ HTTP_PROXY
40
+ HTTPS_PROXY
41
+ }.each { |var| ENV.delete(var) }
42
+ end
43
+ end
44
+ end
45
+
46
+ ProxyTester.configure_i18n
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ module ProxyTester
3
+ class User < ActiveRecord::Base
4
+ #crypt_keeper :password, :encryptor => :aes, :key => ProxyTester.environment.password, salt: 'salt'
5
+
6
+ validates :name, presence: true
7
+ validates :password, presence: true
8
+
9
+ def self.load_from(source)
10
+ source.create_users(self)
11
+ end
12
+
13
+ def to_string
14
+ sprintf '%s:%s', name, password
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+ module ProxyTester
3
+ class PacResult
4
+
5
+ attr_reader :proxy, :proxy_port, :request_type
6
+
7
+ def initialize(verbatim_content = nil)
8
+
9
+ if verbatim_content.blank?
10
+ parsed_content = {}
11
+ else
12
+ parsed_content = parse(verbatim_content) || {}
13
+ end
14
+
15
+ @proxy = parsed_content[:proxy]
16
+ @proxy_port = parsed_content[:proxy_port]
17
+ @request_type = parsed_content[:request_type]
18
+ end
19
+
20
+ private
21
+
22
+ def parse(string)
23
+ regex.match(string)
24
+ end
25
+
26
+ def regex
27
+ %r{
28
+ \A
29
+ "?
30
+ (?<request_type>
31
+ [A-Z]+
32
+ )
33
+ (?:
34
+ \s+
35
+ (?<proxy>
36
+ [0-9]{1,3}(:?\.[0-9]{1,3}){3} ||
37
+ [[:alnum:]]+(?:\.[[:alnum:]]+)*\.?
38
+ )
39
+ (?:
40
+ :
41
+ (?<proxy_port>[0-9]+)
42
+ )?
43
+ )?
44
+ ;?
45
+ "?
46
+ \Z
47
+ }x
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,211 @@
1
+ # encoding: utf-8
2
+ module ProxyTester
3
+ module SpecHelper
4
+ module Capybara
5
+ include ::Capybara::DSL
6
+
7
+ @__runtime = Time.now.strftime('%Y-%m-%d_%H:%M:%S')
8
+
9
+ class << self
10
+ def runtime
11
+ @__runtime
12
+ end
13
+ end
14
+
15
+ def proxy
16
+ @__proxy
17
+ end
18
+
19
+ def proxy_pac
20
+ @__proxy_pac
21
+ end
22
+
23
+ def keep_report_directories
24
+ @__keep_report_directories ||= 5
25
+ end
26
+
27
+ def cleanup_reports
28
+ old_report_directories.each { |d| FileUtils.rm_rf d }
29
+ end
30
+
31
+ def take_screenshot
32
+ page.save_screenshot(screenshot_path, full: true)
33
+
34
+ screenshot_path
35
+ end
36
+
37
+ def view_screenshot
38
+ show_image(take_screenshot)
39
+ end
40
+ alias_method :show_screenshot, :view_screenshot
41
+
42
+ def use_user_agent(agent)
43
+ page.driver.headers = { "User-Agent" => agent }
44
+ end
45
+
46
+ def visit(url)
47
+ @__proxy ||= ProxyTester::CapybaraProxy.new
48
+ @__proxy_pac ||= ProxyTester::CapybaraProxyPac.new
49
+
50
+ proxy_pac.url = url
51
+
52
+ if !proxy_pac.blank? and !proxy_pac.direct?
53
+ proxy.host = proxy_pac.host
54
+ proxy.port = proxy_pac.port
55
+ end
56
+
57
+ register_driver proxy
58
+ use_driver proxy
59
+ use_user_agent 'Mozilla/5.0 (X11; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0'
60
+
61
+ begin
62
+ super(url)
63
+ rescue ::Capybara::Poltergeist::TimeoutError
64
+ raise ProxyTester::Exceptions::FetchUrlTimeout
65
+ end
66
+
67
+ end
68
+
69
+ def use_user(name)
70
+ @__proxy ||= ProxyTester::CapybaraProxy.new
71
+ proxy.user = ProxyTester::User.find_by!(name: name)
72
+
73
+ rescue ActiveRecord::RecordNotFound
74
+ ProxyTester.ui_logger.fatal "User \"#{name}\" could not be found. Please make use he's in the user database. Exiting."
75
+ raise ProxyTester::Exceptions::ProxyUserInvalid, user: name
76
+ end
77
+
78
+ def use_client_ip(ip)
79
+ @__proxy_pac ||= ProxyTester::CapybaraProxyPac.new
80
+
81
+ proxy_pac.client_ip = ip
82
+ end
83
+
84
+ def use_time(time)
85
+ @__proxy_pac ||= ProxyTester::CapybaraProxyPac.new
86
+
87
+ proxy_pac.time = time
88
+ end
89
+
90
+ def use_proxy(*args)
91
+ @__proxy ||= ProxyTester::CapybaraProxy.new
92
+ @__proxy_pac ||= ProxyTester::CapybaraProxyPac.new
93
+
94
+ if args.first.kind_of? Symbol
95
+ case args.first
96
+ when :host
97
+ proxy.host, proxy.port = args.second.split(/:/)
98
+ when :pac
99
+ proxy_pac.pac_file = args.second
100
+ else
101
+ fail ProxyTester::Exceptions::SyntaxInvalid, message: "Unknown symbol: #{args.first}"
102
+ end
103
+ else
104
+ proxy.host, proxy.port = args.first.split(/:/)
105
+ end
106
+
107
+ proxy.type = args.last[:type] if args.last.kind_of? Hash
108
+ end
109
+
110
+ def use_timeout(threshold, &block)
111
+ old_timeout = ::Capybara.default_wait_time
112
+ ::Capybara.default_wait_time = threshold
113
+
114
+ block.call
115
+ ensure
116
+ ::Capybara.default_wait_time = old_timeout
117
+ end
118
+
119
+ private
120
+
121
+ def use_driver(proxy)
122
+ ::Capybara.current_driver = proxy.to_sym
123
+ end
124
+
125
+ def register_driver(local_proxy)
126
+ if local_proxy.blank?
127
+ options = {
128
+ js_errors: false,
129
+ phantomjs_logger: $stderr,
130
+ }
131
+ else
132
+ options = {
133
+ phantomjs_options: local_proxy.as_phantomjs_arguments,
134
+ js_errors: false,
135
+ phantomjs_logger: $stderr,
136
+ }
137
+ end
138
+
139
+ ProxyTester.ui_logger.debug('options: ' + options.to_s)
140
+
141
+ ::Capybara.register_driver local_proxy.to_sym do |app|
142
+ ::Capybara::Poltergeist::Driver.new(app, options)
143
+ end
144
+
145
+ ::Capybara.run_server = false
146
+ end
147
+
148
+ def screenshot_directory
149
+ if @__screenshot_dir.blank?
150
+ @__screenshot_dir = File.join(ProxyTester.config.reports_directory, ProxyTester::SpecHelper::Capybara.runtime)
151
+ FileUtils.mkdir_p @__screenshot_dir
152
+ end
153
+
154
+ @__screenshot_dir
155
+ end
156
+
157
+ def screenshot_path
158
+ return @__screenshot_path if @__screenshot_path
159
+
160
+ @__screenshot_path = File.join(screenshot_directory, "#{example.full_description.parameterize}.png")
161
+ end
162
+
163
+ def old_report_directories
164
+ Dir.glob(File.join(ProxyTester.config.reports_directory, '*')).keep_if { |d| FileTest.directory? d }.sort.reverse.drop(keep_report_directories)
165
+ end
166
+
167
+ def operating_system
168
+ case RUBY_PLATFORM.downcase
169
+ when /win32/
170
+ :win32
171
+ when /linux/
172
+ :linux
173
+ when /darwin/
174
+ :darwin
175
+ else
176
+ :unknown
177
+ end
178
+ end
179
+
180
+ def show_image(image)
181
+ viewer = case operating_system
182
+ when :linux
183
+ 'xdg-open'
184
+ when :win32
185
+ 'start'
186
+ when :darwin
187
+ 'open'
188
+ else
189
+ 'xdg-open'
190
+ end
191
+
192
+ system("#{viewer} #{image.shellescape}")
193
+ end
194
+
195
+ end
196
+ end
197
+ end
198
+
199
+ RSpec.configure do |c|
200
+ c.include ProxyTester::SpecHelper::Capybara
201
+
202
+ c.before :each do
203
+ @__proxy = ProxyTester::CapybaraProxy.new
204
+ end
205
+
206
+ c.before :all do
207
+ cleanup_reports
208
+ end
209
+ end
210
+
211
+ Capybara.default_driver = :poltergeist
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ require 'rspec'
3
+
4
+ module ProxyTester
5
+ class RspecRunner
6
+ private
7
+
8
+ attr_reader :test_cases_directory
9
+
10
+ public
11
+
12
+ def initialize(options = {})
13
+ @test_cases_directory = options.fetch(:test_cases_directory, ProxyTester.config.test_cases_directory)
14
+ end
15
+
16
+ def run(tags)
17
+ ProxyTester.load_user_database
18
+ ProxyTester.clear_environment
19
+
20
+ RSpec.configure do |c|
21
+ c.color = true
22
+ c.add_formatter 'Fuubar'
23
+ c.filter_run_including to_filter(tags) unless tags.blank?
24
+ end
25
+
26
+ $LOAD_PATH << test_cases_directory
27
+ RSpec::Core::Runner.run(spec_files)
28
+ end
29
+
30
+ private
31
+
32
+ def to_filter(a)
33
+ Hash[*a.collect { |e| e.to_sym }.zip([true] * a.size).flatten]
34
+ end
35
+
36
+ def spec_files
37
+ files = ::Dir.glob(::File.join(test_cases_directory, '**', '*_spec.rb'))
38
+ ProxyTester.ui_logger.warn "No spec files found at \"#{test_cases_directory}\"." if files.blank?
39
+
40
+ files
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ module ProxyTester
3
+ class TemplateFile
4
+
5
+ attr_reader :path
6
+
7
+ def initialize(path)
8
+ @path = ::File.expand_path(path)
9
+ end
10
+
11
+ def name
12
+ ::File.basename(path, '.*').to_sym
13
+ end
14
+
15
+ def read
16
+ ::File.read(path)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ module ProxyTester
3
+ class TemplateRepository
4
+ private
5
+
6
+ attr_reader :root_directory, :creator
7
+
8
+ public
9
+
10
+ def initialize(root_directory = ::File.expand_path('../../../files', __FILE__), creator = TemplateFile)
11
+ @root_directory = ::File.expand_path(root_directory)
12
+ @creator = creator
13
+ end
14
+
15
+ def find(name)
16
+ path = ::File.join(root_directory, "#{name.to_s}.erb")
17
+ fail Exceptions::ErbTemplateIsUnknown, "Template \"#{name}\" could not be found!" unless ::File.exist? path
18
+
19
+ creator.new(path)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ module ProxyTester
2
+ class UiLogger
3
+ def initialize
4
+ @logger = ::Logger.new($stderr)
5
+ end
6
+
7
+ def level=(l)
8
+ @logger.level = case l.to_s.to_sym
9
+ when :unknown
10
+ ::Logger::UNKNOWN
11
+ when :fatal
12
+ ::Logger::FATAL
13
+ when :error
14
+ ::Logger::ERROR
15
+ when :warn
16
+ ::Logger::WARN
17
+ when :info
18
+ ::Logger::INFO
19
+ when :debug
20
+ ::Logger::DEBUG
21
+ else
22
+ ::Logger::ERROR
23
+ end
24
+ end
25
+
26
+ def method_missing(method, *args, &block)
27
+ @logger.public_send method, *args
28
+ end
29
+ end
30
+ end