Sha256: 0358b5c97b81955411578029d931488ea61dc05224b1de378828b2789bb24f32

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'
require 'helpers/data'

require 'data_paths/finders'

describe DataPaths::Finders do
  subject do
    Class.new {
      include DataPaths
      include DataPaths::Finders
    }.new
  end

  it "should find a file" do
    subject.find_data_file('one.txt').should == File.join(Helpers::DATA_DIRS[0],'one.txt')
  end

  it "should find a directory" do
    subject.find_data_dir('dir').should == File.join(Helpers::DATA_DIRS[0],'dir')
  end

  it "should find all matching files" do
    subject.all_data_files('dir/two.txt').should == [
      File.join(Helpers::DATA_DIRS[0],'dir','two.txt'),
      File.join(Helpers::DATA_DIRS[1],'dir','two.txt')
    ]
  end

  it "should find all matching directories" do
    subject.all_data_dirs('dir').should == [
      File.join(Helpers::DATA_DIRS[0],'dir'),
      File.join(Helpers::DATA_DIRS[1],'dir')
    ]
  end

  it "should find all paths matching a pattern" do
    subject.glob_data_paths('*/*.txt').should == [
      File.join(Helpers::DATA_DIRS[0],'dir','two.txt'),
      File.join(Helpers::DATA_DIRS[1],'dir','two.txt')
    ]
  end

  it "should load the first found YAML file" do
    data = subject.load_yaml_file('data.yml')

    data.should == {'one' => 1}
  end

  it "should load all matching YAML files" do
    data = subject.load_yaml_files('data.yml')

    data.should == [{'one' => 1}, {'two' => 2}]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
data_paths-0.3.1 spec/finders_spec.rb
data_paths-0.3.0 spec/finders_spec.rb