rspec错误:期待<“index”>但使用<“”>进行渲染

时间:2015-04-23 19:26:17

标签: ruby-on-rails ruby rspec factory-bot

我查看了有关此错误的所有其他帖子,但没有任何效果:

carrier_spec.rb

require 'rspec'
require 'spec_helper'
require 'factory_girl_rails'
require 'rails_helper'
require 'helpers'


RSpec.configure do |c|
  c.include Helpers

end


RSpec.describe CarriersController, :type => :controller do


  describe "#index" do
    render_views
    it 'should get index' do
      CarriersController.prepend_view_path(root_path)
      login_id = login_admin
      expect(response).to be_successful


      get :index, :format => "html"
      expect(response).to render_template(:index)
      # var = FactoryGirl.create(:carrier)
      # expect(var.valid?).to eql(true)
    end
  end

end

helpers.rb

module Helpers
  def login(user)
    request.session[:user] = user.id
  end

  def login_admin
    admin = FactoryGirl.create(:admin)

    expect(admin.valid?).to eql(true)
    expect(admin.admin?).to eql(true)
    expect(admin.device_admin?).to eql(true)

    login(admin)
  end
end

carriers_controller.rb

  # GET /carriers
  # GET /carriers.json
def index
    @carriers = Carrier.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @carriers }
    end

  end

我不确定为什么会这样...... 我知道索引页面加载到/ carrier,而不是/carriers/index.html,但是这会有所不同吗?

0 个答案:

没有答案