我有一个简单的控制器:
class MonitorController < ApplicationController
def pinger
render text: 'pong'
end
end
有路线:
Rails.application.routes.draw do
constraints subdomain: 'api' do
scope module: 'api' do
namespace :v1 do
end
end
end
# ********************************************************************************************
root to: 'monitor#pinger'
end
和我的控制器测试:
require 'spec_helper'
describe MonitorController do
context "#pinger" do
it "Responds Successfully." do
get "/"
response.status.should be(200)
end
it "Should contain 'pong' in the response body." do
get "/"
response.body.should == "pong"
end
end
end
无论我做什么,我似乎无法获得根路线。
错误:
Failures:
1) MonitorController#pinger Should contain 'pong' in the response body.
Failure/Error: get "/"
ActionController::UrlGenerationError:
No route matches {:action=>"/", :controller=>"monitor"}
# ./spec/controllers/monitor_controller_spec.rb:12:in `block (3 levels) in <top (required)>'
2) MonitorController#pinger Responds Successfully.
Failure/Error: get "/"
ActionController::UrlGenerationError:
No route matches {:action=>"/", :controller=>"monitor"}
# ./spec/controllers/monitor_controller_spec.rb:7:in `block (3 levels) in <top (required)>'
Finished in 0.13662 seconds
2 examples, 2 failures
有人能指出我为什么会失败的正确方向吗?
答案 0 :(得分:0)
在您的rspec规范中,请尝试使用:
get :pinger