Ruby on rails RSpec未定义的方法'request='1'

Ruby on rails RSpec未定义的方法'request='1',ruby-on-rails,rspec,Ruby On Rails,Rspec,这是我的规格/控制器/飞行\u控制器\u规格.rb: require 'rails_helper' require 'spec_helper' require 'flight' RSpec.describe Flight, type: :controller do describe 'GET/index', :type => :request do it 'displays flights' do Flight

这是我的规格/控制器/飞行\u控制器\u规格.rb:

    require 'rails_helper'
    require 'spec_helper'
    require 'flight'


    RSpec.describe Flight, type: :controller  do
      describe 'GET/index', :type => :request do
       it 'displays flights' do
        Flight.create!(:destination => 'San Francisco')
        get :index
        response.body.should include('San Francisco')
       end
     end
    end
这是我的应用程序/controllers/flights\u controller.rb:

    require 'rails_helper'

    RSpec.describe FlightsController, type: :controller do
      describe 'GET index' do
      end
    end
不知道有什么事-感谢任何帮助-提前感谢,
Slavko

在你的天赋的顶端

    class FlightsController < ApplicationController
      before_action :set_flight, only: [:show, :edit, :update, :destroy]

      # GET /flights
      # GET /flights.json
      def index
        @flights = Flight.all
      end

      # GET /flights/1
      # GET /flights/1.json
      def show
  end

  # GET /flights/new
  def new
    @flight = Flight.new
  end

  # GET /flights/1/edit
  def edit
  end

  # POST /flights
  # POST /flights.json
  def create
    @flight = Flight.new(flight_params)

    respond_to do |format|
      if @flight.save
        format.html { redirect_to @flight, notice: 'Flight was successfully created.' }
        format.json { render :show, status: :created, location: @flight }
      else
        format.html { render :new }
        format.json { render json: @flight.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /flights/1
  # PATCH/PUT /flights/1.json
  def update
    respond_to do |format|
      if @flight.update(flight_params)
        format.html { redirect_to @flight, notice: 'Flight was successfully updated.' }
        format.json { render :show, status: :ok, location: @flight }
      else
        format.html { render :edit }
        format.json { render json: @flight.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /flights/1
  # DELETE /flights/1.json
  def destroy
    @flight.destroy
    respond_to do |format|
      format.html { redirect_to flights_url, notice: 'Flight was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_flight
      @flight = Flight.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def flight_params
      params.require(:flight).permit(:departure, :arrival, :destination, :baggage_allowance, :capacity)
    end
end
但就在下面

RSpec.describe Flight, type: :controller
您必须从规范中选择一个或另一个,您可能需要控制器规范


除控制器规范外,所述对象应为控制器类,而非模型类。

此处未显示的代码中可能有@flight.request=的地方。可能在视图中?确定-将“请求”更改为“控制器”,并注释掉了“创建模型”实例行,但仍然得到相同的错误。@user3570192您仍然得到了描述航班
RSpec.describe Flight, type: :controller
describe "GET /index", type: :request