语法错误,意外的 '\n',期待 => (SyntaxError)

syntax error, unexpected '\n', expecting => (SyntaxError)

使用 RSpec 到 运行 一些测试,我得到以下错误:

/spec/requests/booking_applications_spec.rb:13: syntax error, unexpected '\n', expecting => (SyntaxError)

这是文件:

spec/requests/booking_applications_spec.rb:

require 'spec_helper'
require "rails_helper"

RSpec.describe "Booking applications", :type => :request do

  describe "POST new booking application" do

    it "creates a new booking application" do
      BookingApplication.destroy_all
      BookingApplication.count.should == 0      

      params = { format: :json, booking_application: { driver_id: 1 } } #Error
      post :create, :booking_id => 1, params

      BookingApplication.count.should == 1
      response.status.should eq(200)
    end

  end

end

您的错误似乎在下一行:

  post :create, :booking_id => 1, params

您需要将其更改为:

  post :create, params.merge(booking_id: 1)

或者一次在参数中包含 booking_id: 1

Ruby 无法在方法调用结束时解析选项散列,它期望像

  post :create, :booking_id => 1, params => 'something'