[rspec-users] client first, top down, outside in, etc with rails

Pat Maddox pergesu at gmail.com
Tue Jan 29 01:34:50 EST 2008

On Jan 28, 2008 3:24 PM, Jay Donnell <jaydonnell at yahoo.com> wrote:
> I guess I can use dummy methods in my models that simply return some canned result. Maybe even name it 'my_method_dummy' so I can easily track down the dummy methods. The stubbing syntax is so clean In rspec that I was hoping I could define a bunch of mocks in a single place, environment.rb maybe, and be able to easily glance to see what is still being mocked. We also have different people working on the views vs the models and would like for the views to progress separately from the models. We can do this by spec'ing the views in isolation but it would be nice to see the views integrated into a functioning page as well.

hrm...well if you want it all in one place, I'd stick it in some
mocked_methods.rb file and require that.  You can open the classes you
want there

User.class_eval do
  def full_name
    "Johnny Tsunami"

That way it's easy to see where they all are.  You really don't need
to introduce RSpec dependencies into your production code.  Just
define methods on the class you want, or use OpenStruct and return
canned values, or write your own simple stub class.  If I was doing
this a bunch (I never would, of course :) then I might write a macro
that defines these stubs for me and includes some diagnostic info,
like a logger.warn("*** dude this is a stubbed method ***") and maybe
the caller information as well.  Then I could just do

User.stub_method(:full_name, "Johnny Tsunami")

Going that route would let you collect info about how many times
they're called, blah blah blah.

Or you could just implement your code :)


More information about the rspec-users mailing list