Module: Frameworks::EnvHelper
- Includes:
- W3CValidators
- Defined in:
- lib/frameworks/cucumber.rb
Instance Method Summary collapse
-
#generate_base_urls ⇒ Object
Generate base urls to use in Cucumber step defs.
- #new_mechanize(http_proxy = nil) ⇒ Object
- #prepare_host ⇒ Object
- #setup_mechanize(agent, http_proxy = nil) ⇒ Object
- #validate_online(src, validator_args = nil) ⇒ Object
Instance Method Details
#generate_base_urls ⇒ Object
Generate base urls to use in Cucumber step defs
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 |
# File 'lib/frameworks/cucumber.rb', line 8 def generate_base_urls environment = ENV['ENVIRONMENT'].downcase #be defensive prepare_host if(environment =='sandbox') @base_url = @sandbox + @bbc_domain @pal_base_url = @sandbox + @bbc_domain @ssl_base_url = @sslsandbox + @bbc_domain @static_base_url = @static_sandbox + @bbc_domain @mobile_base_url = @mobiledot_prefix + "sandbox.dev" + @bbc_domain @m_base_url = @mdot_prefix + "sandbox.dev" + @bbc_domain elsif(environment =='sandbox6') @base_url = @sandbox6 + @bbc_domain @pal_base_url = @sandbox6 + @bbc_domain @ssl_base_url = @sslsandbox6 + @bbc_domain @static_base_url = @static_sandbox6 + @bbc_domain @mobile_base_url = @mobiledot_prefix + "sandbox" + @bbc_domain @m_base_url = @mdot_prefix + "sandbox" + @bbc_domain elsif (environment =='live' && ENV['WWW_LIVE']=='false') @base_url = @www_prefix.chop + @bbc_domain @pal_base_url = @pal_prefix + environment + @bbc_domain @ssl_base_url = @ssl_prefix.chop + @bbc_domain @static_base_url = @static_prefix.chop + @bbci_domain @open_base_url = @open_prefix.chop + @bbc_domain @mobile_base_url = @mobiledot_prefix.chop + @bbc_domain @m_base_url = @mdot_prefix.chop + @bbc_domain else @base_url = @www_prefix + environment + @bbc_domain @pal_base_url = @pal_prefix + environment + @bbc_domain @ssl_base_url = @ssl_prefix + environment + @bbc_domain @static_base_url = @static_prefix + environment + @bbci_domain @static_base_url = @static_prefix.chop + @bbci_domain if environment == 'live' @open_base_url = @open_prefix + environment + @bbc_domain @mobile_base_url = @mobiledot_prefix + environment + @bbc_domain @m_base_url = @mdot_prefix + environment + @bbc_domain end proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] proxy_parts = proxy.scan(/(?:http:\/\/)?([^\:]+)(?::(\d+))?/) if proxy && !proxy.empty? if proxy_parts && !proxy_parts.empty? @proxy_host = proxy_parts[0][0] if proxy_parts[0][1] @proxy_port = proxy_parts[0][1] else @proxy_port = "80" end end end |
#new_mechanize(http_proxy = nil) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/frameworks/cucumber.rb', line 131 def new_mechanize(http_proxy=nil) require 'mechanize' agent = Mechanize.new setup_mechanize(agent, http_proxy) agent end |
#prepare_host ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/frameworks/cucumber.rb', line 83 def prepare_host ENV['SCHEME']=='https' ? scheme = 'https' : scheme = 'http' @www_prefix = "#{scheme}://www." @pal_prefix = "#{scheme}://pal." @ssl_prefix = "https://ssl." @static_prefix = "#{scheme}://static." @open_prefix = "#{scheme}://open." @bbc_domain = '.' + (ENV['FW_BBC_DOMAIN'] || 'bbc.co.uk') @bbci_domain = '.bbci.co.uk' @sandbox = "#{scheme}://pal.sandbox.dev" @sandbox6 = "#{scheme}://sandbox" @mobiledot_prefix = "#{scheme}://mobile." @mdot_prefix = "#{scheme}://m." @sslsandbox = "https://ssl.sandbox.dev" @sslsandbox6 = "https://ssl.sandbox" @static_sandbox = "#{scheme}://static.sandbox.dev" @static_sandbox6 = "#{scheme}://static.sandbox" end |
#setup_mechanize(agent, http_proxy = nil) ⇒ Object
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 128 129 |
# File 'lib/frameworks/cucumber.rb', line 102 def setup_mechanize(agent, http_proxy=nil) http_proxy = http_proxy || ENV['HTTP_PROXY'] || ENV['http_proxy'] if ENV['FW_CERT_LOCATION'] agent.cert, agent.key = ENV['FW_CERT_LOCATION'], ENV['FW_CERT_LOCATION'] end agent.ca_file = ENV['CA_CERT_LOCATION'] if ENV['CA_CERT_LOCATION'] agent.set_proxy(http_proxy.scan(/http:\/\/(.*):80/)[0][0].to_s,80) if http_proxy && !http_proxy.empty? # The above proxy setting ignores any no_proxy variable setting: # added the following to circumvent this if(http_proxy) no_proxy = ENV['NO_PROXY'] || ENV['no_proxy'] if(no_proxy) # The no_proxy query string argument must not contain spaces no_proxy_qs = no_proxy.gsub(/[, ]+/,',') agent.agent.http.proxy = URI(http_proxy + '?no_proxy=' + no_proxy_qs) end end #This is necessary because Mech2 does not ship with root certs like Mech1 did and boxes may not have the OpenSSL set installed agent.verify_mode = OpenSSL::SSL::VERIFY_NONE # This prevents Mechanize from raising a Mechanize::ResponseCodeError # when the HTTP Response Code is 404 or 503. This lets capybara continue the journey. agent.agent.allowed_error_codes = ['404', '503'] end |
#validate_online(src, validator_args = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/frameworks/cucumber.rb', line 58 def validate_online(src, validator_args = nil) args = {:proxy_host => @proxy_host,:proxy_port => @proxy_port} if(validator_args != nil) args = args.merge(validator_args) end @validator = MarkupValidator.new(args) @validator.set_doctype!(:xhtml) begin results = @validator.validate_text(src) if results.errors.length > 0 results.errors.each do |err| puts err.to_s end raise "W3C Validation failed." end rescue SystemCallError => e puts "System error whilst performing request to W3C: #{e}" end end |