Module: Frameworks::EnvHelper

Includes:
W3CValidators
Defined in:
lib/frameworks/cucumber.rb

Instance Method Summary collapse

Instance Method Details

#generate_base_urlsObject

Generate base urls to use in Cucumber step defs



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/frameworks/cucumber.rb', line 19

def generate_base_urls 
  environment = ENV['ENVIRONMENT'].downcase #be defensive
  set_scheme
  if(environment =='sandbox')
    @base_url = @sandbox + @bbc_domain 
    @static_base_url = @static_sandbox + @bbc_domain
  elsif (environment =='live' && ENV['WWW_LIVE']=='false')
    @base_url = @www_prefix.chop + @bbc_domain
    @static_base_url = @static_prefix.chop + @bbci_domain
    @open_base_url = @open_prefix.chop + @bbc_domain
  elsif (environment.split('.')[0].include? 'pal') #address specific box
    @base_url = "#{scheme}://#{ENV['ENVIRONMENT']}" 
  else
    @base_url = @www_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
  end
  proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] 
  @proxy_host = proxy.scan(/http:\/\/(.*):80/).to_s if proxy
end

#set_schemeObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/frameworks/cucumber.rb', line 61

def set_scheme  
  ENV['SCHEME']=='https' ? scheme = 'https' : scheme = 'http'
  @www_prefix = "#{scheme}://www."
  @static_prefix = "#{scheme}://static."
  @open_prefix = "#{scheme}://open."
  @bbc_domain = '.bbc.co.uk'
  @bbci_domain = '.bbci.co.uk'
  @sandbox = "#{scheme}://pal.sandbox.dev"
  @static_sandbox = "#{scheme}://static.sandbox.dev"
end

#validate_online(src) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/frameworks/cucumber.rb', line 41

def validate_online(src)

  @validator = MarkupValidator.new({:proxy_host => @proxy_host,:proxy_port => 80})

  @validator.set_doctype!(:xhtml)
  begin
    results = @validator.validate_text(src)
  rescue Net::HTTPFatalError => e
    puts "WARNING - OUTGOING NETWORK ERROR FROM FORGE TO W3C - Validation Not Performed"
  end

  if results.errors.length > 0
    results.errors.each do |err|
      puts err.to_s
    end
    raise "W3C Validation of " + current_url + " failed."
  end
end