[rspec-users] should contain vs. =~

Brennon Bortz brennon at brennonbortz.com
Mon Sep 6 10:20:44 EDT 2010


On 6 Sep 2010, at 14:55, David Chelimsky wrote:

> On Sep 6, 2010, at 8:15 AM, Brennon Bortz wrote:
> 
>> I'm developing another view test.  Relevant example:
>> 
>> it "should show the item's url" do
>>       rendered.should contain("http://www.example.com")
>> end
>> 
>> I'm calling render in a before block.  I have other similar examples on the page in which I'm simply using:
>> 
>> rendered.should =~ "..."
>> 
>> These all work fine, as does the first example I posted here.  However, when trying to express that first example with a regex (which I prefer), the example fails:
>> 
>> it "should show the item's url" do
>>       rendered.should =~ /http:\/\/www.example.com/
>> end
>> 
>> Am I missing something?


Failures:
  1) widgets/show.html.erb widget details should show the widget's url
     Failure/Error: rendered.should =~ /http:\/\/www.example.com/
     expected: /http:\/\/www.example.com/,
          got: "http://www.example.com" (using =~)

I realise this is because of the escaped HTML output, but I'm not quite sure what to do about it...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100906/c9eebf91/attachment.html>


More information about the rspec-users mailing list