Differences in default unit tests between Rails versions

In my efforts to upgrade our site from 2.1.0 to 3.0.x, I have upgraded
to 2.2.2 and the site works, but I am working on understanding tests,
fixtures and the whole deal. So realizing that upgrading really means
testing, what I actually did was look the schema.rb file for our 2.1.0
site and then created a blank Rails 2.2.2 site and used scaffold
(gasp) to generate a fully baked model, controller, view, and tests
that had the same fields. My table is job_posts and the corresponding
unit test was job_post_test.rb

So, two questions. When I compare the two I see differences in the
structure. Our current 2.1.0 site test had the following:
require File.dirname(FILE) + ‘/…/test_helper’

class JobPostTest < Test::Unit::TestCase
fixtures :job_posts

Replace this with your real tests.

def test_truth
assert true
end
end

So, I go over the freshly minted, empty 2.2.2 app and look at the test
created when I scaffolded and saw:
require ‘test_helper’

class JobPostTest < ActiveSupport::TestCase

Replace this with your real tests.

test “the truth” do
assert true
end
end

Is some of this because the default test syntax has changed? Is there
a way to re-create the unit tests in my older app? Basically, tell
Rails to overwrite the older unit tests and create new ones that match
the tables in the schema.rb? I understand the default tests don’t do
much, but I would like to start with a clean slate since I don’t think
our sites tests have much in them anyway.

On Mar 25, 3:07am, “sol.manager” [email protected] wrote:

end
end
end

Is some of this because the default test syntax has changed? Is there
a way to re-create the unit tests in my older app? Basically, tell
Rails to overwrite the older unit tests and create new ones that match
the tables in the schema.rb? I understand the default tests don’t do
much, but I would like to start with a clean slate since I don’t think
our sites tests have much in them anyway.

Rails can’t guess what your models should do, so it can’t possibly
rewrite your tests. It would be possible to write something that would
rewrite

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

to

require ‘test_helper’

but you could just use search & replace in your editor.

test “foo” do
end

is just a style thing. Behind the scenes it will generate a test_foo
method, and you can continue to just write def test_foo (about the
only different is that test ‘foo’ will raise an error if there is
already a test with that name

Fred

On 25 March 2011 03:07, sol.manager [email protected] wrote:

In my efforts to upgrade our site from 2.1.0 to 3.0.x, I have upgraded
to 2.2.2 and the site works, but I am working on understanding tests,
fixtures and the whole deal.

If your app does not already have decent tests, so you are starting
effectively from scratch with the testing, then I would advise against
using fixtures. Instead use a factory such as Machinist or
FactoryGirl. Google for the terms and you will find discussions on
the reasons.

Colin