2016-11-21 47 views
0

我是新來黃瓜測試,我很困惑,爲什麼這將無法正常工作。正如你所看到的,我試圖在編輯後顯示位置的更新細節,但我收到下面的錯誤。任何人都可以幫助我發現什麼是錯的?黃瓜測試 - 任何人都可以解決我的'編輯'情景?

錯誤=

Then I should see the updated location details # features/step_definitions/location_steps.rb:71 
    expected to find text "#<Location:0x007fac52ca98f0>" in "/Location/289" (RSpec::Expectations::ExpectationNotMetError) 
    ./features/step_definitions/location_steps.rb:73:in `/^I\ should\ see\ the\ updated\ location\ details$/' 
    features/location.feature:24:in `Then I should see the updated location details' 

feature.rb =

Scenario: editing a location 
Given There is a location 
And I am on the location details page 
When I click on edit 
Then I should see edit location form 
When I edit location details 
And I click submit changes 
Then I should see the updated location details 

steps.rb =

Given "There is a location" do 
    @location = create(:location) 
end 

And "I am on the locations page" do 
    visit locations_path 
end 

When "I click on edit" do 
    click_link "edit" 
end 

Then "I should see edit location form" do 
    visit edit_location_path(@location) 
end 

When "I edit location details" do 
    @edited_location = build(:location) 
end 

And "I click submit changes" do 
    click_on "Submit Changes" 
end 

Then "I should see the updated location details" do 
    visit location_path(@location) 
    expect(location_path(@location)).to have_content(@edited_location) 
end 
+0

什麼是「@ edited_location」?看起來你正在傳遞一個'Location'對象而不是'String'。我猜你想要傳遞'@ edited_location'的某些屬性。 –

回答

0

有相當這裏的幾個誤區:

首先,這一步​​是不需要的。當你點擊編輯時,你會被帶到某處,因此不需要立即去別的地方

然後,應該只看事情,他們不應該執行操作,例如訪問

步驟When "I edit location details"也是非常錯誤的。在這裏,我懷疑你正在與工廠女孩做些什麼。你應該做的是使用Capybara與你的編輯表單交互,並改變一個值,例如

fill_in(postcode, with: 'M1 3MM') 

當的應該只有在應用程序UI

互動你最後then重複做一個訪問的錯誤。它應該已經存在,如果它不是你的代碼無法正常工作。

有一個負載更多的東西,但希望這足以讓你開始。

最後的幾個提示:

  1. 瞭解如何使用調試器,所以你可以在你的腳步停下來,看看你在哪裏。
  2. 在編寫場景時,通過瀏覽器運行它,以便了解發生了什麼。