rspec 사용자 스토리/오이를 사용하여 OpenID_Authentication 플러그인을 사용할 때 RSPEC 사용자 스토리/오이로 로그인하는 방법

StackOverflow https://stackoverflow.com/questions/382473

문제

나는 오이 시나리오를 작성하려고 노력하고 있습니다. 이는 사용자가 로그인 해야하는 오이 시나리오를 작성하려고합니다. 일반적으로 매우 간단하지만 OpenID 인증 (인증 플러그인의 curtosy) 만 사용합니다. 그러나 Open_ID_Authentication 플러그인 내장을 파헤친 후 오이 내에서 어떻게이를 달성 할 수 있는지 잘 모르겠습니다.

도움이 되었습니까?

해결책

당신이 당신의 기능/support/env.rb에 이것을 배치하면 방법을 알아 냈습니다.

ActionController::Base.class_eval do
  private

  def begin_open_id_authentication(identity_url, options = {})
    yield OpenIdAuthentication::Result.new(:successful), identity_url, nil
  end 
end

그런 다음 적절한 단계에서 이와 같은 일을 할 수 있습니다.

Given /^I am logged in as "(.*)"$/ do |name|
  user = User.find_by_name(user)
  post '/session', :openid_url => user.identity_url
  # Some assertions just to make sure our hack in env.rb is still working
  response.should redirect_to('/')
  flash[:notice].should eql('Logged in successfully')
end

나는 오이 기능에 대한 Open ID Auth를 완전히 막고 있습니다. 로그인이 실패한 인스턴스가 필요한 경우 제공된 Identity_URL을 기반으로 할 수 있습니다.

다른 팁

응답을 스텁 할 수 있으려면 다음을 수행합니다.

기능/지원/도우미에서 : RB :

ActionController::Base.class_eval do

  private
    def fake_openid_response(identity_url)
      [OpenIdAuthentication::Result.new(:successful), identity_url, nil]
    end

    def begin_open_id_authentication(identity_url, options = {})
        yield fake_openid_response(identity_url)
    end 
end

응답을 별도의 메소드로 이동시킴으로써 필요한 경우 단계에서 응답을 스텁 할 수 있습니다. 예를 들어, A : 누락 된 응답을 원하고 컨트롤러 GOOGLELOGINCONTROLLER가 있으면 MOCHA를 사용하여 다음을 수행 할 수 있습니다.

GoogleLoginController.any_instance.stubs(:fake_openid_response)
    .returns([OpenIdAuthentication::Result.new(:missing), identity_url, nil])

보르트, Rails Skeleton 앱은 전체 RSPEC 테스트 세트를 가지고 있으며 OpenID 로그인을 지원하므로 살펴보고 그들이 무엇을하는지 확인할 수 있습니다.

Defusion의 답변은 다음과 같은 Identity_url을 정상화해야한다는 점을 제외하고는 작동합니다.

ActionController::Base.class_eval do

    private

        def begin_open_id_authentication(identity_url, options = {})
            yield OpenIdAuthentication::Result.new(:successful), self.normalize_identifier(identity_url), nil
        end 
end

감사

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top