2017-05-04 2 views
0

현재 rspec을 사용하여 통합 테스트를 작성 중입니다. 나는에 문제가있는 시험은 상당히 symple입니다 :테스트 환경에서 깜박임이 표시되지 않음

문제는 개발하는 알았어 플래시 메시지입니다

require 'rails_helper' 

feature 'Accounts' do 
    scenario 'creating an account' do 
    visit root_path 
    click_link 'Get Started' 
    fill_in 'Name', with: 'Test' 
    click_button 'Create account' 
    save_and_open_page 
    success_message = 'Your account has been successfully created' 
    expect(page).to have_content(success_message) 
    end 
end 

sign_up_spec.rb

def create 
    @account = Account.new(account_params) 
    authorize @account 
if @account.save 
    flash[:notice] = 'Your account has been successfully created' 
    redirect_to :root 
else 
    render :new 
end 

accounts_controller.rb 성공적인 계정 생성 이 나타나지만 테스트 스위트를 시작하면 rspec에서 오류가 발생합니다. 성공 메시지를 발견하고 참으로 save_and_open_page 사용 후, 아무것도

Started POST "/accounts" for 127.0.0.1 at 2017-05-04 18:27:20 +0200 
Processing by AccountsController#create as HTML 
    Parameters: {"utf8"=>"✓", "account"=>{"name"=>"Test"}, "commit"=>"Create  account"} 
    [1m[36m (0.1ms)[0m [1mSAVEPOINT active_record_1[0m 
    [1m[35mSQL (0.3ms)[0m INSERT INTO "accounts" ("name", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["name", "Test"], ["created_at", "2017-05-04 16:27:20.224700"], ["updated_at", "2017-05-04 16:27:20.224700"]] 
    [1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m 
Redirected to http://localhost/ 
Completed 302 Found in 6ms (ActiveRecord: 0.7ms) 
Started GET "/" for 127.0.0.1 at 2017-05-04 18:27:20 +0200 
Processing by PagesController#home as HTML 
    Rendered pages/home.html.erb within layouts/home (5.0ms) 
    Rendered shared/_navbar_home.html.erb (1.1ms) 
    Rendered shared/_flashes.html.erb (0.1ms) 
    Rendered shared/_footer.html.erb (0.6ms) 
Completed 200 OK in 10ms (Views: 9.4ms | ActiveRecord: 0.0ms) 
+0

실패한 테스트에 대한 test.log 출력을 질문에 추가하십시오. –

+0

로그와 함께 내 질문을 편집했습니다. – Viro

+0

로그에 루트로 리다이렉트되어 있으므로 계정 생성이 성공적 일 수 있습니다. 플래시가 실제로 표시되는 방법 (페이지에 JS가 나타나야합니까?) –

답변

1

추측이 초기 visit root_path이 'WWW의 rack_test 드라이버 default_host를 사용하고 있다는 점이다

테스트 로그 ... 화면에 나타납니다. example.com '. 즉, 세션 쿠키 (플래시 포함)가 'example.com'으로 설정되어 있으므로 도메인이 일치하지 않아 앱이 http://localhost으로 리디렉션 될 때 함께 전송되지 않습니다. 한 가지 해결책은 redirect_to :root (대상을 결정하기 위해 url_for(:root)을 호출하는 것으로 끝남)에서 redirect_to root_path으로 변경하는 것입니다. 그러면 리디렉션 할 때 현재 호스트 이름 만 사용됩니다.

+0

그게 다야! 실제로 오류가 거기에서오고 있다고 확신 할 때 실제로 default_host 매개 변수를 찾고있었습니다. 이제는 매력처럼 작동합니다. 다시 한 번 감사드립니다. – Viro

관련 문제