Mysql and unit tests

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

Chris G. 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

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 D. - jdoe - [email protected]”, user.test_s

Alain

Al Evans wrote:

Try:

assert_equal ‘Tue Nov 28 11:45:36 GMT Standard Time 2006’,
@result.last_check.to_s

Shouldn’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
Redirecting... ← NOT a blog!!!