Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec - redirect_to a path matching a regexp

I have the following in Rspec

response.should redirect_to %r{\A/my_settings/mysub_path/}

I get the following error

NoMethodError: undefined method `model_name' for Regexp:Class

I just need to match a part of my path which contains my_settings/mysub_path. How is this achieved in rspec?

like image 297
chugh97 Avatar asked Dec 19 '13 11:12

chugh97


3 Answers

To check the redirect against a regex do a string match on the response.location, like so:

expect(response.location).to match('your_expected_location.com')
like image 77
superluminary Avatar answered Oct 04 '22 09:10

superluminary


redirect_to expects a string or an active record model.

if you want to match something, you can use response.location

like image 26
phoet Avatar answered Oct 04 '22 08:10

phoet


Here's another simple way to do it:

response.location.should =~ /whatever_you_want_to_match/
like image 22
nfriend21 Avatar answered Oct 04 '22 08:10

nfriend21