Sha256: 0c502e9cd969d3f76ae7eb9bd7905e4bfe77361da42cc05dd39f5974998547de

Contents?: true

Size: 783 Bytes

Versions: 2

Compression:

Stored size: 783 Bytes

Contents

# frozen_string_literal: true

module RSpec
  module FileFixtures
    # Provides access to the contents and location of a file fixture.
    class Fixture
      def initialize(raw_path)
        @raw_path = raw_path
      end

      def read
        pathname.read
      end

      def yaml
        YAML.safe_load(read, symbolize_names: true)
      end

      alias yml yaml

      def xml
        require 'nokogiri'
        Nokogiri::XML.parse(read)
      end

      def path
        pathname.realpath.to_s
      end

      def json
        JSON.parse(read, symbolize_names: true)
      end

      private

      def pathname
        @pathname ||= base_path.join(@raw_path)
      end

      def base_path
        Pathname.new(File.join('spec', 'fixtures'))
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-file_fixtures-0.1.1 lib/rspec/file_fixtures/fixture.rb
rspec-file_fixtures-0.1.0 lib/rspec/file_fixtures/fixture.rb