Forum: Ruby on Rails Using a lib in YAML fixtures

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2005-12-12 15:05
(Received via mailing list)
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 http://www.yaml.org/faq.html
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/
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2005-12-12 15:20
(Received via mailing list)
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.
Eb234d1ee9f1dcd334657d7c5c1b1c4d?d=identicon&s=25 Jamie Macey (jamie)
on 2005-12-12 20:25
(Received via mailing list)
On Mon, 2005-12-12 at 07:18 -0700, Pat Maddox 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
This topic is locked and can not be replied to.