sol.manager
2011-Mar-25 03:07 UTC
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. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Mar-25 07:21 UTC
Re: differences in default unit tests between Rails versions
On Mar 25, 3:07 am, "sol.manager" <sol.mana...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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.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 -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Mar-25 08:49 UTC
Re: differences in default unit tests between Rails versions
On 25 March 2011 03:07, sol.manager <sol.manager-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.