class RSpecFileFixtures::Fixture

Provides access to the contents and location of a file fixture.

Public Class Methods

new(raw_path) click to toggle source
# File lib/rspec_file_fixtures/fixture.rb, line 6
def initialize(raw_path)
  @raw_path = raw_path
end

Public Instance Methods

json(symbolize_names_shorthand = true, symbolize_names: true) click to toggle source

rubocop:disable Style/OptionalBooleanParameter

# File lib/rspec_file_fixtures/fixture.rb, line 26
def json(symbolize_names_shorthand = true, symbolize_names: true)
  JSON.parse(read, symbolize_names: symbolize_names & symbolize_names_shorthand)
end
path() click to toggle source
# File lib/rspec_file_fixtures/fixture.rb, line 19
def path
  pathname.realpath.to_s
rescue Errno::ENOENT
  pathname.expand_path.to_s
end
read() click to toggle source
# File lib/rspec_file_fixtures/fixture.rb, line 10
def read
  pathname.read
end
xml() click to toggle source
# File lib/rspec_file_fixtures/fixture.rb, line 14
def xml
  require 'nokogiri'
  Nokogiri::XML.parse(read)
end
yaml(symbolize_names_shorthand = true, symbolize_names: true) click to toggle source
# File lib/rspec_file_fixtures/fixture.rb, line 30
def yaml(symbolize_names_shorthand = true, symbolize_names: true)
  YAML.safe_load(read, symbolize_names: symbolize_names & symbolize_names_shorthand)
end
Also aliased as: yml
yml(symbolize_names_shorthand = true, symbolize_names: true)

rubocop:enable Style/OptionalBooleanParameter

Alias for: yaml

Private Instance Methods

base_path() click to toggle source
# File lib/rspec_file_fixtures/fixture.rb, line 43
def base_path
  Pathname.new(File.join('spec', 'fixtures'))
end
pathname() click to toggle source
# File lib/rspec_file_fixtures/fixture.rb, line 39
def pathname
  @pathname ||= base_path.join(@raw_path)
end