我在做
expect(@link.url_address == 'abc').to be_true
但是在abc
之后url_address可能有其他文本,所以我正在尝试
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