I’m having some trouble trying to spec some methods in my Rails
application controller.
I’m new to rspec converting over from straight test::unit.
Here is the method in my application.rb controller that I’m trying to
spec
def render_403
logger.debug “Returned 403: #{request.request_uri}”
render :file => “#{RAILS_ROOT}/public/403.html”, :status => ‘403’
end
Here is my current spec
describe “handling render 403” do
before(:each) do
controller.request.should_receive(:request_uri).and_return(‘response
request_uri’)
end
it "should render the 403 error page" do
controller.render_403
response.should render_file("#{RAILS_ROOT}/public/403.html")
end
it "should send a message to logger" do
@log_stream = StringIO.new
controller.stub!(:logger).and_return(Logger.new(@log_stream))
controller.render_403
@log_stream.string.should match(/Returned 403:/)
end
end
Both specifications fail with the following error:
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.template
/app/controllers/application.rb:25 :in `render_403’
/spec/controllers/application_controller_spec.rb:34
The errors is being raised on the render :file line of the render_403
method and I have no idea what it is referring too. If I comment out
that line, then my logger spec test passes fine but I need to
obviously test that the render happens and I can’t figure out this
error and google has provided no help.