【发布时间】:2013-01-27 01:02:21
【问题描述】:
我正在尝试在 Michael Hartl 的 RailsTutorial.org 的第 8 章中做练习 2。我在 spec/support/utilities.rb 文件中添加了以下内容:
RSpec::Matchers.define :have_title do |message|
match do |page|
page.should have_selector('title', text: message)
end
end
在我的 authentication_pages_spec.rb 文件中,我已更改
it { should have_selector('title', text: 'Sign in') }
到
it { should have_title('Sign in') }
我希望这可以正常工作,但在运行测试时我收到以下错误消息:
使用无效信息的身份验证登录 失败/错误:它 { should have_title('Sign in') } 无方法错误: '
中未定义的方法has_title?' for #<Capybara::Session>
# ./spec/requests/authentication_pages_spec.rb:22:inblock(4 级)
当我相信我写的方法正确时,我不明白为什么它抱怨没有方法。
【问题讨论】:
标签: rspec nomethoderror matcher