gpt4 book ai didi

ruby-on-rails - 将字符串与 rspec 中的正则表达式进行比较?

转载 作者:数据小太阳 更新时间:2023-10-29 06:51:48 25 4
gpt4 key购买 nike

我在做

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

关于ruby-on-rails - 将字符串与 rspec 中的正则表达式进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25372445/

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