簡體   English   中英

語法錯誤,意外的'\\ n',期望=>(SyntaxError)

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

使用RSpec運行一些測試,我得到以下錯誤:

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

這是文件:

規格/要求/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'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM