为什么这个功能测试会失败?

时间:2012-03-06 19:26:16

标签: ruby-on-rails unit-testing functional-testing

我的haml:

- for status in current_account.job_statuses.active
  = link_to status.name, '#', :class => params[:job_status_id].to_i == status.id ? "current status block" : "status block", :rel => status.id

我的HTML:

<a rel="1" class="status block" href="#">in progress</a>
<a rel="2" class="status block" href="#">in progress</a>
<a rel="3" class="status block" href="#">in progress</a>
<a rel="4" class="status block" href="#">in progress</a>

我的测试:

test 'index - job_status: set' do
  job_status = @account.job_statuses.create! :name => 'foo'
  job_status.reload

  @job.update_attribute :job_status_id, job_status.id
  @job.reload

  get :index, :job_status_id => job_status.id.to_s
  assert_response :success
  assert_template 'jobs/index'

  jobs = assigns(:jobs)

  assert jobs.include?(@job)
  assert_select 'div.status[rel=?]', job_status.id
end

但是我失败了:

  3) Failure:
test_index_-_job_status:_set(NewJobsControllerTest)
    [test/functional/new_jobs_controller_test.rb:127:in `block in <class:NewJobsControllerTest>'
     test/test_helper.rb:221:in `run'
     test/test_helper.rb:221:in `run']:
Expected at least 1 element matching "div.status[rel='16']", found 0.
<false> is not true.

这是一个明显的愚蠢原因吗?我道歉,如果是......我无法理解。

1 个答案:

答案 0 :(得分:2)

喔。总是那些我们从未想过要检查的小东西......在那个HAML无用地盯着我要求五分钟之后,它击中了我:

那些不是DIV。这些是A s。

干杯!