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

时间:2015-04-23 11:21:03

标签: ruby-on-rails rspec

使用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

1 个答案:

答案 0 :(得分:2)

您的错误似乎在下一行:

  post :create, :booking_id => 1, params

您需要将其更改为:

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

或者同时将booking_id: 1包含在参数中。

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

这样的smth
  post :create, :booking_id => 1, params => 'something'