2012-03-06 113 views
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. 

這是一個明顯的啞巴兒子?我很抱歉,如果是..我無法弄清楚。

+0

HTML是如何生成的?如果有ERB代碼,你可以發佈ERB代碼片段嗎? – 2012-03-06 19:36:15

+0

用我上面的haml更新。 – Trip 2012-03-06 19:50:37

回答

2

哦。總是那些我們從未想過要檢查的小東西......在那個HAML無用地凝視之後,我問了五分鐘它打我:

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

乾杯!

+0

哈...大起大落。非常感謝 ;) – Trip 2012-03-06 20:22:30