이상한 문제가 있습니다. 로컬 레일 앱을 시작하고 http://localhost:3000/static_pages/help으로 이동하면 내가 만든 페이지를 볼 수 있습니다. 그러나 필자가 작성한 테스트 케이스는 다르게 말한다.루비 레일 테스트 케이스가 실패했지만 실제 앱이 작동합니다.
static_pages_controller_test.rb 그것은이 오류와 함께 실패
require 'test_helper'
class StaticPagesControllerTest < ActionController::TestCase
test "should get home" do
get :home
assert_response :success
end
test "should get help" do
puts static_pages_help_url
puts static_pages_help_path
get static_pages_help_url
assert_response :success
end
end
, $ 빈의 출력/레이크 시험 : 여기
Running:
..http://test.host/static_pages/help
/static_pages/help
E
Finished in 0.466745s, 8.5700 runs/s, 4.2850 assertions/s.
1) Error.
StaticPagesControllerTest#test_should_get_help:
ActionController::UrlGenerationError: No route matches {:action=>"http://test.host/static_pages/help", :controller=>"static_pages"}
test/controllers/static_pages_controller_test.rb:12:in `block in <class:StaticPagesControllerTest>'
는 routes.rb
Rails.application.routes.draw do
get 'static_pages/home'
get "static_pages/help"
end
입니다
여기에 있습니다. 브라우저에서/static_pages/도움말을 탐색 할 때 나는 또한 그들을 볼 수 있습니다로 static_pages_controller.rb
class StaticPagesController < ApplicationController
def home
end
def help
end
end
이 두 파일
app/views/static_pages/home.html.erb
app/views/static_pages/help.html.erb
가 존재한다. 나는 몇 시간 동안 웹을 검색했다. 단서가 없다.
$ rails --version
Rails 4.2.7.1
$ ruby --version
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
나는 뭔가를 놓쳐 야합니다. 도와주세요.
빠른 답변 주셔서 감사합니다. 완전히 나를 괴롭히는 이유는 다음과 같습니다.이 페이지의 저자는 왜 https://www.railstutorial.org/book/static_pages#code-default_controller_test 그의 테스트를 작성합니까? 사실 그것은 작동하지 않는 동안! 그것은 시간이 걸렸습니다 ... – CodeKid
@ 코드 키, 하트를 과소 평가하지 마십시오. 그는 그의 물건을 알고있다. 문제는 Hartl이 제시 한 예제 코드를 보면, 실제로 '통합 테스트'이고, 수행하려는 것은 '컨트롤러 스펙'이다. Hartl의 코드와 당신의 클래스 서명을 보라. 당신의 StaticPagesControllerTest는'ActionController :: TestCase'로부터 상속 받고 그의 구현은'ActionDispatch :: IntegrationTest'에서 상속받습니다. 간단히 말하면, Hartl의 코드는 url을 방문하여 응답이 성공인지 확인하려고 시도합니다. 그러나 컨트롤러 사양은 다릅니다. –
이것은 내가 실제로 알고 싶어하는 것에 대한 대답입니다. 이제는 모두 확실합니다. 정말 고맙습니다. – CodeKid