pyt*_*ips 14 ruby rspec ruby-on-rails rspec-rails
我正在尝试在应用程序控制器上测试一个将用作前置过滤器的方法.为此,我在测试中设置了一个匿名控制器,并应用了之前的过滤器以确保其正常运行.
测试目前看起来像这样:
describe ApplicationController do
controller do
before_filter :authenticated
def index
end
end
describe "user authenticated" do
let(:session_id){"session_id"}
let(:user){OpenStruct.new(:email => "pythonandchips@gmail.com", :name => "Colin Gemmell")}
before do
request.cookies[:session_id] = session_id
UserSession.stub!(:find).with(session_id).and_return(user)
get :index
end
it { should assign_to(:user){user} }
end
end
Run Code Online (Sandbox Code Playgroud)
应用程序控制器是这样的:
class ApplicationController < ActionController::Base
protect_from_forgery
def authenticated
@user = nil
end
end
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我运行测试时,我收到以下错误
1) ApplicationController user authenticated
Failure/Error: get :index
ActionView::MissingTemplate:
Missing template stub_resources/index with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml, :haml], :formats=>[:html], :locale=>[:en, :en]} in view paths "#<RSpec::Rails::ViewRendering::PathSetDelegatorResolver:0x984f310>"
Run Code Online (Sandbox Code Playgroud)
根据文档,运行控制器测试时不会呈现视图,但是这指示此操作没有存根(由于视图不存在,这是可以理解的)
任何人都知道如何解决这个问题或将视图存根.
干杯科林G.
小智 19
你不能通过以下方式解决这个问题:
render :nothing => true
Run Code Online (Sandbox Code Playgroud)
在#index行动里面?
| 归档时间: |
|
| 查看次数: |
3478 次 |
| 最近记录: |