我在做
expect(@link.url_address == 'abc').to be_true
但url_address可能在abc之后有其他文本,所以我正在尝试
expect(@link.url_address =~ 'abc').to be_true
但我得到了
Failure/Error: expect(@link.url_address =~ /abc/).to be_true expected to respond to `true?`
我也试过了
expect(@link.url_address).to =~ /abc/
但我明白了
Failure/Error: expect(@link.url_address).to =~ /abc/ ArgumentError: The expect Syntax does not support operator matchers,so you must pass a matcher to `#to`.
解决方法
试试这个:
expect(@link.url_address).to match(/abc/)
资料来源:https://github.com/rspec/rspec-expectations#regular-expressions