Sha256: 7a25dd06252b7c7d68782eabca8991950dad8dbddeb4b4322ea919a3e575c283

Contents?: true

Size: 1.77 KB

Versions: 13

Compression:

Stored size: 1.77 KB

Contents

require 'find'
require 'erb'
require 'extensions/hash'
require 'taza/entity'

module Taza
  # The module that will mixin methods based on the fixture files in your 'spec/fixtures'
  # 
  # Example:
  #   describe "something" do
  #     it "should test something" do
  #       users(:jane_smith).first_name.should eql("jane")
  #     end
  #   end
  # 
  #  where there is a spec/fixtures/users.yml file containing a entry of:
  # jane_smith:
  #   first_name: jane
  #   last_name: smith
  class Fixture # :nodoc:

    def initialize # :nodoc:
      @fixtures = {}
    end

    def load_fixtures_from(dir) # :nodoc:
      Dir.glob(File.join(dir,'*.yml')) do |file|
        templatized_fixture=ERB.new(File.read(file))
        entitized_fixture = {}
        YAML.load(templatized_fixture.result()).each do |key, value|
          entitized_fixture[key] = value.convert_hash_keys_to_methods(self)
        end
        @fixtures[File.basename(file,'.yml').to_sym] = entitized_fixture
      end
    end
    
    def fixture_names # :nodoc:
      @fixtures.keys
    end

    def get_fixture(fixture_file_key)
      @fixtures[fixture_file_key]
    end  
    
    def get_fixture_entity(fixture_file_key,entity_key) # :nodoc:
      @fixtures[fixture_file_key][entity_key]
    end

    def pluralized_fixture_exists?(singularized_fixture_name) # :nodoc:
      fixture_exists?(singularized_fixture_name.pluralize.to_sym)
    end
    
    def specific_fixture_entities(fixture_key, select_array)
      cloned_fixture = @fixtures[fixture_key].clone
      cloned_fixture.delete_if {|key , value| !select_array.include?(key)}
    end

    def fixture_exists?(fixture_name)
      fixture_names.include?(fixture_name.to_sym)
    end

   def self.base_path # :nodoc:
     File.join('.','spec','fixtures','')
   end
  end
  
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
makevoid-taza-0.8.6 lib/taza/fixture.rb
scudco-taza-0.8.5 lib/taza/fixture.rb
scudco-taza-0.8.6 lib/taza/fixture.rb
scudco-taza-0.8.7 lib/taza/fixture.rb
taza-0.9.2.1 lib/taza/fixture.rb
taza-0.9.2.0 lib/taza/fixture.rb
taza-0.9.1.2 lib/taza/fixture.rb
taza-0.9.1.1 lib/taza/fixture.rb
taza-0.9.1 lib/taza/fixture.rb
taza-0.9.0 lib/taza/fixture.rb
taza-0.8.5 lib/taza/fixture.rb
taza-0.8.6 lib/taza/fixture.rb
taza-0.8.7 lib/taza/fixture.rb