Sha256: 8f222ce17d7e980ff1b420a2aae02e2e59dbba4eec88606a60edbc5219d2c743

Contents?: true

Size: 899 Bytes

Versions: 32

Compression:

Stored size: 899 Bytes

Contents

class Fixture

  TYPES = { :gzip => "gz", :response => "xml", :wsdl => "xml" }

  class << self

    def [](type, fixture)
      fixtures(type)[fixture] ||= read_file type, fixture
    end

    def response_hash(fixture)
      @response_hash ||= {}
      @response_hash[fixture] ||= nori.parse(response(fixture))[:envelope][:body]
    end

    TYPES.each do |type, ext|
      define_method(type) { |fixture| self[type, fixture] }
    end

  private

    def nori
      Nori.new(:strip_namespaces => true, :convert_tags_to => lambda { |tag| tag.snakecase.to_sym })
    end

    def fixtures(type)
      @fixtures ||= {}
      @fixtures[type] ||= {}
    end

    def read_file(type, fixture)
      path = File.expand_path "../../fixtures/#{type}/#{fixture}.#{TYPES[type]}", __FILE__
      raise ArgumentError, "Unable to load: #{path}" unless File.exist? path

      File.read path
    end

  end
end

Version data entries

32 entries across 32 versions & 4 rubygems

Version Path
savon-2.12.1 spec/support/fixture.rb
savon-2.12.0 spec/support/fixture.rb
savon-2.11.2 spec/support/fixture.rb
savon-SU-2.11.1b spec/support/fixture.rb
savon-SU-2.11.1 spec/support/fixture.rb
savon-2.11.1 spec/support/fixture.rb
savon-2.11.0 spec/support/fixture.rb
savon-2.10.1 spec/support/fixture.rb
savon-2.10.0 spec/support/fixture.rb
savon-2.9.0 spec/support/fixture.rb
savon-2.8.1 spec/support/fixture.rb
savon-2.8.0 spec/support/fixture.rb
savon-2.7.2 spec/support/fixture.rb
savon-2.7.1 spec/support/fixture.rb
savon-2.7.0 spec/support/fixture.rb
savon-2.6.0 spec/support/fixture.rb
savon-2.5.1 spec/support/fixture.rb
savon-2.5.0 spec/support/fixture.rb
savon_with_adapter-2.4.1 spec/support/fixture.rb
savon-2.4.0 spec/support/fixture.rb