2014-01-08 2 views
0

나는 도움이되는 뱀파이어가되고 싶지 않지만 나는 새롭다. 나는 거의 이틀을 지켜 보았다.RSpec 스펙이 실패하고 알아낼 수 없다.

저는 Michael Hartl이 만든 Ruby on Rails 튜토리얼을 작성하고 있습니다. 아래 목록에있는 테스트를 실행하고 있습니다. 내가 전달하려고하는 특정 테스트는 페이지에 "Ruby on Rails Tutorial Sample App"텍스트가있는 선택기가 있는지 확인합니다. 나는이 문제에 대한 해결책을 SO에 묻는 과정에서이 문제에 대한 해결책을 찾아 낼 것이다. 그러나 여기에 우리가 간다.

/spec/requests/static_pages_spec.rb

require 'spec_helper' 

describe "StaticPages" do 

    describe "Home page" do 

    it "should have the h1 'Sample App'" do 
     visit '/static_pages/home' 
     page.should have_selector('h1', :text => 'Sample App') 
    end 

    it "should have the base title" do 
     visit '/static_pages/home' 
     page.should have_selector('title', :text => "Ruby on Rails Tutorial Sample App") 
    end 

    it "should not have a custom page title" do 
     visit '/static_pages/home' 
     page.should_not have_selector('title', :text => '| Home') 
    end 

    end 
    ...[other tests for other pages, let me know if you think they're necessary] 

end 

응용 프로그램/헬퍼/application_helper.rb

module ApplicationHelper 
    # It is a good idea to put controller specific helpers in their 
    # related helper file (e.g., helpers specifically for the 
    # StaticPages controller). 

    # Returns the full title on a per-page basis: 
    # This helper will be used for each page's title (unless 
    # otherwise noted). 
    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 

end 

응용 프로그램 : 아래는 내가 관련 파일, 무엇을 믿는입니다 /views/layouts/application.html.erb

<!DOCTYPE html> 
<html> 
<head> 
    <title><%= full_title(yield(:title))%></title> 
    <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> 
    <%= javascript_include_tag "application", "data-turbolinks-track" => true %> 
    <%= csrf_meta_tags %> 
</head> 
<body> 

<%= yield %> 

</body> 
</html> 

나는 아직 콘솔에서 RSpec에 실행 라임을 구성하지 않은

<% provide :title, "Home" %> 
<h1>Sample App</h1> 
<p> 
    This is the home page for a 
    <a href="http://railstutorial.org/">Ruby on Rails</a> tutorial. 
</p> 
<p> 
    It's by <a href="https://github.com/mhartl">Michael Hartl</a> 
</p> 

응용 프로그램/뷰/static_pages/home.html.erb. | 내가 크롬의 소스 코드를 볼 때, 나는 분명히 레일 튜토리얼 샘플 응용 프로그램에 루비 "로 태그 한 쌍을 볼 수 있습니다

.......F. 

Failures: 

    1) StaticPages Home page should have the base title 
    Failure/Error: page.should have_selector('title', :text => "Ruby on Rails Tutorial Sample App") 
     expected #has_selector?("title", {:text=>"Ruby on Rails Tutorial Sample App"}) to return true, got false 
    # ./spec/requests/static_pages_spec.rb:14:in `block (3 levels) in <top (required)>' 

Finished in 0.14273 seconds 
9 examples, 1 failure 

Failed examples: 

rspec ./spec/requests/static_pages_spec.rb:12 # StaticPages Home page should have the base title 

Randomized with seed ##### 

: 나는 떠들썩한 파티에서 터미널에서 테스트를 실행하면, 다음과 같은 수 그 (것)들의 사이에서 "가정".

글쎄, 나는 그걸 전부 다 통과했는데 무슨 일이 일어나는지 알 수 없다. 안녕, 세상! 도와주세요. 고맙습니다.

나는 지금 github에 밀고 하겠지만, 내려갔습니다. 가능하면 업데이트하겠습니다.

+0

'have_selector ('title', : text => 'Ruby on Rails Tutorial App App | Home') 텍스트가 == 인 것으로 가정하면, – Doon

+0

@doon 나는 그것이 나쁜 가정이라고 생각한다. –

+0

[제목 테스트는 레일 스 3에 대한 Michael Hartls 튜토리얼의 요청 사양에 실패했습니다.] (http://stackoverflow.com/questions/13479601/title-test-failing-for-request-specs-in-michael-hartls- 튜토리얼 -for-rails-3) –

답변

1

변화

have_selector('title', :text => "Ruby on Rails Tutorial Sample App") 

have_title("Ruby on Rails Tutorial Sample App | Home") 

에 그것은 Capybara을 변경 그리고 마이클 하틀의 tutorial에 업데이트되었습니다. 튜토리얼에서 "have_selector ('title', ...) to have_title (...)"변경 사항에 대한 업데이트 검색을 확인하십시오.

관련 문제