[rspec-users] How do BOTH these examples pass?

Mikel Lindsaar raasdnil at gmail.com
Wed Oct 1 09:11:39 EDT 2008


On Wed, Oct 1, 2008 at 1:02 AM, Ashley Moran
<ashley.moran at patchspace.co.uk> wrote:

> RssReader when there is an HTTP error
> - should attempt to parse the RSS
> - should not attempt to parse the RSS
> - should fail gracefully

>From what I can see, your code error is not doing anything with the
caught exception:

    def rss
      rss_body =
        begin
          @uri.read
        rescue OpenURI::HTTPError => e
          nil
        end

      ::RSS::Parser.parse(rss_body, false)
    end

This starts reading the body, catches an error, evaluates nil, exits
the rescue block and then continues to do the Parser.parse.

Changing it to:

    def rss
      rss_body =
        begin
          @uri.read
          ::RSS::Parser.parse(rss_body, false)
        rescue OpenURI::HTTPError => e
          nil
        end
    end

Should pass your specs.

Mikel


-- 
http://lindsaar.net/
Rails, RSpec and Life blog....


More information about the rspec-users mailing list