class Object

Public Instance Methods

_config() click to toggle source
# File lib/rspec-dns/have_dns.rb, line 109
def _config
  @config ||= if File.exists?(_config_file)
    require 'yaml'
    _symbolize_keys(YAML::load(ERB.new(File.read(_config_file) ).result))
  else
    nil
  end
end
_config_file() click to toggle source
# File lib/rspec-dns/have_dns.rb, line 118
def _config_file
  File.join('config', 'dns.yml')
end
_options() click to toggle source
# File lib/rspec-dns/have_dns.rb, line 137
def _options
  @_options ||= {}
end
_pretty_print_options() click to toggle source
# File lib/rspec-dns/have_dns.rb, line 176
def _pretty_print_options
  "\n  (#{_options.sort.map { |k, v| "#{k}:#{v.inspect}" }.join(', ')})\n"
end
_pretty_print_records() click to toggle source
# File lib/rspec-dns/have_dns.rb, line 180
def _pretty_print_records
  "\n" + @records.map { |r| r.to_s }.join("\n")
end
_records() click to toggle source
# File lib/rspec-dns/have_dns.rb, line 141
def _records
  @_name ||= if (IPAddr.new(@dns) rescue nil) # Check if IPAddr(v4,v6)
               IPAddr.new(@dns).reverse
             else
               @dns
             end

  if @zone_file
    @_records = Dnsruby::Message.new
    rrs = Dnsruby::ZoneReader.new(@zone_origin).process_file(@zone_file)
    rrs.each { |rr| @_records.add_answer(rr) if @_name == rr.name.to_s  }
  end

  @_records ||= begin
    config = _config || {}
    # Backwards compatible config option for rspec-dnsruby
    query_timeout = config[:timeouts] || RSpec.configuration.rspec_dns_connection_timeout
    Timeout::timeout(query_timeout + 0.2) do
      resolver =  Dnsruby::Resolver.new(config)
      resolver.query_timeout = query_timeout
      resolver.do_caching = false
      resolver.query(@_name, _options[:type] || Dnsruby::Types.ANY)
    end
  rescue Exception => e
    if Dnsruby::NXDomain === e
      @exceptions << "Have not received any records"
    elsif Dnsruby::Refused === e && @refuse_request
      @refuse_request_received = true
    else
      @exceptions << e.message
    end
    Dnsruby::Message.new
  end
end
_symbolize_keys(hash) click to toggle source
# File lib/rspec-dns/have_dns.rb, line 122
def _symbolize_keys(hash)
  hash.inject({}){|result, (key, value)|
    new_key = case key
              when String then key.to_sym
              else key
              end
    new_value = case value
                when Hash then _symbolize_keys(value)
                else value
                end
    result[new_key] = new_value
    result
  }
end
description() click to toggle source
# File lib/rspec-dns/have_dns.rb, line 71
def description
  "have the correct dns entries with #{_options}"
end
method_missing(m, *args, &block) click to toggle source
Calls superclass method
# File lib/rspec-dns/have_dns.rb, line 100
def method_missing(m, *args, &block)
  if m.to_s =~ /(and\_with|and|with)?\_(.*)$/
    _options[$2.to_sym] = args.first
    self
  else
    super
  end
end