Method seems to work ok but the test fails - why?

Hi,

I’ve never used hpricot, so I thought I’d give this a try in irb. If I do

doc = Hpricot(open(“www.google.co.uk”))

I get an error: “No such file or directory - www.google.co.uk

However, if I prepend “http://” to the url

doc = Hpricot(open(“http://www.google.co.uk”))

it works. So, give that a try and let everyone know if that works.

I’d also like to offer this idea re: your Article constructor: it does too much. Fetching the title of a web page has nothing to do with an Article. Rather, an Article constructor should simply ensure that it is given a non-nil title, i.e., Article validates the presence of its title. Therefore, consider extracting a class whose purpose it is to build Articles, and give it the responsibility of using a given title or fetching one from the url to build an Article. Doing so will allow you to test Article in isolation from fetching a title from a url, resulting in shorter, more focused tests. Furthermore, separating these concerns will move your classes closer to having a single responsibility [http://en.wikipedia.org/wiki/Single_responsibility_principle
], a design for which to strive.

Regards,
Craig

Craig Demyanovich wrote:

Hi,

doc = Hpricot(open(“www.google.co.uk”))

I get an error: “No such file or directory -
www.google.co.uk

However, if I prepend “http://” to the url

doc = Hpricot(open(“http://www.google.co.uk”))

it works. So, give that a try and let everyone know if that works.

Thanks craig - i spotted that as a potential problem and fixed it but
the test still fails in the same way.

If you can make your project available via anonymous checkout or some kind of download, I and/or someone else could try it and maybe offer a solution. Barring that, post as much code as you can, say your whole test and your whole Article class.

Rather, an Article constructor should simply ensure that it is given a

non-nil title, i.e., Article validates the presence of its title.

I’m not very happy with my constructors generally. Ideally i’d like to
do more research and then rewrite my app according to cleaner

principles. I just dove in and started doing stuff, learning as i went
along. I have learnt a lot, but i know now that most of my code is
pretty clunky. (i’m a newcomer to programming and rails in particular).

Thanks for the advice :slight_smile:

Doing is one of the best ways to learn, and you have a great community willing to help when you get stuck. :slight_smile: