PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/unit/file_format/common_regular_expressions_spec.rb

https://github.com/andreazaupa/request-log-analyzer
Ruby | 80 lines | 62 code | 17 blank | 1 comment | 2 complexity | d4f52bf43318039649204cd93706bd2f MD5 | raw file
  1. # encoding: UTF-8
  2. require 'spec_helper'
  3. describe RequestLogAnalyzer::FileFormat::CommonRegularExpressions do
  4. include RequestLogAnalyzer::FileFormat::CommonRegularExpressions
  5. describe '.timestamp' do
  6. it "should parse timestamps with a given format" do
  7. anchored(timestamp('%Y-%m-%dT%H:%M:%S%z')).should =~ '2009-12-03T00:12:37+0100'
  8. anchored(timestamp('%Y-%m-%dT%H:%M:%S%z')).should_not =~ '2009-12-03 00:12:37+0100'
  9. anchored(timestamp('%Y-%m-%dT%H:%M:%S%z')).should_not =~ '2009-12-03T00:12:37'
  10. end
  11. end
  12. describe '.hostname' do
  13. it "should parse hostnames successfully" do
  14. anchored(hostname).should =~ 'railsdoctors.com'
  15. anchored(hostname).should =~ 'www.rails-doctors.com'
  16. anchored(hostname).should =~ 'hostname.co.uk'
  17. anchored(hostname).should =~ 'localhost'
  18. anchored(hostname).should_not =~ '192.168.0.1'
  19. anchored(hostname).should_not =~ '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
  20. anchored(hostname).should_not =~ 'railsdoctors.'
  21. end
  22. end
  23. describe '.ip_address' do
  24. it "should parse IPv4 addresses" do
  25. anchored(ip_address).should =~ '127.0.0.1'
  26. anchored(ip_address).should =~ '255.255.255.255'
  27. anchored(ip_address).should_not =~ '2552.2552.2552.2552'
  28. anchored(ip_address).should_not =~ '127001'
  29. anchored(ip_address).should_not =~ ''
  30. anchored(ip_address).should_not =~ '-'
  31. anchored(ip_address).should_not =~ 'sub-host.domain.tld'
  32. end
  33. it "should pase IPv6 addresses" do
  34. anchored(ip_address).should =~ '::1'
  35. anchored(ip_address).should =~ '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
  36. anchored(ip_address).should =~ '3ffe:1900:4545:3:200:f8ff:127.0.0.1'
  37. anchored(ip_address).should =~ '::3:200:f8ff:127.0.0.1'
  38. anchored(ip_address).should =~ '0:0:0:0:0:0:0:1'
  39. anchored(ip_address).should_not =~ 'qqqq:wwww:eeee:3q:200:wf8ff:fe21:67cf'
  40. anchored(ip_address).should_not =~ '3ffe44:1900f:454545:3:200:f8ff:ffff:5432'
  41. end
  42. it "should allow blank if true is given as parameter" do
  43. anchored(ip_address(true)).should =~ ''
  44. anchored(ip_address(true)).should_not =~ ' '
  45. end
  46. it "should allow a nil substitute if a string is given as parameter" do
  47. anchored(ip_address('-')).should =~ '-'
  48. anchored(ip_address('-')).should_not =~ ' -'
  49. anchored(ip_address('-')).should_not =~ '--'
  50. anchored(ip_address('-')).should_not =~ ''
  51. end
  52. end
  53. describe '.hostname_or_ip_address' do
  54. it "should parse either hostnames or ip addresses" do
  55. anchored(hostname_or_ip_address).should =~ 'railsdoctors.com'
  56. anchored(hostname_or_ip_address).should =~ 'hostname.co.uk'
  57. anchored(hostname_or_ip_address).should =~ 'localhost'
  58. anchored(hostname_or_ip_address).should =~ '192.168.0.1'
  59. anchored(hostname_or_ip_address).should =~ '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
  60. anchored(hostname_or_ip_address).should_not =~ 'railsdoctors.'
  61. end
  62. end
  63. end