黄瓜测试 - 谁能解决我的 'edit' 场景?
Cucumber Test - Can anyone solve my 'edit' Scenario?
我是黄瓜测试的新手,我很困惑为什么这不起作用。如您所见,我正在尝试测试某个位置的更新详细信息是否在编辑后显示,但我收到以下错误。谁能帮我找出问题所在?
错误=
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
这里有不少错误:
首先,不需要这一步 Then I should see edit location form
。当您单击编辑时,您将被带到某个地方,因此之后无需立即去其他地方
那就只看东西,不应该做动作访问
步骤When "I edit location details"
也很错误。在这里,我怀疑你在和工厂女工做某事。您应该做的是使用 Capybara 与您的编辑表单进行交互并更改一个值,例如
fill_in(postcode, with: 'M1 3MM')
什么时候应该只与应用程序交互UI
你上次then
重复了访问的错误。它应该已经存在,如果不是,您的代码将无法正常工作。
还有很多内容,但希望这些足以让您入门。
最后一点提示:
- 学习使用调试器,这样您就可以停下来查看自己的进度。
- 编写场景时 运行 通过浏览器编写场景,这样您就可以看到发生了什么。
我是黄瓜测试的新手,我很困惑为什么这不起作用。如您所见,我正在尝试测试某个位置的更新详细信息是否在编辑后显示,但我收到以下错误。谁能帮我找出问题所在?
错误=
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
这里有不少错误:
首先,不需要这一步 Then I should see edit location form
。当您单击编辑时,您将被带到某个地方,因此之后无需立即去其他地方
那就只看东西,不应该做动作访问
步骤When "I edit location details"
也很错误。在这里,我怀疑你在和工厂女工做某事。您应该做的是使用 Capybara 与您的编辑表单进行交互并更改一个值,例如
fill_in(postcode, with: 'M1 3MM')
什么时候应该只与应用程序交互UI
你上次then
重复了访问的错误。它应该已经存在,如果不是,您的代码将无法正常工作。
还有很多内容,但希望这些足以让您入门。
最后一点提示:
- 学习使用调试器,这样您就可以停下来查看自己的进度。
- 编写场景时 运行 通过浏览器编写场景,这样您就可以看到发生了什么。