[rspec-users] Testing lib code

Peter Jaros peter.a.jaros at gmail.com
Tue Dec 30 14:02:56 EST 2008


On Tue, Dec 30, 2008 at 12:50 PM, s.ross <cwdinfo at gmail.com> wrote:

> This question has, I'm sure, been asked and answered hundreds of times, but
> I was unable to turn up anything in Google. Here's the issue: I have some
> code in a Rails app in the lib/ directory that affects how views are
> rendered. Specifically, it checks CSS and Javascript files for existence and
> some application-specific stuff, then injects them into the right part of
> the HTML that's rendered.

To be honest, this smells funny to me.  Why is something in lib/
affecting how views are rendered?

Or does it need to be called or "activated" by something in the
controller layer to take effect?  That would make sense, but it would
be a bit tricky to spec.  I'm not sure there's enough information here
about how it functions to give a good suggestion.

Try being more specific (with us and with yourself) in describing the
behavior of the objects which do this injection.  That might lead to
you to a way to test that behavior.  Poor specs, as well as difficulty
in writing specs, are often the result of not clearly defining what
you want the behavior of the object to be.

Free your mind, and the rest will follow.

Peter


More information about the rspec-users mailing list