2010-04-02 9 views
3

설명서를 읽지도 아래 오류가 발생합니다. 내 기능 테스트 에서 Authlogic 및 기능 테스트 - Authlogic :: Session :: Activation :: NotActivatedError : 활성화해야합니다.

ENV["RAILS_ENV"] = "test" 
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") 
require "authlogic/test_case" 
require 'test_help' 
require 'shoulda' 
require File.dirname(__FILE__) + "/factories" 

test_helper.rb

에서

는 environments.rb

config.gem "authlogic" 

임은 일 밤은 왜 확실하지에 'test_helper을'

class SentencesControllerTest < ActionController::TestCase 
    setup do 
    :activate_authlogic 
    end 

    context "logged in" do 
    setup do 
     @user = Factory(:user) 
     UserSession.create(@user.id) 
    end 

    context "on GET to :new" do 
     setup do 
     get :new 
     end 

     should "present form with text field" do 
     assert_select('form#new_sentence') do 
      assert_select('textarea#sentence_text') 
     end 
     end 
    end 
    end #context logged in. 
end 

이 필요합니다. 아무도 이것에 도울 수 있습니까?

Authlogic::Session::Activation::NotActivatedError: You must activate the Authlogic::Session::Base.controller with a controller object before creating objects 
authlogic (2.1.3) lib/authlogic/session/activation.rb:47:in `initialize' 
    authlogic (2.1.3) lib/authlogic/session/klass.rb:64:in `initialize' 
    authlogic (2.1.3) lib/authlogic/session/scopes.rb:79:in `initialize' 
    authlogic (2.1.3) lib/authlogic/session/existence.rb:29:in `new' 
    authlogic (2.1.3) lib/authlogic/session/existence.rb:29:in `create' 
    test/functional/sentences_controller_test.rb:11:in `__bind_1270172858_922804' 
    shoulda (2.10.3) lib/shoulda/context.rb:380:in `call' 
    shoulda (2.10.3) lib/shoulda/context.rb:380:in `run_current_setup_blocks' 
    shoulda (2.10.3) lib/shoulda/context.rb:379:in `each' 
    shoulda (2.10.3) lib/shoulda/context.rb:379:in `run_current_setup_blocks' 
    shoulda (2.10.3) lib/shoulda/context.rb:371:in `run_all_setup_blocks' 
    shoulda (2.10.3) lib/shoulda/context.rb:375:in `run_parent_setup_blocks' 
    shoulda (2.10.3) lib/shoulda/context.rb:359:in `test: logged in on GET to :new should present form with text field. ' 
    /opt/rubymine/rb/testing/patch/testunit/test/unit/ui/testrunnermediator.rb:36:in `run_suite' 
    /opt/rubymine/rb/testing/patch/testunit/test/unit/ui/teamcity/testrunner.rb:215:in `start_mediator' 
    /opt/rubymine/rb/testing/patch/testunit/test/unit/ui/teamcity/testrunner.rb:191:in `start' 

답변

9

수행해야합니다

class SentencesControllerTest < ActionController::TestCase 

    setup do 
    :activate_authlogic 
    end 

    ... 

가 될 :

을 :

class SentencesControllerTest < ActionController::TestCase 

    def setup    # setup should be its own method, prefixed with "def" 
    activate_authlogic # note the lack of a ":" 
    end 

    ... 

이 경우, 양자 택일로, 당신은 튜토리얼을 테스트 레일 다음있어,이 같은 한 줄의 설정 계약을 할 수 있습니다

setup :activate_authlogic # note the USE of a ":" here - not sure why it's different between this and when you put it in its own method but that might be the answer for you 
+0

잘 찾아 냈습니다. 매우 고마워요 – robodisco

+0

당신은 그것을 가지고 - 내 기쁨 – jefflunt

+0

OMG, 고마워! 나는 이것을 몇 시간 동안 고민해왔다. –