Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `setup' for main:Object while trying to run controller tests with authlogic

I am a little new to RSpec tests and i am trying to run some controller tests in my Rails 3 application using RSpec 2 and Authlogic 3 authentication.

Following the steps provided by Authlogic documentation (http://rdoc.info/github/binarylogic/authlogic/master/Authlogic/TestCase), i got the following codes in my files:

spec_helper.rb

require "authlogic/test_case" # include at the top of test_helper.rb  

events_controller_spec.rb

require 'spec_helper'  
setup :activate_authlogic  

Running the tests through rake spec SPEC='spec/controllers/eventos_controller_spec.rb' i got the following error:

events_controller_spec.rb:2: undefined method `setup' for main:Object (NoMethodError)

When i ran the tests before using authlogic i've got no problems.

I am using Ubuntu 11.04 and this configuration:

ruby - 1.8.7  
rails - 3.0.7  
authlogic - 3.0.2  
rspec-rails - 2.4.1  
factory_girl_rails - 1.0.1
like image 204
klidebharrow Avatar asked Nov 28 '25 06:11

klidebharrow


1 Answers

The setup method is undefined because it's a Test::Unit method. From the authlogic docs:

If you are using Test::Unit::TestCase, the standard testing library that comes with ruby, then you can skip this next part. If you are not, you need to include the Authlogic::TestCase into your testing suite.

To do the same thing with RSpec, you have to include Authlogic::TestCase and call activate_authlogic before each spec:

require 'spec_helper'

describe EventsController do
  include Authlogic::TestCase

  before(:each) do
    activate_authlogic
  end
end
like image 52
Tomas Mattia Avatar answered Nov 29 '25 23:11

Tomas Mattia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!