2012-07-07 83 views
2

我忘了什麼?在獲取請求時沒有路由匹配使用rspec

路線:

get "/comingsoon" => "visitors#comingsoon" 
    resources :visitors 

控制器:

class VisitorsController < ApplicationController 
    def comingsoon 
    @new_visitor = Visitor.new 
    end 
end 

規格:

require 'spec_helper' 

describe VisitorsController do 
    describe "GET /comingsoon" do 
    it "should be happy" do 
     get "/comingsoon" 
     response.should be_success 
    end 
    end 
end 

而這裏的結果:

✗ rspec spec/controllers/visitors_controller_spec.rb 
F 

Failures: 

    1) VisitorsController GET /comingsoon should be valid 
    Failure/Error: get "/comingsoon" 
    ActionController::RoutingError: 
     No route matches {:controller=>"visitors", :action=>"/comingsoon"} 
    # ./spec/controllers/visitors_controller_spec.rb:7:in `block (3 levels) in <top (required)>' 

Finished in 0.14226 seconds 
1 example, 1 failure 

Failed examples: 

rspec ./spec/controllers/visitors_controller_spec.rb:6 # VisitorsController GET /comingsoon should be valid 

我忘了什麼?

回答

3

在你規範文件,get "comingsoon"

更換get "/comingsoon" 當規範中的一個控制器使用RSpec的HTTP動詞的操作數(GET,POST,PUT,刪除)是控制器的行動,而不是一個網址。

0

可能是愚蠢的建議,但你有一個看法是正確的?否則,你必須告訴你的控制器渲染一些東西。