From: Sarah Allen Date: 2009-03-02T18:49:38+09:00 Subject: passing a method as a paramter I'm probably missing some basic Ruby syntax, but I'm relatively new to Ruby and can't figure this out from the various references I've looked at I'd like to use this nifty test helper: # Calls creation_method with nil values for field_names and asserts that # the resulting object was not saved and that errors were added for that field. # # assert_required_fields :create_article, :subject, :body, :author def assert_required_fields(creation_method, *field_names) field_names.each do |field| record = send(creation_method, field => nil) assert_equal false, record.valid? assert_not_nil record.errors.on(field) end end However, I don't know how to pass the creation method. My basic test would be: def test_should_create_user user = User.create(:email => "fred@foo.com", :lastname => "jones", :password => "secret"); assert user.valid?, "User was invalid:\n#{user.to_yaml}" end I tried this for the failure case... def test_should_not_create_user_unless_default_fields assert_required_fields User::create, :email, :lastname, :password end But that reports an error: 1) Error: test_should_not_create_user_unless_default_fields(UserTest): TypeError: # is not a symbol Can someone advise me of the correct syntax? Thanks, Sarah -- Posted via http://www.ruby-forum.com/.