According to this Rails guide, if you create a fixture, it becomes available in your test class.
I have this fixture in users.yml:
<% stan = User.new stan.username = 'stan' stan.set_hashed_password('mysterio') stan.email = 'stan@abc.com' %> stan: username: <%= stan.username %> hashed_password: <%= stan.hashed_password %> password_salt: <%= stan.password_salt %> email: <%= stan.email %>
Following the Rails guide, I’m trying to access it like this:
class SessionsControllerTest < ActionController::TestCase @user = users(:stan) # ... end
I get this error:
./test/functional/sessions_controller_test.rb:5: undefined method `users' for SessionsControllerTest:Class (NoMethodError) from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'
Thanks for the help guys. I realized that I had various declarations and calls structured incorrectly. This isn’t clearly explained in the guide I cited, but apparently
users(:stan)only works inside ashouldblock, or in pure Test::Unit inside atest_method.