[rspec-users] Controller Isolation

Dylan Egan dylanegan at gmail.com
Tue Nov 21 19:42:47 EST 2006


I have a project that I had running under rspec 0.6.x and recently upgraded
to 0.7.2.

I am trying to isolate my controllers from the database as I go through and
change all the specs to run under 0.7.2.

I am having a problem where I need to make the create! method return the
mocked object as well as raise RecordInvalid exception. Is this at all

I use the rescue statement in my controller methods and not @
object.new_record? or @object.valid? to check whether to redirect or render.

-- controller --

  def create
    @star = Star.create!(params[:star])
    redirect_to star_path(@star)
  rescue ActiveRecord::RecordInvalid
    render :action => 'new'

-- spec --
  @star = mock('star')
  Star.should_receive(:create!).with({ 'name' => nil }).and_return(@star)

I'm new to all the mocking/stubbing business so my head spins are turning
into headaches. :)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20061122/9c0bfc6f/attachment.html 

More information about the rspec-users mailing list