Compare string with regex in rspec?

I was doing

expect(@link.url_address == 'abc').to be_true 

but url_address may have different text after abc , so I'm trying

 expect(@link.url_address =~ 'abc').to be_true 

but i get

 Failure/Error: expect(@link.url_address =~ /abc/).to be_true expected to respond to `true?` 

I also tried

 expect(@link.url_address).to =~ /abc/ 

but i get

  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`. 
+8
source share
1 answer

Try the following:

 expect(@link.url_address).to match(/abc/) 

Source: https://github.com/rspec/rspec-expectations#regular-expressions

+17
source

Source: https://habr.com/ru/post/1200626/


All Articles