0
我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.
這是一個明顯的啞巴兒子?我很抱歉,如果是..我無法弄清楚。
HTML是如何生成的?如果有ERB代碼,你可以發佈ERB代碼片段嗎? – 2012-03-06 19:36:15
用我上面的haml更新。 – Trip 2012-03-06 19:50:37