2

我忘记了什么?

路线:

  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

我忘记了什么?

4

2 回答 2

3

在您的规范文件中替换get "/comingsoon"get "comingsoon"

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

于 2012-07-07T22:13:44.353 回答
0

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

于 2012-07-07T22:13:05.857 回答