[rspec-users] Fixing "expected success? to return true, got false"

Mark A. Richman mark at markrichman.com
Tue Jan 6 20:25:09 EST 2009


I am trying to get the following test to pass, and get this error. Since I'm
only on day 4 of rspec, I'm sure I'm missing something simple. Any ideas?

## rake spec

'PatientsController GET 'new' should be successful' FAILED
expected success? to return true, got false
./spec/controllers/patients_controller_spec.rb:27:

## patients_controller_spec.rb

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe PatientsController do

  integrate_views
  fixtures :all

  before(:each) do
    @user  = mock_user
    @login_params = { :login => 'quentin', :password => 'monkey' }
    User.stub!(:authenticate).with(@login_params[:login],
@login_params[:password]).and_return(@user)
    @user.stub!(:enabled?).and_return(true)
    @user.stub!(:account_id).and_return(1)
    @user.stub!(:time_zone).and_return('Eastern Time (US & Canada)')
    @user.stub!(:role).and_return('Normal')
    controller_bypass_authentication(@user)
  end

  #Delete these examples and add some real ones
  it "should use PatientsController" do
    controller.should be_an_instance_of(PatientsController)
  end

  describe "GET 'new'" do
    it "should be successful" do
      get 'new'
      response.should be_success # this is the offending line 27
    end
  end
end

# Allows a spec to bypass auth for controllers that filter for logged_in user
def controller_bypass_authentication(user=nil)
  controller.stub!(:logged_in).and_return(true)
  controller.stub!(:authorized?).and_return(true)
  controller.stub!(:current_user).and_return(user)
end

## patients_controller.rb

...
def new
  @patient = Patient.new

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @patient }
  end
end
...

http://www.pastie.org/354313
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090106/431b335d/attachment.html>


More information about the rspec-users mailing list