Class: Taza::Fixture

Inherits:
Object show all
Defined in:
lib/taza/fixture.rb

Overview

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 Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Fixture) initialize

:nodoc:



22
23
24
# File 'lib/taza/fixture.rb', line 22

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

Class Method Details

+ (Object) base_path

:nodoc:



62
63
64
# File 'lib/taza/fixture.rb', line 62

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

Instance Method Details

- (Boolean) fixture_exists?(fixture_name)



58
59
60
# File 'lib/taza/fixture.rb', line 58

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

- (Object) fixture_names

:nodoc:



37
38
39
# File 'lib/taza/fixture.rb', line 37

def fixture_names # :nodoc:
  @fixtures.keys
end

- (Object) get_fixture(fixture_file_key)



41
42
43
# File 'lib/taza/fixture.rb', line 41

def get_fixture(fixture_file_key)
  @fixtures[fixture_file_key]
end

- (Object) get_fixture_entity(fixture_file_key, entity_key)

:nodoc:



45
46
47
# File 'lib/taza/fixture.rb', line 45

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

- (Object) load_fixtures_from(dir)

:nodoc:



26
27
28
29
30
31
32
33
34
35
# File 'lib/taza/fixture.rb', line 26

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

- (Boolean) pluralized_fixture_exists?(singularized_fixture_name)

:nodoc:



49
50
51
# File 'lib/taza/fixture.rb', line 49

def pluralized_fixture_exists?(singularized_fixture_name) # :nodoc:
  fixture_exists?(singularized_fixture_name.pluralize.to_sym)
end

- (Object) specific_fixture_entities(fixture_key, select_array)



53
54
55
56
# File 'lib/taza/fixture.rb', line 53

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