我正在使用Rails 4.0.8。当我运行bundle exec rspec spec/
时,这是我从教程(http://www.railstutorial.org/book/filling_in_the_layout)得到的错误:
待定:StaticPagesHelper添加一些示例(或删除) /Users/Desktop/sample_app/spec/helpers/static_pages_helper_spec.rb #没有给出理由 #./spec/helpers/static_pages_helper_spec.rb:14
故障:
1)StaticPagesController GET' ...'返回http成功 失败/错误:得到' ...' ActionController的:: UrlGenerationError: 没有路线匹配{:action =>" ...",:controller =>" static_pages"} #./spec/controllers/static_pages_controller_spec.rb:7:在'
中的块(3级)在0.20849秒完成19个例子,1个失败,1个未决
失败的例子:
rspec ./spec/controllers/static_pages_controller_spec.rb:6# StaticPagesController GET' ...'返回http成功
这是我的route.rb
文件:
SampleApp::Application.routes.draw do
resources :users
root to: '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
这是我的static_pages_helper_spec.rb
文件:
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the StaticPagesHelper. For example:
#
# describe StaticPagesHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end describe StaticPagesHelper do pending "add some examples to (or delete) #{__FILE__}" end
这是我的static_pages_controller_spec.rb
文件:
require 'spec_helper'
describe StaticPagesController do
describe "GET '...'" do
it "returns http success" do
get '...'
response.should be_success
end
end
end
应用/控制器/ static_pages_controller.rb
class StaticPagesController < ApplicationController
def home
end
def help
end
def about
end
def contact
end
end
我想知道我是否收到错误,因为我的版本与他的教程不兼容。我应该查看本教程而不是http://rails-3-2.railstutorial.org/book/filling_in_the_layout#sec-rails_routes吗?
答案 0 :(得分:0)
您的static_pages_controller_spec
有
describe "GET '...'" do
it "returns http success" do
get '...'
response.should be_success
end
end
"..."
在此上下文中是无意义的,教程可能将其作为“标本”条目包含在其中。
注释掉上面的行,或者用static_pages_controller.rb中的实际方法替换“...”。你可能有一个index
方法,所以你可以做...
describe "GET index" do
it "returns http success" do
get :index
response.should be_success
end
end
干杯