2011-10-18 43 views
0

我剛開始使用Cucumber,我不確定如何測試視圖中的部分內容。

這裏是我的特點
黃瓜:posting.feature使用Cucumber測試Ruby on Rails嵌套視圖

Scenario: After having created job posting 
    Given I am authenticated as "administrator" 
    Given I am on the new posting page 
    When I press "Create Posting" 
    Then I should see "Back to list of all postings" 


(這是網頁,我目前)
我new.html.haml

= link_to 'Logout', logged_out_url(@user) 
%h1 New posting 
= render 'form' 
%br/ 
= link_to 'Cancel', postings_path 


(這是在new.html.haml其「創建發佈」加載視圖按鈕,我想測試)
_form.html.haml

= form_for(@postings) do |posting_builder| 
    - if @postings.errors.any? 
     #error_explanation 
     %h2 
      = pluralize(@postings.errors.count, "error") 
      prohibited this posting from being saved: 
     %ul 
      - @postings.errors.full_messages.each do |msg| 
      %li= msg 

.field 
    %b= posting_builder.label :title 
    %br/ 
    = posting_builder.text_field :title 
.field 
    %b= posting_builder.label :description 
    %br/ 
    = posting_builder.text_field :description 
.field 
    %b= posting_builder.label :requirements 
    %br/ 
    = posting_builder.text_field :requirements 
.field 
    %b= posting_builder.label :location 
    %br/ 
    = posting_builder.text_field :location 
.field 
    %b= posting_builder.label :Admin 
    %br/ 
    = select("posting", "user_id", User.order('last_name ASC').collect {|u| [u.fullname, u.id]}) 

%br/ 
%br/ 

/Submit 
.actions 
= posting_builder.submit 


有任何建議至於我應該如何處理這個或與我的問題相關的資源/例子?

回答

2

您不應該嘗試單獨測試部分。黃瓜沒有看到與主頁分開的部分,它看到完全呈現的頁面(包括所有部分內容)。所以,如果你做And I should see [the text from the partial]那麼你很好。

如果這不是工作,你認爲它應該,在And I should see...步驟之前然後右鍵,增加一個步驟,說And show me the page,它會打開你的默認瀏覽器,並顯示您黃瓜看到的東西。這可能會幫助您找出您實際上的頁面,以及它與您的預期不符。

注意:當您使用And show me the page時,您所得到的內容有時會被精簡(無格式,無.CSS)版本的頁面,所以如果不像所看到的頁面一樣通過瀏覽器瀏覽時通常會看到。重要的是它包含HTML,標籤,名稱,元素的ID等。