Class: Taza::Fixture
- Inherits:
-
Object
- Object
- Taza::Fixture
- 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
-
.base_path ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #fixture_exists?(fixture_name) ⇒ Boolean
-
#fixture_names ⇒ Object
:nodoc:.
- #get_fixture(fixture_file_key) ⇒ Object
-
#get_fixture_entity(fixture_file_key, entity_key) ⇒ Object
:nodoc:.
-
#initialize ⇒ Fixture
constructor
:nodoc:.
-
#load_fixtures_from(dir) ⇒ Object
:nodoc:.
-
#pluralized_fixture_exists?(singularized_fixture_name) ⇒ Boolean
:nodoc:.
- #specific_fixture_entities(fixture_key, select_array) ⇒ Object
Constructor Details
#initialize ⇒ Fixture
:nodoc:
21 22 23 |
# File 'lib/taza/fixture.rb', line 21 def initialize # :nodoc: @fixtures = {} end |
Class Method Details
.base_path ⇒ Object
:nodoc:
61 62 63 |
# File 'lib/taza/fixture.rb', line 61 def self.base_path # :nodoc: File.join('.','spec','fixtures','') end |
Instance Method Details
#fixture_exists?(fixture_name) ⇒ Boolean
57 58 59 |
# File 'lib/taza/fixture.rb', line 57 def fixture_exists?(fixture_name) fixture_names.include?(fixture_name.to_sym) end |
#fixture_names ⇒ Object
:nodoc:
36 37 38 |
# File 'lib/taza/fixture.rb', line 36 def fixture_names # :nodoc: @fixtures.keys end |
#get_fixture(fixture_file_key) ⇒ Object
40 41 42 |
# File 'lib/taza/fixture.rb', line 40 def get_fixture(fixture_file_key) @fixtures[fixture_file_key] end |
#get_fixture_entity(fixture_file_key, entity_key) ⇒ Object
:nodoc:
44 45 46 |
# File 'lib/taza/fixture.rb', line 44 def get_fixture_entity(fixture_file_key,entity_key) # :nodoc: @fixtures[fixture_file_key][entity_key] end |
#load_fixtures_from(dir) ⇒ Object
:nodoc:
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/taza/fixture.rb', line 25 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] = Taza::Entity.new(value, self) end @fixtures[File.basename(file,'.yml').to_sym] = entitized_fixture end end |
#pluralized_fixture_exists?(singularized_fixture_name) ⇒ Boolean
:nodoc:
48 49 50 |
# File 'lib/taza/fixture.rb', line 48 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
52 53 54 55 |
# File 'lib/taza/fixture.rb', line 52 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 |