我正在使用rails 4.1.1
和rspec 3.0.3
。
这是rspec代码。
require 'rails_helper'
describe MembersController, type: :controller do
describe 'GET index' do
it 'should be success' do
puts "11111"
get :index
puts "33333"
expect(response).to render_template :index
end
end
end
控制器的和:index
动作是,
def index
puts "22222"
@members = Member.order('mem_id DESC').paginate(page: params[:page]||1, per_page: params[:per_page]||30)
end
==============================
并且我做了'rake spec',我在控制台上打印出这样的打印。
11111
22222
33333
但结果是,
11111
33333
它会发出如下错误信息。
Failure/Error: expect(response).to render_template :index
expecting <"index"> but rendering with <[]>
我的rspec出了什么问题?
----------------------------------- 更新问题 --- ---------------------------
这是spec/rails_helper.rb
(删除所有评论)
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = false
config.infer_spec_type_from_file_location!
end