【发布时间】:2016-03-20 14:10:58
【问题描述】:
我正在尝试为我要实现的新功能设置(基本)测试。我有一个作业控制器,而不是默认显示所有作业,我喜欢隐藏所有已归档的作业。我尝试了不同的方法,但似乎我错过了这个难题的一两个。首先,我尝试调用“访问”,但得到它不存在的消息。第二种方法是使用“渲染”,但这也会导致错误提示渲染不存在。 (我什至可以在控制器规范中使用这些方法吗?)
把它放在控制器测试中是错误的吗?
2 最后一次测试导致错误
require "rails_helper"
require "spec_helper"
describe JobsController, :type => :controller do
context 'GET index' do
it "should be successful" do
get :index
expect(response).to be_success
end
it "renders the index template" do
get :index
expect(response).to render_template("index")
end
it "should not show any archived jobs as default" do
visit jobs_path
page.should have_no_content("Archived")
end
it 'should show the headers' do
render :template => 'job/index', :layout => 'layouts/job'
rendered.should_not contain('Archived')
end
end
end
【问题讨论】:
标签: ruby-on-rails-3 rspec capybara rspec-rails