2013-10-30 42 views
0

通过哈特尔的Rails的教程和章5.4.2去,我不能够得到一定的测试通过。哈特尔第5章的问题

以下是错误:

1) UserPages GET /user_pages works! (now write some real specs) 
    Failure/Error: get user_pages_index_path 
    NameError: 
     undefined local variable or method `user_pages_index_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f9106e2cce8> 
    # ./spec/requests/user_pages_spec.rb:7:in `block (3 levels) in <top (required)>' 

这里是user_pages_spec.rb测试:

require 'spec_helper' 

    describe "UserPages" do 
     describe "GET /user_pages" do 
     it "works! (now write some real specs)" do 
      # Run the generator again with the 
      # --webrat flag if you want to use webrat methods/matchers 

      get user_pages_index_path 
      response.status.should be(200) 
     end 
     end 
    end 

这里是路线文件:

get "users/new" 
root 'static_pages#home' 
match '/signup', to: 'users#new',   via: 'get' 
match '/help', to: 'static_pages#help', via: 'get' 
match '/about', to: 'static_pages#about', via: 'get' 
match '/contact', to: 'static_pages#contact', via: 'get' 
match 'static_pages/home', to: 'static_pages#home', via: 'get' 

任何输入被理解


对不起格式。在这一节一开始是一个规范文件:规格/请求/ user_pages_spec.rb

require 'spec_helper' 

describe "User pages" do 

    subject { page } 

    describe "signup page" do 
    before { visit signup_path } 

    it { should have_content('Sign up') } 
    it { should have_title(full_title('Sign up')) } 
    end 
end 

,我收到以下错误:

故障/错误:让user_pages_index_path NameError:未定义的局部变量或方法用于`#

这里user_pages_index_path”是耙路线输出:

 Prefix Verb URI Pattern     Controller#Action 
    users_new GET /users/new(.:format)   users#new 
     root GET/       static_pages#home 
     signup GET /signup(.:format)   users#new 
     help GET /help(.:format)    static_pages#help 
     about GET /about(.:format)    static_pages#about 
     contact GET /contact(.:format)   static_pages#contact 

static_pages_homeģ ET /static_pages/home(.:format)static_pages#家

+0

我不明白。 M. Hartl教程的5.4.2注册URL中的测试有所不同。你想做什么?你也可以在你的问题中格式化代码。很难这样读。 –

+0

格式化抱歉。在该部分的最开始部分是spec文件:spec/requests/user_pages_spec.rb – user2623706

+0

请在您的终端中运行'rake routes'。什么是输出? –

回答

0

就在 “user_pages_spec.rb” 删除内容 原因没有叫user_pages_index_path

所以这样的方法,这里是什么应该

user_pages_spec.rb

require 'spec_helper' 

describe "User pages" do 

    subject { page } 

    describe "signup page" do 
    before { visit signup_path } 

    it { should have_content('Sign up') } 
    it { should have_title(full_title('Sign up')) } 
    end 
end 

而且在/config/routes.rb文件

SampleApp::Application.routes.draw do 
    get "users/new" 

    root 'static_pages#home' 
    match '/signup', to: 'users#new',   via: 'get' 
    match '/help', to: 'static_pages#help', via: 'get' 
    match '/about', to: 'static_pages#about', via: 'get' 
    match '/contact', to: 'static_pages#contact', via: 'get' 
    . 
    . 
    . 
end 
0

我有同样的问题,我只是注释掉“user_pages_spec.rb”文件。当我这样做时,我通过了所有的测试。这是正确的答案,我不知道,但正如我所说,它允许测试通过。

相关问题