Странная ошибка с простым тестом - PullRequest
1 голос
/ 31 января 2011

это то, что я тестирую:

модель

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 contato@test.com", 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 contato@test.com", 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 contato@test.com", 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 contato@test.com", locked: false, visits: 0>]
     # ./spec/models/job_spec.rb:91:in `block (3 levels) in <top (required)>'

что мне не хватает? все выглядит хорошо, верно? Я не могу понять, что там не так.

1 Ответ

3 голосов
/ 31 января 2011

Похоже, что ваша область возвращает массив (что я и ожидал). Ваш тест должен выглядеть примерно так:

Job.user_pending(@user).first.should == @job

...