Class: Taza::Fixture
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:
22 23 24 |
# File 'lib/taza/fixture.rb', line 22 def initialize # :nodoc: @fixtures = {} end |
Class Method Details
.base_path ⇒ Object
: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
58 59 60 |
# File 'lib/taza/fixture.rb', line 58 def fixture_exists?(fixture_name) fixture_names.include?(fixture_name.to_sym) end |
#fixture_names ⇒ Object
: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:
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 |