Rails测试错误,同时学习Rails教程

时间:2019-02-11 01:13:51

标签: ruby-on-rails ruby-on-rails-5

我目前正在学习Rails教程。在Rails测试后,TDD,我有错误消息。还有更多消息,但首先我要调试这些消息。即使Rails测试无法正常运行,但到目前为止,应用程序本身仍可以正常运行。

我看了看这个示例代码。 https://github.com/yasslab/sample_apps

错误消息

 11) Error:
StaticPagesControllerTest#test_should_get_about:
NameError: undefined local variable or method `static_pages_about_url' for #<StaticPagesControllerTest:0x00000006f89228>
StaticPagesControllerTest#test_should_get_home:NameError: undefined local variable or method `static_pages_home_url' for #<StaticPagesControllerTest:0x00000006f964a0>
    test/controllers/static_pages_controller_test.rb:7:in `block in <class:StaticPagesControllerTest>' 13) Error:
StaticPagesControllerTest#test_should_get_contact:NameError: undefined local variable or method `static_pages_contact_url' for #<StaticPagesControllerTest:0x0000000623d600>
    test/controllers/static_pages_controller_test.rb:27:in `block in <class:StaticPagesControllerTest>' 14) Error:StaticPagesControllerTest#test_should_get_help:NameError: undefined local variable or method `static_pages_help_url' for #<StaticPagesControllerTest:0x00000006f9d6d8>    test/controllers/static_pages_controller_test.rb:13:in `block in <class:StaticPagesControllerTest>'

static_pages_controller.rb

class StaticPagesController < ApplicationController
  def home
  end

  def help
  end

  def about
  end

  def contact
  end
end

static_pages_controller_test.rb

class StaticPagesControllerTest < ActionController::TestCase


  test "should get home" do
    get static_pages_home_url
    assert_response :success
    assert_select "title", "Ruby on Rails Tutorial Sample App"
  end

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

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

  end


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

routes.rb

Rails.application.routes.draw do
  get 'sessions/new'

  root 'static_pages#home'
  get  '/help',    to: 'static_pages#help'
  get  '/about',   to: 'static_pages#about'
  get  '/contact', to: 'static_pages#contact'
  get  '/signup',  to: 'users#new'
  post '/signup', to: 'users#create'

  get '/login', to: 'sessions#new'
  post '/login', to: 'sessions#create'
  delete '/logout', to: 'sessions#destroy'
  resources :users
end

我想使这些错误成为断言。 你能帮我吗?

0 个答案:

没有答案