gpt4 book ai didi

testing - NoMethodError 对 rspec 使用 has_selector

转载 作者:行者123 更新时间:2023-11-28 21:31:07 24 4
gpt4 key购买 nike

这些是我的测试:

it "should have the title 'Contact'" do

visit '/static_pages/contact'

expect(page).to have_title("Rails Development | Contact")

end



it "should have 'h1'" do

visit '/static_pages/contact'

expect(page).to has_selector?('h1')

end

为什么第一个测试正常,但第二个测试却出现 NoMethodError?

1)

Static Pages Contact page should have 'h1'

Failure/Error:expect(page).to has_selector?('h1')

NoMethodError:

undefined method `matches?' for true:TrueClass

最佳答案

RSpec 方法 to 需要一个 RSpec Matcher,但您已经将 has_selector 的结果传递给它,如果成功,它是true,从而导致您收到错误。

capybara 方法 has_selector? 旨在由 RSpec 匹配器 have_selector 隐式使用,如下所示:

expect(page).to have_selector('h1')

参见 https://github.com/jnicklas/capybara#querying获取更多信息。

关于testing - NoMethodError 对 rspec 使用 has_selector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22134756/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com