문제

Rails 앱에서 기능 테스트를 작성하려고 노력하고 있으며 Application_Controller.rb에 다음과 같습니다.

before_filter :current_account
def current_account
  @current_account ||= Account.find_by_subdomain!(request.subdomians.first)
end

테스트를 실행할 때 request.subdomains 내가 찾고있는 유효한 하위 도메인이 포함되어 있지 않으며 기능 테스트를 실행할 수 없습니다.

스텁 할 수 있습니까? current_account 방법 또는 조롱 request.subdomains 물체?

도움이 되었습니까?

해결책

기능 테스트에서 (Mocha 사용) 할 수 있어야합니다.

@request.expects(:subdomains).returns(['www'])

다른 팁

나에게 (그리고 Rails 2.3.4), 올바른 진술은

@controller.request.expects(:subdomains).returns(['www'])

@request에 직접 액세스 할 수 없으므로

@controller.instance_variable_set(:@request, OpenStruct.new({:subdomains => 'www'}))

당신은 루비에서 무엇이든 액세스 할 수 있습니다 :)

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