Sha256: ad823a3c07049253048546bef5235a75a2c0dd6f733edd89b89ce309ec3a1876

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

require 'rspec'
require 'nokogiri'

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'ncs_navigator/mdes'

module NcsNavigator::Mdes::Spec; end

require 'differences_matchers'

RSpec.configure do |config|
  config.include(NcsNavigator::Mdes::Spec::Matchers)

  def logger
    @logger ||= NcsNavigator::Mdes::Spec::AccumulatingLogger.new
  end

  ##
  # Returns a parsed XML element whose root ancestor is an appropriate
  # schema root.
  #
  # @param [String] xml_fragment
  def schema_element(xml_fragment)
        Nokogiri::XML(<<-XSD).root.elements.first
<xs:schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ncs="http://www.nationalchildrensstudy.gov" xmlns:ncsdoc="http://www.nationalchildrensstudy.gov/doc" xmlns:xlink="http://www.w3.org/TR/WD-xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.nationalchildrensstudy.gov" elementFormDefault="unqualified" attributeFormDefault="unqualified">
  #{xml_fragment}
</xs:schema>
XSD
  end
end

module NcsNavigator::Mdes
  module Spec
    ##
    # A logger that holds on to everything that is logged for later examination.
    class AccumulatingLogger
      def messages
        @messages ||= {}
      end

      def [](name)
        messages[name] ||= []
      end

      def method_missing(name, *args)
        self[name] << (args.size == 1 ? args.first : args)
        true # what Logger does
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ncs_mdes-0.13.0 spec/spec_helper.rb
ncs_mdes-0.12.0 spec/spec_helper.rb