作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这些是我的测试:
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')
关于testing - NoMethodError 对 rspec 使用 has_selector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22134756/
我有以下 rspec 测试: # spec/decorators/user_decorator_spec.rb require File.expand_path 'spec/spec_helpe
这些是我的测试: it "should have the title 'Contact'" do visit '/static_pages/contact' expect(page).to h
我是一名优秀的程序员,十分优秀!