0

通过 Hartl 的 Rails 教程和第 5.4.2 章,我无法通过某个测试。

这是错误:

 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'

任何输入表示赞赏


对不起格式。该部分的最开始是一个规范文件:spec/requests/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' for #

这是 rake 路由输出:

       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 GET /static_pages/home(.:format) static_pages#home

4

2 回答 2

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
于 2013-10-31T02:30:16.063 回答
0

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

于 2013-11-01T05:31:39.633 回答