在get请求中没有使用rspec匹配路由

时间:2012-07-07 21:53:29

标签: ruby-on-rails ruby 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

我忘了什么?

2 个答案:

答案 0 :(得分:3)

在您的spec文件中替换get "/comingsoon"  与get "comingsoon"

当您使用rspec指定控制器时,http动词的操作数(get,post,put,delete)是控制器的操作而不是URL。

答案 1 :(得分:0)

可能是愚蠢的建议,但你有一个观点对吗?否则你必须告诉你的控制器渲染一些东西。