Sha256: 0d03cef8fd5e7d9435b41443b07e621d0f61b8a92b802e4d8dccbbf47984399b

Contents?: true

Size: 644 Bytes

Versions: 4

Compression:

Stored size: 644 Bytes

Contents

require 'yaml'

class FixtureHelper
  FIXTURE_FILES = Dir[File.expand_path("#{Dir.pwd}/spec/fixtures/*.yml")]

  class << self
    def method_missing(sym, *args, &block)
      if fixture_exists? sym
        load_fixture(sym)
      else
        super(sym, args, block)
      end
    end

    def load_fixture name
      instance_variable_get("@#{name}") || instance_variable_set("@#{name}", YAML.load_file(FIXTURE_FILES[line_of_fixture(name)]))
    end

    def fixture_exists? name
      !line_of_fixture(name).nil?
    end

    def line_of_fixture name
      FIXTURE_FILES.map { |f| f.split('/').last }.index("#{name}.yml")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pair-0.0.4 spec/fixture_helper.rb
pair-0.0.3 spec/fixture_helper.rb
pair-0.0.2 spec/fixture_helper.rb
pair-0.0.1 spec/fixture_helper.rb