【问题标题】:Cucumber Test - Can anyone solve my 'edit' Scenario?黄瓜测试 - 任何人都可以解决我的“编辑”场景吗?
【发布时间】:2016-11-21 14:13:20
【问题描述】:

我是黄瓜测试的新手,我很困惑为什么这不起作用。如您所见,我正在尝试测试位置的更新详细信息是否在编辑后显示,但我收到以下错误。谁能帮我找出问题所在?

错误 =

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

【问题讨论】:

  • 什么是@edited_location?看起来您传递的是 Location 对象而不是 String。我猜你想传递@edited_location 的一些属性。

标签: ruby-on-rails testing cucumber edit


【解决方案1】:

这里有不少错误:

首先这一步Then I should see edit location form 是不需要的。当您单击编辑时,您将被带到某个地方,因此无需立即去其他地方

那么应该只看事物,他们不应该执行操作,例如访问

When "I edit location details"这一步也很不对。在这里,我怀疑你在和工厂女孩做某事。您应该做的是使用 Capybara 与您的编辑表单交互并更改值,例如

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

何时应该只与应用程序 UI 交互

您的最后一个then 重复了访问的错误。它应该已经存在,如果不是,您的代码无法正常工作。

还有很多东西,但希望这足以让你开始。

最后几点提示:

  1. 学习使用调试器,这样您就可以停下来看看自己在哪里。
  2. 在编写场景时,通过浏览器运行它,这样您就可以看到发生了什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-02
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多