user2014905 user2014905 - 1 year ago 138
Ruby Question

Rspec forward and back slash

I saw this line of code in betterspecs.

it { expect(assigns('message')).to match /it was born in Belville/ }

What does the slashes before 'it' and after 'Belville' mean?

Answer Source

The slashes indicate a Regexp-literal definition. It holds a regular expression, that can be matched againts other strings.

The example checks that the assigned instance variable message matches the regex it was born in Belville. In this scenario, it essentially just checks that message contains it was born in Belville. Regexes can get much more complicated than this, though.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download