2016-01-29 4 views
0

Когда я бегу $ bundle exec rake test я получаю следующие сбои:Учебник Rails Майкл Hartl - Глава 5.3

$ bundle exec rake test 
/home/ubuntu/workspace/sample_app/db/schema.rb doesn't exist yet. Run `rake db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter /home/ubuntu/workspace/sample_app/config/application.rb to limit the frameworks that will be loaded. 
Run options: --seed 7295 

# Running: 

FF.F 

Finished in 0.664525s, 6.0193 runs/s, 12.0387 assertions/s. 

    1) Failure: 
StaticPagesControllerTest#test_should_get_contact [/home/ubuntu/workspace/sample_app/test/controllers/static_pages_controller_test.rb:25]: 
<Contact | Ruby on Rails Tutorial Sample App> expected but was 
<Contact | Ruby on Rails Tutorial Sample App>.. 
Expected 0 to be >= 1. 


    2) Failure: 
StaticPagesControllerTest#test_should_get_about [/home/ubuntu/workspace/sample_app/test/controllers/static_pages_controller_test.rb:19]: 
<About | Ruby on Rails Tutorial Sample App> expected but was 
<Ruby on Rails Tutorial Sample App>.. 
Expected 0 to be >= 1. 


    3) Failure: 
StaticPagesControllerTest#test_should_get_help [/home/ubuntu/workspace/sample_app/test/controllers/static_pages_controller_test.rb:13]: 
<Help | Ruby on Rails Tutorial Sample App> expected but was 
<Ruby on Rails Tutorial Sample App>.. 
Expected 0 to be >= 1. 

4 runs, 8 assertions, 3 failures, 0 errors, 0 skips 

Мои /static_pages_controller_test.rb является:

require 'test_helper' 

class StaticPagesControllerTest < ActionController::TestCase 
    test "should get home" do 
    get :home 
    assert_response :success 
    assert_select "title", "Ruby on Rails Tutorial Sample App" 
    end 

    test "should get help" do 
    get :help 
    assert_response :success 
    assert_select "title", "Help | Ruby on Rails Tutorial Sample App" 
    end 

    test "should get about" do 
    get :about 
    assert_response :success 
    assert_select "title", "About | Ruby on Rails Tutorial Sample App" 
    end 

    test "should get contact" do 
    get :contact 
    assert_response :success 
    assert_select "title", "Contact | Ruby on Rails Tutorial Sample App" 
    end 

end 

мой routes.rb является:

Rails.application.routes.draw do 
    root 'static_pages#home' 

    get 'static_pages/help' 

    get 'static_pages/about' 

    get 'static_pages/contact' 
end 

Все работает нормально, хотя, я думаю. Я получаю каждую ссылку, которую я нажимаю, но мои тесты терпят неудачу. Кто-нибудь знает, почему?

+0

Я получаю все, как static_pages/помощь static_pages/о и т.д., но Безразлично» t пройти тест. – clair13

ответ

0

Убедитесь, что точно не заполнены следующие файлы.

application_helper.rb:

module ApplicationHelper 

    # Returns the full title on a per-page basis. 
    def full_title(page_title = '') 
    base_title = "Ruby on Rails Tutorial Sample App" 
    if page_title.empty? 
     base_title 
    else 
     page_title + " | " + base_title 
    end 
    end 
end 

contact.html.erb:

<% provide(:title, 'Contact') %> 
<h1>Contact</h1> 
<p> 
    Contact the Ruby on Rails Tutorial about the sample app at the 
    <a href="http://www.railstutorial.org/#contact">contact page</a>. 
</p> 

about.html.erb:

<% provide(:title, "About") %> 
<h1>About</h1> 
<p> 
    The <a href="http://www.railstutorial.org/"><em>Ruby on Rails 
    Tutorial</em></a> is a 
    <a href="http://www.railstutorial.org/book">book</a> and 
    <a href="http://screencasts.railstutorial.org/">screencast series</a> 
    to teach web development with 
    <a href="http://rubyonrails.org/">Ruby on Rails</a>. 
    This is the sample application for the tutorial. 
</p> 

help.html.erb:

<% provide(:title, "Help") %> 
<h1>Help</h1> 
<p> 
    Get help on the Ruby on Rails Tutorial at the 
    <a href="http://www.railstutorial.org/#help">Rails Tutorial help section</a>. 
    To get help on this sample app, see the 
    <a href="http://www.railstutorial.org/book"><em>Ruby on Rails Tutorial</em> 
    book</a>. 
</p> 

Затем, чтобы исправить первую ошибку (как также предложено @ 0r4cl3) в командной строке: rake db:migrate.

Если все описанные выше шаги до сих пор не исправить все ошибки, проверьте следующий файл:

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 %> 
    <%= render 'layouts/shim' %> 
    </head> 
    <body> 
    <%= render 'layouts/header' %> 
    <div class="container"> 
     <% flash.each do |message_type, message| %> 
     <div class="alert alert-<%= message_type %>"><%= message %></div> 
     <% end %>  
     <%= yield %> 
     <%= render 'layouts/footer' %> 
     <%= debug(params) if Rails.env.development? %> 
    </div> 
    </body> 
</html> 
+0

Спасибо за ваше время. Я нашел решение в пространстве на module.between "# {page_title} | # {base_title}". Проблема решена. – clair13

0

В первой строке указывается, что вам нужно сначала построить схему. Попробуйте работать rake db:migrate