Hi, Im currently writing unit tests for a fairly simple application and Im using mysql with RoR. When i have the following test: def test_create assert_equal 1, @result.id assert_equal ''henry-test'', @result.module_name assert_equal "11:24", @result.build_status_since assert_equal ''10:00'', @result.last_failure assert_equal ''11:20'', @result.last_success assert_equal ''b.12'', @result.build_number assert_equal ''http://127.0.0.1:3000/test.html'', @result.build_url assert_equal ''Tue Nov 28 11:45:36 GMT Standard Time 2006'', @result.last_check end which is for the standard create action in rails scaffold i get the following error: 1) Failure: test_create(ResultTest) [./test/unit/result_test.rb:19]: <"Tue Nov 28 11:45:36 GMT Standard Time 2006"> expected but was <Tue Nov 28 11:45:36 GMT Standard Time 2006>. the data matches up but it fails the test? does anyone know why this is happening? If it matters im loading in the db using fixtures. see below: first: id: 1 module_name: henry-test build_status_since: ''11:24'' last_failure: ''10:00'' last_success: ''11:20'' build_number: ''b.12'' build_url: ''http://127.0.0.1:3000/test.html'' last_check: "2006-11-28 11:45:36" cheers, Chris -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chris Gallagher wrote:> assert_equal ''Tue Nov 28 11:45:36 GMT Standard Time 2006'', > @result.last_check> test_create(ResultTest) [./test/unit/result_test.rb:19]: > <"Tue Nov 28 11:45:36 GMT Standard Time 2006"> expected but was > <Tue Nov 28 11:45:36 GMT Standard Time 2006>.Try: assert_equal ''Tue Nov 28 11:45:36 GMT Standard Time 2006'', @result.last_check.to_s --Al Evans -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chris Aside from Al''s solution to your problem.. > def test_create > assert_equal ''henry-test'', @result.module_name > assert_equal "11:24", @result.build_status_since > assert_equal ''10:00'', @result.last_failure > end If you really need tests that fine-grained, you should not hesitate to modify the models to make your tests easier to write and read: Example: class User < ActiveRecord::Base def test_s <<------ ADD THIS METHOD "#{name} - #{login} - #{email}" end ... end => you can now write assertions like assert_equal "John Doe - jdoe - john.doe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org", user.test_s Alain --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Al Evans wrote:> Try: > > assert_equal ''Tue Nov 28 11:45:36 GMT Standard Time 2006'', > @result.last_check.to_sShouldn''t that be .to_s :db, and a spiked date sample (via techniques related to "mock objects"), _and_ a matching style date in the equal? -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---