未定义的方法`有&#39; for#<object:0x007f997fabf778>(NoMethodError)

时间:2017-05-09 22:52:24

标签: ruby rspec automation cucumber capybara

我收到了一条未定义的方法错误消息,因为&#39;有&#39;方法

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

有人有任何建议吗?

1 个答案:

答案 0 :(得分:1)

Capybara没有提供have匹配器,它提供了一堆have_<something>匹配器。假设@gymhomepage.find_your_local_gym.first_gym_location返回一个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元素将其限定为<input class="my-input" ...> input.my-input { ... } 元素(假设您没有陷入XPath陷阱 - https://github.com/teamcapybara/capybara#beware-the-xpath--trap

相关问题