[rspec-users] Is it bad to use a shared example in rspec_helper.rb?

Daniel N has.sox at gmail.com
Mon Jul 9 09:55:09 EDT 2007


I want to extract the method for logging in so that I don't have to include
it in each before call.

Is it bad to use a describe block within the rspec_helper in a rails project
for controller tests?

I have in my spec_helper.rb

describe "an authenticated request", :shared => true do
  before( :each ) do
    @u = mock_model( User )
    mock_login( @u )
  end

  def mock_login( user )
    session[:user] = user
    controller.send( :instance_variable_set, :@current_user, user )
    controller.stub!( :current_user ).and_return( user )
  end

end


which I then share in my relevant controller tests with

  it_should_behave_like "an authenticated request"

Is this bad?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070709/d74c003f/attachment-0001.html 


More information about the rspec-users mailing list