Unable to load file in testing

Hello champs,

I am in testing phase of an application. I have created a simple test
case to add a holiday object like this:-

def test_should_not_add_holiday_without_name
holiday = Holiday.new
assert !holiday.save, “Holiday not saved without name”
end

In model, i have given validation as validates_presence_of :name.

So i think this is fine upto here but when i run this test case, in
test.log file i seen like:- “Unable to load holiday, underlying cause no
such file to load – holiday”

Why i comes like this as i am already having holiday’s yml and holidays
table in test database as well… ?

Also how to tackle with plural names in testing… I mean suppose i have
one more table leaves and while i’ll test it, it will come something
like this:- “Unable to load leafe, underlying cause no such file to load
– leafe”

For this i know that set_fixture_class is to be declared at
test_helper.rb… and i have defined as well… But not working…

Snatching my head on it …
Thanks in advance…

Anyone listening me …

Also how to tackle with plural names in testing… I mean suppose i have
one more table leaves and while i’ll test it, it will come something
like this:- “Unable to load leafe, underlying cause no such file to load
– leafe”

For this i know that set_fixture_class is to be declared at
test_helper.rb… and i have defined as well… But not working…

Snatching my head on it …
Thanks in advance…

On 19 February 2010 12:30, Hemant B. [email protected] wrote:

In model, i have given validation as validates_presence_of :name.

So i think this is fine upto here but when i run this test case, in
test.log file i seen like:- “Unable to load holiday, underlying cause no
such file to load – holiday”

Googling the error message suggests that this means that it cannot
find the fixtures file. How have you specified the fixtures in the
_test.rb file and what is the name of the holidays fixture file?

Colin

Colin L. wrote:

Googling the error message suggests that this means that it cannot
find the fixtures file. How have you specified the fixtures in the
_test.rb file and what is the name of the holidays fixture file?

Thanks for a reply colin.
In test_helper.rb file only i have specified the fixtures as fixtures
:all and the name of the holidays fixtures file is holidays.yml

On 19 February 2010 16:03, Hemant B. [email protected] wrote:

Colin L. wrote:

Googling the error message suggests that this means that it cannot
find the fixtures file. How have you specified the fixtures in the
_test.rb file and what is the name of the holidays fixture file?

Thanks for a reply colin.
In test_helper.rb file only i have specified the fixtures as fixtures
:all and the name of the holidays fixtures file is holidays.yml

That should be ok then, you said something about using
set_fixture_class, what have you specified, where, and why?
What is the name of the test class?

Colin

That should be ok then, you said something about using
set_fixture_class, what have you specified, where, and why?
What is the name of the test class?

Colin

No colin … That is not ok… thats why i put my question here… Even i
am thinking that i am doing all right… But still … I have entered
set_fixture_class in test_helper only… becauce upto my knowledge we
have to explicitly specify the name of fixture classes in test helper…
so i have specified it as:-
set_fixture_class => Holidays

On 19 February 2010 19:56, Hemant B. [email protected] wrote:

so i have specified it as:-
set_fixture_class => Holidays

I know it is not ok, that is why I said it should be ok and went on
to ask further questions. If you have model class Holiday then
normally it will expect the fixtures to be in holidays.yml and there
is no need for set_fixture_class. Remove that and see what happens.

Colin

On 20 February 2010 10:15, Hemant B. [email protected] wrote:

Ohhh … Sorry for my words …

Earlier, i was not there in test helper… So removing them is also
causing the same problem…

Very strange.

In that case can you post:

  1. The start of the file containing class Holiday, (down to first
    method) and tell me what is the filename with full path.
  2. test_helper.rb
  3. The start of file containing the test, and tell me what is the
    filename with full path
  4. The start of fixture file for holiday, and what is the filename
    with full path with full path.

Colin

Ohhh … Sorry for my words …

Earlier, i was not there in test helper… So removing them is also
causing the same problem…

I know it is not ok, that is why I said it should be ok and went on
to ask further questions. If you have model class Holiday then
normally it will expect the fixtures to be in holidays.yml and there
is no need for set_fixture_class. Remove that and see what happens.

Colin

Well colin … i am posting here the details you want

  1. The start of the file containing class Holiday, (down to first
    method) and tell me what is the filename with full path.

class Holidays < ActiveRecord::Base
validation on holiday_name
validation on holiday_date
end
Location:- app/models/holidays.rb

  1. test_helper.rb
    ENV[“RAILS_ENV”] = “test”
    require File.expand_path(File.dirname(FILE) +
    “/…/config/environment”)
    require ‘test_help’

class ActiveSupport::TestCase

Transactional fixtures accelerate your tests by wrapping each test

method

in a transaction that’s rolled back on completion. This ensures

that the

test database remains unchanged so your fixtures don’t have to be

reloaded

between every test method. Fewer database queries means faster

tests.

Read Mike C.'s excellent walkthrough at

http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting

Every Active Record database supports transactions except MyISAM

tables

in MySQL. Turn off transactional fixtures in this case; however, if

you

don’t care one way or the other, switching from MyISAM to InnoDB

tables

is recommended.

The only drawback to using transactional fixtures is when you

actually

need to test transactions. Since your test is bracketed by a

transaction,

any transactions started in your code will be automatically rolled

back.
self.use_transactional_fixtures = false

Instantiated fixtures are slow, but give you @david where otherwise

you

would need people(:david). If you don’t want to migrate your

existing

test cases which use the @david style and don’t mind the speed hit

(each

instantiated fixtures translates to a database query per test

method),

then set this back to true.

self.use_instantiated_fixtures = false

Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in

alphabetical order.

Setting fixtures classes here with
set_fixture_class :holdiays => ‘Holidays’

Note: You’ll currently still have to declare fixtures explicitly in

integration tests

– they do not yet inherit this setting

fixtures :all

Add more helper methods to be used by all tests here…

end

  1. The start of file containing the test, and tell me what is the
    filename with full path

require File.dirname(FILE) + ‘/…/test_helper’

class HolidaysTest < ActiveSupport::TestCase
test_methods_for_testing
end

Location:- test/unit/holidays_test.rb

  1. The start of fixture file for holiday, and what is the filename
    with full path with full path.

holidays.yml


holidays_0005:
name: “ABC”
created_at:
updated_at:
id: “5”
holiday_date: “2010-03-16”

Location:- test/fixtures/holidays.yml

Colin

On 20 February 2010 11:19, Colin L. [email protected] wrote:

Location:- app/models/holidays.rb

in a transaction that’s rolled back on completion. This ensures

tables

any transactions started in your code will be automatically rolled

method),

then set this back to true.

self.use_instantiated_fixtures = false

Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in

alphabetical order.

Setting fixtures classes here with

Also the line above does not seem to start with #

Colin

You said you had taken this out. Try it without. Apart from anything
else you have spelled it wrong. But I don’t think you want it anyway.

Already tried it without, i written it to give you a brief of it where i
am setting fixture class… Yes i spelled wrong here… it is
set_fixture_class :holidays => ‘Holidays’ only …

If you still get an error post it in full please.

What else you want …

Colin

On 20 February 2010 11:06, Hemant B. [email protected] wrote:

that the

in MySQL. Turn off transactional fixtures in this case; however, if

back.

then set this back to true.

self.use_instantiated_fixtures = false

Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in

alphabetical order.

Setting fixtures classes here with
set_fixture_class :holdiays => ‘Holidays’

You said you had taken this out. Try it without. Apart from anything
else you have spelled it wrong. But I don’t think you want it anyway.

If you still get an error post it in full please.

Colin

On 20 February 2010 11:25, Hemant B. [email protected] wrote:

What else you want …

As I said above, post the error after checking that there is no
set_fixture_class anywhere.

Colin

On 20 February 2010 11:06, Hemant B. [email protected] wrote:

Well colin … i am posting here the details you want

  1. The start of the file containing class Holiday, (down to first
    method) and tell me what is the filename with full path.

class Holidays < ActiveRecord::Base
validation on holiday_name
validation on holiday_date
end
Location:- app/models/holidays.rb

That should be class Holiday (not Holidays) and it should be in
holiday.rb not holidays.rb
Change these (make sure you do not leave the old rb files or any
backup files in the models folder).

See also comments below

in a transaction that’s rolled back on completion. This ensures

tables

any transactions started in your code will be automatically rolled

method),
integration tests
require File.dirname(FILE) + ‘/…/test_helper’

class HolidaysTest < ActiveSupport::TestCase
test_methods_for_testing
end

Location:- test/unit/holidays_test.rb

That should be class HolidayTest in holiday_test.rb
Again make sure you do not leave the old files or backup files as they
will get run.

Colin

On 20 February 2010 11:55, Hemant B. [email protected] wrote:

FixtureClassNotFound: No class attached to find.
test/integration/leave_test.rb:17:in
`test_leave_page_access_if_employee_login’

So if I read correctly then with the set_fixture_class you get the
unable to load problem above but if you do not have the
set_fixture_class it loads the fixtures ok, but gives a different
error. Not exactly what you said before. So the conclusion is that
set_fixture_class is not required (and in fact causes the the unable
to load error). So I suggest you leave out set_fixture_class and move
on to the next error.

What happens if you change the class and file names as I suggested in
my other post?

Colin

Colin L. wrote:

On 20 February 2010 11:25, Hemant B. [email protected] wrote:

What else you want …

As I said above, post the error after checking that there is no
set_fixture_class anywhere.

In TEST.LOG

FOR HOLIDAYS:-
Unable to load holiday, underlying cause no such file to load – holiday

FOR ACCOUNTS:-
Unable to load account, underlying cause no such file to load – account

Means that it is coming for every table… Also if i dont do
set_fixture_class :holidays => ‘Holidays’ then while running test cases
i am getting error

FixtureClassNotFound: No class attached to find.
test/integration/leave_test.rb:17:in
`test_leave_page_access_if_employee_login’

Colin

Ok fine colin… somehow i managed to get rid of this… I’ll you how i
had done this…

For time being can you please tell me that how to specify the plural
names?
I mean i have a fixture file leaves.yml and by default error is coming
that no file to load - leafe…

So if I read correctly then with the set_fixture_class you get the
unable to load problem above but if you do not have the
set_fixture_class it loads the fixtures ok, but gives a different
error. Not exactly what you said before. So the conclusion is that
set_fixture_class is not required (and in fact causes the the unable
to load error). So I suggest you leave out set_fixture_class and move
on to the next error.

What happens if you change the class and file names as I suggested in
my other post?

Colin

Hemant B. wrote:

Ok fine colin… somehow i managed to get rid of this… I’ll you how i
had done this…

For time being can you please tell me that how to specify the plural
names?

Hello dude … Thanks a lot to you …
Anywayz i have resolved it. the only problem wat that i was giving
fixtures :all in test_helper… I still think that there is no problem
writing that line in test_helper… but i just removed that line from
there and it worked like a charm … :slight_smile:

Cheers …

I mean i have a fixture file leaves.yml and by default error is coming
that no file to load - leafe…

On 21 February 2010 12:44, Hemant B. [email protected] wrote:

writing that line in test_helper… but i just removed that line from
there and it worked like a charm … :slight_smile:

I guess you have merely delayed the problem here by avoiding
attempting to load the fixture for the problematic model. When you
come to test the leave model the problem will re-appear. As I said
before it is important to get the names correct. The model class name
should be singular (class Thing < ActiveRecord::Base in thing.rb), the
unit test also singular (ThingTest in thing_test.rb) and the fixtures
file plural (things.yml).

To check what rails thinks are the singular and the plural of words
run script/console so for example
colinl@piglet:~/websites/weather$ script/console
Loading development environment (Rails 2.3.4)

“leaves”.singularize
=> “leafe”
“leafe”.pluralize
=> “leaves”
“leaf”.pluralize
=> “leafs”

I must admit that leafe looks wrong to me, I am not sure that it even
a word. I would have expected the singular of leaves to be leave or
leaf (in UK English at least). This may even be a bug.

It is possible to override the builtin rules for your model names if
you wish but it is generally simpler to avoid this unless you really
have to. Google will tell you how if you feel the need.

Colin