1
저는 rspec을 통해 수천 가지 테스트를 거쳐 커다란 응용 프로그램을 사용하고 있습니다.i18n 리디렉션으로 내 테스트가 깨졌습니다.
/
/foo
/foo/4/bar/34
...
TO :
if params[:locale].blank?
headers["Status"] = "301 Moved Permanently"
redirect_to request.env['REQUEST_URI'].sub!(%r(^(http.?://[^/]*)?(.*))) { "#{$1}/#{I18n.locale}#{$2}" }
end
:
/en
/en/foo
/fr/foo/4/bar/34
....
그래서 내가 이렇게 같은 application.rb에서 필터 이전했다
우리는 같은 모든 페이지를 리디렉션 할 선택을
잘 작동하지만 ... 내 검사가 많이 끊어졌습니다. 예 :
심각하게 나는에 노력 하나 하나 ...내 모든 테스트를 수정하지 않으려는
get :last_failed_encoding, :locale => "en"
하지만를 ... :
it "should return 404" do
Video.should_receive(:failed_encodings).and_return([])
get :last_failed_encoding
response.status.should == "404 Not Found"
end
이 테스트를 해결하려면 어떻게해야 로케일이 같은 기본 매개 변수합니다
class ActionController::TestCase
alias_method(:old_get, :get) unless method_defined?(:old_get)
def get(path, parameters = {}, headers = nil)
parameters.merge({:locale => "fr"}) if parameters[:locale].blank?
old_get(path, parameters, headers)
end
end
...하지만이 작품 ... 어떤 생각을 couldnt는?
끝까지 읽을 때 더 이상 문제가 아니며 이미 로케일 문제를 해결했습니다. 내 문제는 이제 내 테스트에 있습니다. – Mike