Sha256: 645d9b484aef9e4e4c0ffe266ddc145dbc5069e9c7fac0952e80a74124a04495

Contents?: true

Size: 911 Bytes

Versions: 7

Compression:

Stored size: 911 Bytes

Contents

module Savon
  module Spec

    # = Savon::Spec::Fixture
    #
    # Loads SOAP response fixtures.
    class Fixture
      class << self

        def path
          @path ||= Rails.root.join("spec", "fixtures").to_s if defined? Rails
          
          raise ArgumentError, "Savon::Spec::Fixture.path needs to be specified" unless @path
          @path
        end

        attr_writer :path

        def load(*args)
          file = args.map { |arg| arg.to_s.snakecase }.join("/")
          fixtures[file] ||= load_file file
        end

        alias [] load

      private

        def fixtures
          @fixtures ||= {}
        end

        def load_file(file)
          full_path = File.expand_path File.join(path, "#{file}.xml")
          raise ArgumentError, "Unable to load: #{full_path}" unless File.exist? full_path
          
          File.read full_path
        end

      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
savon_spec-0.1.6 lib/savon/spec/fixture.rb
savon_spec-0.1.5 lib/savon/spec/fixture.rb
savon_spec-0.1.4 lib/savon/spec/fixture.rb
savon_spec-0.1.3 lib/savon/spec/fixture.rb
savon_spec-0.1.2 lib/savon/spec/fixture.rb
savon_spec-0.1.1 lib/savon/spec/fixture.rb
savon_spec-0.1.0 lib/savon/spec/fixture.rb