语法错误,意外的 '\n',期待 =>(语法错误) [英] syntax error, unexpected '\n', expecting => (SyntaxError)

查看:66
本文介绍了语法错误,意外的 '\n',期待 =>(语法错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Using RSpec to run some tests, I get the following error:

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

这是文件:

spec/requests/booking_applications_spec.rb:

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

推荐答案

你的错误似乎在下一行:

Your error seem to be in the next line:

  post :create, :booking_id => 1, params

您需要将其更改为:

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

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

Or include booking_id: 1 in params at once.

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

Ruby cannot parse options hash in the end of method call, it expects smth like

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

这篇关于语法错误,意外的 '\n',期待 =>(语法错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆