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
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 |
# File 'lib/frameworks/cucumber.rb', line 20 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.co.uk" @m_base_url = @mdot_prefix + "sandbox.dev.bbc.co.uk" 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.co.uk" @m_base_url = @mdot_prefix + "sandbox.bbc.co.uk" 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
132 133 134 135 136 137 |
# File 'lib/frameworks/cucumber.rb', line 132 def new_mechanize(http_proxy=nil) require 'mechanize' agent = Mechanize.new setup_mechanize(agent, http_proxy) agent end |
#prepare_host ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/frameworks/cucumber.rb', line 95 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 = '.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
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/frameworks/cucumber.rb', line 114 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? #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
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/frameworks/cucumber.rb', line 70 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 of " + current_url + " failed." end rescue Net::HTTPFatalError => e puts "WARNING - OUTGOING NETWORK ERROR FROM FORGE TO W3C - Validation Not Performed" end end |