Using a lib in YAML fixtures

I’m using the runt library [1] to do some temporal expression
matching. I want to keep the expression in a binary field in my db.
I figured that then in order to do the fixtures, I’d need to do some
erb in the yaml file. So I came up with this:

onetime:
id: 1
name: One Time
description: This event occurs only one time.
timex: <%= REYear.new(7) & REMonth.new(24) & REDay.new(3, 0, 17, 0) %>

If I try to load in the fixture, I get the following error:

  1. Error:
    test_create(EventTest):
    Fixture::FormatError: a YAML error occured parsing
    /Users/pergesu/work/mesafire/config/…/test/fixtures/events.yml.
    Please note that YAML must be consistently indented using spaces. Tabs
    are not allowed. Please have a look at YAML Ain't Markup Language
    The exact error was:
    NameError: uninitialized constant REYear
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/fixtures.rb:300:in
    read_fixture_files' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/fixtures.rb:275:in initialize’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/fixtures.rb:247:in
    new' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/fixtures.rb:247:in create_fixtures’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/fixtures.rb:246:in
    map' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/fixtures.rb:246:in create_fixtures’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/fixtures.rb:244:in
    silence' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/fixtures.rb:244:in create_fixtures’
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/fixtures.rb:540:in
    load_fixtures' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/fixtures.rb:487:in setup’

I’ve put require ‘runt’ in environtment.rb, the unit test file, and
even in my yaml file doing <% require ‘runt’ %>. Not really sure how
I’m supposed to access this lib from the yaml file. I’d really
appreciate any input.

Thanks,
Pat

[1] http://runt.rubyforge.org/

Turns out I need to be looking much simpler. I just did
./script/console and typed require ‘runt’ and it came back false.
I’ve installed the runt gem, so this should work. Anyone else using
runt for anything? I wonder why it won’t load the lib for me.

On Mon, 2005-12-12 at 07:18 -0700, Pat M. wrote:

Turns out I need to be looking much simpler. I just did
./script/console and typed require ‘runt’ and it came back false.
I’ve installed the runt gem, so this should work. Anyone else using
runt for anything? I wonder why it won’t load the lib for me.

require can do one of three things:

If the specified module is not loaded, it loads it and returns true.
If the specified module is already loaded, it returns false.
If the specified module is not found, it raises a MissingSourceFile
error.

So the fact that it’s returning false from script/console means that
it’s being loaded as part of the env setup.

As to why it’s not usable in your fixture, I don’t rightly know.

  • Jamie