Sha256: e4f80d05c91a75737af6f6728c824481da9ea4dcf056854d369356e05d9b7062

Contents?: true

Size: 1.32 KB

Versions: 15

Compression:

Stored size: 1.32 KB

Contents

require 'rspec'
require 'nokogiri'

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

RSpec.configure do |config|
  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

15 entries across 15 versions & 1 rubygems

Version Path
ncs_mdes-0.11.0 spec/spec_helper.rb
ncs_mdes-0.10.0 spec/spec_helper.rb
ncs_mdes-0.9.0 spec/spec_helper.rb
ncs_mdes-0.8.1 spec/spec_helper.rb
ncs_mdes-0.8.0 spec/spec_helper.rb
ncs_mdes-0.7.0 spec/spec_helper.rb
ncs_mdes-0.6.1 spec/spec_helper.rb
ncs_mdes-0.6.0 spec/spec_helper.rb
ncs_mdes-0.5.0 spec/spec_helper.rb
ncs_mdes-0.4.2 spec/spec_helper.rb
ncs_mdes-0.4.1 spec/spec_helper.rb
ncs_mdes-0.4.0 spec/spec_helper.rb
ncs_mdes-0.3.1 spec/spec_helper.rb
ncs_mdes-0.3.0 spec/spec_helper.rb
ncs_mdes-0.2.0 spec/spec_helper.rb