Greg Freemyer
2006-Jan-16 19:49 UTC
[Rails] My first test - named fixture not autoloading instance variable
I''m trying to write a test like the one at the bottom of page 148 in Agile Rails. I''m using rails 1.0 I''ve created the fixture correctly I''m pretty sure because the test database table is being populated per the fixture. I have what I think is a simple unit test: ========require File.dirname(__FILE__) + ''/../test_helper'' class CaseTest < Test::Unit::TestCase fixtures :cases def setup @case = Case.find(1) end # Replace this with your real tests. def test_verify_schema_has_correct_fields assert_kind_of Case, @case assert_equal 1, @case.id assert_equal "F-06-101", @case.case_number assert_equal @first.case_number, @case.case_number end ==== The first 2 assert_equal statements are working fine and demonstrate the basic table logic is fine and that my fixture is working. The third one is failing because @first is nil. Per the book @first should be automatically created because it is the name of my fixture. (ie. the scaffold named the first fixture "first" and I should be able to reference it as @first.) Any idea what is wrong? Greg -- Greg Freemyer The Norcross Group Forensics for the 21st Century
Tom Ward
2006-Jan-16 19:58 UTC
[Rails] My first test - named fixture not autoloading instance variable
If in test_helper.rb you have use_instantiated_fixtures = false, then your fixtures will not be pre-instantiated into instance variables. You can still access the fixture you want using cases(:first) Tom Ward On 1/16/06, Greg Freemyer <greg.freemyer@gmail.com> wrote:> I''m trying to write a test like the one at the bottom of page 148 in > Agile Rails. > > I''m using rails 1.0 > > I''ve created the fixture correctly I''m pretty sure because the test > database table is being populated per the fixture. > > I have what I think is a simple unit test: > ========> require File.dirname(__FILE__) + ''/../test_helper'' > > class CaseTest < Test::Unit::TestCase > fixtures :cases > > def setup > @case = Case.find(1) > end > > # Replace this with your real tests. > def test_verify_schema_has_correct_fields > assert_kind_of Case, @case > assert_equal 1, @case.id > assert_equal "F-06-101", @case.case_number > assert_equal @first.case_number, @case.case_number > end > ====> > The first 2 assert_equal statements are working fine and demonstrate > the basic table logic is fine and that my fixture is working. > > The third one is failing because @first is nil. > > Per the book @first should be automatically created because it is the > name of my fixture. (ie. the scaffold named the first fixture "first" > and I should be able to reference it as @first.) > > Any idea what is wrong? > > Greg > -- > Greg Freemyer > The Norcross Group > Forensics for the 21st Century > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Greg Freemyer
2006-Jan-16 20:55 UTC
[Rails] My first test - named fixture not autoloading instance variable
That worked. Thanks Tom On 1/16/06, Tom Ward <tom@popdog.net> wrote:> If in test_helper.rb you have use_instantiated_fixtures = false, then > your fixtures will not be pre-instantiated into instance variables. > You can still access the fixture you want using cases(:first) > > Tom Ward > > On 1/16/06, Greg Freemyer <greg.freemyer@gmail.com> wrote: > > I''m trying to write a test like the one at the bottom of page 148 in > > Agile Rails. > > > > I''m using rails 1.0 > > > > I''ve created the fixture correctly I''m pretty sure because the test > > database table is being populated per the fixture. > > > > I have what I think is a simple unit test: > > ========> > require File.dirname(__FILE__) + ''/../test_helper'' > > > > class CaseTest < Test::Unit::TestCase > > fixtures :cases > > > > def setup > > @case = Case.find(1) > > end > > > > # Replace this with your real tests. > > def test_verify_schema_has_correct_fields > > assert_kind_of Case, @case > > assert_equal 1, @case.id > > assert_equal "F-06-101", @case.case_number > > assert_equal @first.case_number, @case.case_number > > end > > ====> > > > The first 2 assert_equal statements are working fine and demonstrate > > the basic table logic is fine and that my fixture is working. > > > > The third one is failing because @first is nil. > > > > Per the book @first should be automatically created because it is the > > name of my fixture. (ie. the scaffold named the first fixture "first" > > and I should be able to reference it as @first.) > > > > Any idea what is wrong? > > > > Greg > > -- > > Greg Freemyer > > The Norcross Group > > Forensics for the 21st Century > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Greg Freemyer The Norcross Group Forensics for the 21st Century