#<Object:0x007f997fabf778> 的未定义方法“有”(NoMethodError)

undefined method `have' for #<Object:0x007f997fabf778> (NoMethodError)

我收到 'have' 方法的未定义方法错误消息。

expect(@gymhomepage.find_your_local_gym).to have(@gymhomepage.find_your_local_gym.first_gym_location)

我正在尝试断言 first_gym_location css 是否位于 find_your_local_gym 部分。

Please see my framework on Github

大家有什么建议吗?

Capybara 不提供 have 匹配器,它提供了一堆 have_<something> 匹配器。假设 @gymhomepage.find_your_local_gym.first_gym_location returns 一个 CSS 选择器那么你会使用

expect(@gymhomepage.find_your_local_gym).to have_css(@gymhomepage.find_your_local_gym.first_gym_location)

如果相反,@gymhomepage.find_your_local_gym.first_gym_location 是一种查找元素的方法,您只需要这样做

expect(@gymhomepage.find_your_local_gym.first_gym_location).to be

因为它已经保证通过调用它被限定在 find_your_local_gym 元素中(假设您没有落入 XPath 陷阱 - https://github.com/teamcapybara/capybara#beware-the-xpath--trap