rspecs
This commit is contained in:
@@ -92,7 +92,13 @@ class Browser
|
|||||||
data = JSON.parse(File.read(config_file))
|
data = JSON.parse(File.read(config_file))
|
||||||
end
|
end
|
||||||
|
|
||||||
override_config(data)
|
OPTIONS.each do |option|
|
||||||
|
option_name = option.to_s
|
||||||
|
unless data[option_name].nil?
|
||||||
|
self.send(:"#{option_name}=", data[option_name])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# @param [ String ] url
|
# @param [ String ] url
|
||||||
|
|||||||
@@ -16,14 +16,13 @@ describe Browser do
|
|||||||
}
|
}
|
||||||
let(:options) { {} }
|
let(:options) { {} }
|
||||||
let(:instance_vars_to_check) {
|
let(:instance_vars_to_check) {
|
||||||
['user-agent', 'random-agent', 'proxy',
|
['proxy', 'max_threads', 'cache_ttl', 'request_timeout', 'connect_timeout']
|
||||||
'max_threads', 'cache_ttl', 'request_timeout', 'connect_timeout']
|
|
||||||
}
|
}
|
||||||
let(:json_config_without_proxy) { JSON.parse(File.read(CONFIG_FILE_WITHOUT_PROXY)) }
|
let(:json_config_without_proxy) { JSON.parse(File.read(CONFIG_FILE_WITHOUT_PROXY)) }
|
||||||
let(:json_config_with_proxy) { JSON.parse(File.read(CONFIG_FILE_WITH_PROXY)) }
|
let(:json_config_with_proxy) { JSON.parse(File.read(CONFIG_FILE_WITH_PROXY)) }
|
||||||
|
|
||||||
def check_instance_variables(browser, json_expected_vars)
|
def check_instance_variables(browser, json_expected_vars)
|
||||||
json_expected_vars['max_threads'] ||= 1 # max_thread can not be nil
|
json_expected_vars['max_threads'] ||= 20 # max_thread can not be nil
|
||||||
|
|
||||||
instance_vars_to_check.each do |variable_name|
|
instance_vars_to_check.each do |variable_name|
|
||||||
browser.send(:"#{variable_name}").should === json_expected_vars[variable_name]
|
browser.send(:"#{variable_name}").should === json_expected_vars[variable_name]
|
||||||
@@ -39,12 +38,6 @@ describe Browser do
|
|||||||
describe '::instance' do
|
describe '::instance' do
|
||||||
after { check_instance_variables(browser, @json_expected_vars) }
|
after { check_instance_variables(browser, @json_expected_vars) }
|
||||||
|
|
||||||
context "when default config_file = #{CONFIG_FILE_WITHOUT_PROXY}" do
|
|
||||||
it 'will check the instance vars' do
|
|
||||||
@json_expected_vars = json_config_without_proxy
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when :config_file = #{CONFIG_FILE_WITH_PROXY}" do
|
context "when :config_file = #{CONFIG_FILE_WITH_PROXY}" do
|
||||||
let(:options) { { config_file: CONFIG_FILE_WITH_PROXY } }
|
let(:options) { { config_file: CONFIG_FILE_WITH_PROXY } }
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ describe 'WebSite' do
|
|||||||
before :all do
|
before :all do
|
||||||
Browser::reset
|
Browser::reset
|
||||||
Browser.instance(
|
Browser.instance(
|
||||||
config_file: SPEC_FIXTURES_CONF_DIR + '/browser/browser.conf.json',
|
config_file: SPEC_FIXTURES_CONF_DIR + '/browser.conf.json',
|
||||||
cache_ttl: 0
|
cache_ttl: 0
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ describe WpTarget do
|
|||||||
let(:login_url) { wp_target.uri.merge('wp-login.php').to_s }
|
let(:login_url) { wp_target.uri.merge('wp-login.php').to_s }
|
||||||
let(:options) {
|
let(:options) {
|
||||||
{
|
{
|
||||||
config_file: SPEC_FIXTURES_CONF_DIR + '/browser/browser.conf.json',
|
config_file: SPEC_FIXTURES_CONF_DIR + '/browser.conf.json',
|
||||||
cache_ttl: 0,
|
cache_ttl: 0,
|
||||||
wp_content_dir: 'wp-content',
|
wp_content_dir: 'wp-content',
|
||||||
wp_plugins_dir: 'wp-content/plugins'
|
wp_plugins_dir: 'wp-content/plugins'
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
{
|
{
|
||||||
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0) Gecko/20100101 Firefox/9.0",
|
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0) Gecko/20100101 Firefox/9.0",
|
||||||
"user_agent_mode": "static",
|
"cache_ttl": 600,
|
||||||
"cache_ttl": 300,
|
|
||||||
"request_timeout": 2000,
|
"request_timeout": 2000,
|
||||||
"connect_timeout": 1000,
|
"connect_timeout": 1000,
|
||||||
"max_threads": 5
|
"max_threads": 20
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0) Gecko/20100101 Firefox/11.0",
|
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0) Gecko/20100101 Firefox/11.0",
|
||||||
"user_agent_mode": "static",
|
|
||||||
"proxy": "127.0.0.1:3038",
|
"proxy": "127.0.0.1:3038",
|
||||||
"cache_ttl": 300,
|
"cache_ttl": 300,
|
||||||
"request_timeout": 2000,
|
"request_timeout": 2000,
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0) Gecko/20100101 Firefox/11.0",
|
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0) Gecko/20100101 Firefox/11.0",
|
||||||
"user_agent_mode": "static",
|
|
||||||
"proxy": "127.0.0.1:3038",
|
"proxy": "127.0.0.1:3038",
|
||||||
"proxy_auth": "user:pass",
|
"proxy_auth": "user:pass",
|
||||||
"cache_ttl": 300,
|
"cache_ttl": 300,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ SPEC_FIXTURES_CONF_DIR = SPEC_FIXTURES_DIR + '/conf' # FIXME Remove it
|
|||||||
SPEC_FIXTURES_WP_VERSIONS_DIR = SPEC_FIXTURES_DIR + '/wp_versions'
|
SPEC_FIXTURES_WP_VERSIONS_DIR = SPEC_FIXTURES_DIR + '/wp_versions'
|
||||||
|
|
||||||
redefine_constant(:CACHE_DIR, SPEC_DIR + '/cache')
|
redefine_constant(:CACHE_DIR, SPEC_DIR + '/cache')
|
||||||
redefine_constant(:CONF_DIR, SPEC_FIXTURES_DIR + '/conf/browser') # FIXME Remove the /browser
|
redefine_constant(:CONF_DIR, SPEC_FIXTURES_DIR + '/conf')
|
||||||
|
|
||||||
MODELS_FIXTURES = SPEC_FIXTURES_DIR + '/common/models'
|
MODELS_FIXTURES = SPEC_FIXTURES_DIR + '/common/models'
|
||||||
COLLECTIONS_FIXTURES = SPEC_FIXTURES_DIR + '/common/collections'
|
COLLECTIONS_FIXTURES = SPEC_FIXTURES_DIR + '/common/collections'
|
||||||
|
|||||||
Reference in New Issue
Block a user