I am testing with assert_equal
Here is my Fixture:
bob1:
id: 1000001
login: bob
glogin: bob-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org
session_token: 77a38 # test
Here is my Test method:
class Guser < ActiveRecord::Base
attr_accessor :session_token
def self.match_login(glogin, login, ses_token)
u=find(:first, :conditions=>["glogin = ? AND login = ?",
glogin,
login])
return nil if u.nil?
if (u.session_token != ses_token)
u.session_token = ses_token
return u
end
nil
end
end
The test database table is Guser and it has no rows to start with
Here is my where I call test method:
assert_equal @bob1,
Guser.match_login("bob-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org",
"bob", "77a038")
I get this message on the console:
1) Failure:
test_match_login(GuserTest) [test/unit/guser_test.rb:14]:
<#<Guser id: 1000001, glogin:
"bob-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org", login: "bob",
session_token: "77a
0d943cdbace52716a9ef9fae12e45e2788d38", created_at: "2010-02-02
15:45:37", updat
ed_at: "2010-02-02 15:45:37">> expected but was
<nil>.
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
I expected the test to fail as there was no record in the database and
the ''find'' should return nothing. But it creates a new one and
the test
is a success. I do not see any code for creating new record or save. So
why is it creating a new record?
I do not understand assert_equal behavior , can someone please explain?
--
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-/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.
On Feb 2, 3:58 pm, Vishwa Rao <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > I expected the test to fail as there was no record in the database and > the ''find'' should return nothing. But it creates a new one and the test > is a success. I do not see any code for creating new record or save. So > why is it creating a new record? > I do not understand assert_equal behavior , can someone please explain?assert_equal is a simple beast - it just compares the two arguments you pass to it. What you actually don''t understand is how the test database is setup. In particular if you have a fixtures file for a table (as you appear to do) rails will create rows in that table for you based on your fixtures file. 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.
On Feb 2, 9:58 am, Vishwa Rao <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I am testing with assert_equal > > Here is my Fixture: > bob1: > id: 1000001 > login: bob > glogin: b...-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org > session_token: 77a38 # test > > Here is my Test method: > class Guser < ActiveRecord::Base > attr_accessor :session_token > def self.match_login(glogin, login, ses_token) > u=find(:first, :conditions=>["glogin = ? AND login = ?", glogin, > login]) > return nil if u.nil? > if (u.session_token != ses_token) > u.session_token = ses_token > return u > end > nil > end > end > > The test database table is Guser and it has no rows to start with > > Here is my where I call test method: > assert_equal @bob1, Guser.match_login("b...-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org", "bob", "77a038") > > I get this message on the console: > 1) Failure: > test_match_login(GuserTest) [test/unit/guser_test.rb:14]: > <#<Guser id: 1000001, glogin: "b...-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org", login: "bob", > session_token: "77a > 0d943cdbace52716a9ef9fae12e45e2788d38", created_at: "2010-02-02 > 15:45:37", updat > ed_at: "2010-02-02 15:45:37">> expected but was > <nil>. > 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips >You want users(:bob1), not @bob1, in your test (unless you''ve explicitly turned on use_instantiated_fixtures = true in your test_helper.rb). Jeff purpleworkshops.com> I expected the test to fail as there was no record in the database and > the ''find'' should return nothing. But it creates a new one and the test > is a success. I do not see any code for creating new record or save. So > why is it creating a new record? > I do not understand assert_equal behavior , can someone please explain? > -- > Posted viahttp://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-/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.