Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare string to regex in rspec?

I was doing

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

but url_address might have other text after abc so I am trying

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

but I am getting

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`.
like image 505
Michael Durrant Avatar asked Aug 18 '14 21:08

Michael Durrant


1 Answers

Try this:

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

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

like image 83
Surya Avatar answered Sep 19 '22 20:09

Surya