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

#initializeFixture

:nodoc:



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

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

Class Method Details

.base_pathObject

:nodoc:



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

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

Instance Method Details

#fixture_exists?(fixture_name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#fixture_namesObject

:nodoc:



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

def fixture_names # :nodoc:
  @fixtures.keys
end

#get_fixture(fixture_file_key) ⇒ Object



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

def get_fixture(fixture_file_key)
  @fixtures[fixture_file_key]
end

#get_fixture_entity(fixture_file_key, entity_key) ⇒ Object

: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

#load_fixtures_from(dir) ⇒ Object

: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

#pluralized_fixture_exists?(singularized_fixture_name) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


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

#specific_fixture_entities(fixture_key, select_array) ⇒ Object



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