2012-06-19 2 views
1

RoR 애플리케이션으로 테스트를하고 있습니다. 내 static_pages_spec.rb rspec 테스트의 이상한 동작

# encoding: utf-8 

require 'spec_helper' 

describe "Static pages" do 

    subject { page } 

    describe "Home page" do 
    before { visit root_path } 

    it { should have_selector('h1', text: 'Giripedia') } 
    it { should have_selector('title', text: full_title('')) } 
    it { should_not have_selector 'title', text: '| Home' } 
    end 

    describe "Help page" do 
    before { visit help_path } 

    it { should have_selector('h1', text: 'Yardım') } 
    it { should have_selector('title', text: full_title('Help')) } 
    end 

    describe "About page" do 
    before { visit about_path } 

    it { should have_selector('h1', text: 'Hakkımızda') } 
    it { should have_selector('title', text: full_title('About Us')) } 
    end 

    describe "Contact page" do 
    before { visit contact_path } 

    it { should have_selector('h1', text: 'İletişim') } 
    it { should have_selector('title', text: full_title('Contact')) } 
    end 
end 

내 사양/지원/utilites.rb 파일

def full_title(page_title) 
    base_title = "Ruby on Rails Tutorial Sample App" 
    if page_title.empty? 
    base_title 
    else 
    "#{base_title} | #{page_title}" 
    end 
end 

내가 base_title = "Giripedia 포럼"을 변경하는 경우에

. 테스트가 실패하고 오류가 발생합니다.

1) Static pages Home page 
    Failure/Error: it { should have_selector('title', text: full_title('')) } 
     expected css "title" with text "Giripedia forum" to return something 
    # ./spec/requests/static_pages_spec.rb:13:in `block (3 levels) in <top (required)>' 

    2) Static pages Help page 
    Failure/Error: it { should have_selector('title', text: full_title('Help')) } 
     expected css "title" with text "Giripedia forum | Help" to return something 
    # ./spec/requests/static_pages_spec.rb:21:in `block (3 levels) in <top (required)>' 

    3) Static pages About page 
    Failure/Error: it { should have_selector('title', text: full_title('About Us')) } 
     expected css "title" with text "Giripedia forum | About Us" to return something 
    # ./spec/requests/static_pages_spec.rb:28:in `block (3 levels) in <top (required)>' 

    4) Static pages Contact page 
    Failure/Error: it { should have_selector('title', text: full_title('Contact')) } 
     expected css "title" with text "Giripedia forum | Contact" to return something 
    # ./spec/requests/static_pages_spec.rb:35:in `block (3 levels) in <top (required)>' 

왜 테스트에서 base_title의 변경이 실패합니까?

+0

웹 페이지의 '제목'도 변경 했습니까? – sarnold

+0

제목이 변경되지 않았습니다. base_title 만 변경했습니다. 테스트를 위해 헬퍼 메소드를 사용합니다. – ytsejam

+0

내 실수를 발견 했으므로 실제 application_helper.rb를 변경하지 않았습니다. 스펙 파일 만 변경했습니다. 실수를보기까지 1 시간이 걸렸습니다. – ytsejam

답변

1

여기에서 실수를 발견 할 수있었습니다. 이것은 다른 사람들을 도울 것입니다.

사양 파일의 base_title 만 변경되었습니다. 하지만 테스트를 거친 app/helper에 속하는 base_title을 변경해야했습니다.

나는 테스트 로그를 잘 읽어야한다는 것을 알고있다.