On Dec 22, 10:38 pm, Marnen Laibow-Koser <[email protected]> wrote:
> Let's see your error messages. But why the heck are you defining an
> object like this anyway? What are you trying to achieve?
I'm trying to get a test for acts_as_list working. I've defined a
method in test_helper that I use in my unit tests:
# tests acts as list and default_scope :order => 'position'
def self.should_act_as_list(options = {})
klass = self.name.gsub(/Test$/, "").constantize # converts string
to class
context "acting as a list" do
setup do # DON'T DO THIS???
#...@instance = klass.all[0]
end
should "have a position column" do
instance = klass.first
assert_not_nil instance.position, :message => "If you
see me, check
out the POSITION."
end
should "move objects correctly" do
instance = klass.first
instance.move_to_bottom
assert_equal klass.all[-1], instance
instance.move_higher
assert_equal klass.all[-2], instance
instance.move_to_top
assert_equal klass.first, instance
instance.move_lower
assert_equal klass.all[1], instance
end
end
end
My error messages just show this:
---------------
Loaded suite C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/
rake_test_loader
Started
....EE.....................EEEE..
Finished in 0.171875 seconds.
1) Error:
test: An article acting as a list should have a position column.
(ArticleTest):
NoMethodError: undefined method `position' for nil:NilClass
/test/test_helper.rb:36:in `__bind_1293122683_953075'
2) Error:
test: An article acting as a list should move objects correctly.
(ArticleTest):
NoMethodError: undefined method `move_to_bottom' for nil:NilClass
/test/test_helper.rb:41:in `__bind_1293122683_953075'
3) Error:
test: acting as a list should have a position column. (PageTest):
NoMethodError: undefined method `position' for nil:NilClass
/test/test_helper.rb:36:in `__bind_1293122684_93700'
4) Error:
test: acting as a list should move objects correctly. (PageTest):
NoMethodError: undefined method `move_to_bottom' for nil:NilClass
/test/test_helper.rb:41:in `__bind_1293122684_93700'
5) Error:
test: A section acting as a list should have a position column.
(SectionTest):
NoMethodError: undefined method `position' for nil:NilClass
/test/test_helper.rb:36:in `__bind_1293122684_109325'
6) Error:
test: A section acting as a list should move objects correctly.
(SectionTest):
NoMethodError: undefined method `move_to_bottom' for nil:NilClass
/test/test_helper.rb:41:in `__bind_1293122684_109325'
33 tests, 28 assertions, 0 failures, 6 errors
rake aborted!
Command failed with status (1): [C:/Ruby187/bin/ruby.exe -I"lib;test"
"C:/R...]
-------
..which is really the same error over and over again. My variable
"instance" becomes nil somehow.
>>> ...and I'm sure that my test db is populated whenever I run my tests...
> You shouldn't have to be sure of that beforehand; rather, you should be
> using factories to create records for tests on the fly.
I want my development and test dbs to be the same, so I thought using
the seeds.rb file - which in my case uses Factories - in conjunction
with rake db:seed RAILS_ENV=test would be the best way. There are
some things I want to have set names for, like sections - they'll
always be Sports, News, etc. Other things like Articles, though, I
generate in the seeds file en masse.
Is my methodology totally wrong? Should I be testing acts_as_list's
functionality in a totally different way?
I mean, are you saying I should create records in the "setup" method
for each unit test rather than populate the db with that rake db:seed
RAILS_ENV=test command?
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.