简单测试发现奇怪的错误
这就是我正在测试的:
模型
scope :user_pending, lambda { |user|
where("jobs.available = 0 AND jobs.user_id = ?", user.id) }
测试
it "should have the scope" do
Job.should respond_to(:user_pending)
end
it "should return a list of jobs that are unavailable for the current_user" do
@user = Factory(:user, :id => 1)
@job = Factory(:job, :available => false, :user_id => @user)
Job.user_pending(@user).should == @job
end
第一个测试通过了,但我无法通过第二个测试。返回以下错误消息:
Failures:
1) Job Job :user_pending should return a list of jobs that are unavailable for the current_user
Failure/Error: Job.user_pending(@user).should == @job
expected: #<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para [email protected]", locked: false, visits: 0>,
got: [#<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para [email protected]", locked: false, visits: 0>] (using ==)
Diff:
@@ -1,2 +1,2 @@
-#<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para [email protected]", locked: false, visits: 0>
+[#<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para [email protected]", locked: false, visits: 0>]
# ./spec/models/job_spec.rb:91:in `block (3 levels) in <top (required)>'
我缺少什么?看起来一切都好,对吧?我不明白那里出了什么问题。
this is what I'm testing:
model
scope :user_pending, lambda { |user|
where("jobs.available = 0 AND jobs.user_id = ?", user.id) }
test
it "should have the scope" do
Job.should respond_to(:user_pending)
end
it "should return a list of jobs that are unavailable for the current_user" do
@user = Factory(:user, :id => 1)
@job = Factory(:job, :available => false, :user_id => @user)
Job.user_pending(@user).should == @job
end
the first test is passing, but I can't pass on second. The following error message is returning:
Failures:
1) Job Job :user_pending should return a list of jobs that are unavailable for the current_user
Failure/Error: Job.user_pending(@user).should == @job
expected: #<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para [email protected]", locked: false, visits: 0>,
got: [#<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para [email protected]", locked: false, visits: 0>] (using ==)
Diff:
@@ -1,2 +1,2 @@
-#<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para [email protected]", locked: false, visits: 0>
+[#<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para [email protected]", locked: false, visits: 0>]
# ./spec/models/job_spec.rb:91:in `block (3 levels) in <top (required)>'
what I missing? it's look all okay, right? I can't understand whats wrong there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您的作用域正在返回一个数组(这是我所期望的)。您的测试可能应如下所示:
Job.user_pending(@user).first.should == @job
It appears that your scope is returning an array (which is what I would expect). Your test should probably look like:
Job.user_pending(@user).first.should == @job