我是黄瓜测试的新手,我很困惑为什么这不起作用。正如您所看到的,我正在尝试测试编辑后显示位置的更新详细信息,但我收到以下错误。任何人都可以帮我发现错误吗?
错误=
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 :(得分:0)
这里有很多错误:
首先,不需要此步骤Then I should see edit location form
。当你点击编辑时,你将被带到某个地方,所以之后不需要立即去其他地方
然后应该只看事情,他们应该永远不要执行行动,例如访问强>
步骤When "I edit location details"
也是非常错误的。在这里,我怀疑你正在和工厂女孩做些什么。您应该做的是使用Capybara与编辑表单进行交互并更改值,例如
fill_in(postcode, with: 'M1 3MM')
什么时候应该只与应用程序UI交互
你的上一次then
重复了访问的错误。它应该已经存在,如果它不是你的代码不能正常工作。
有更多的东西,但希望这足以让你开始。
最后提示几点: