Ruby Rspec csv parser syntax error, unexpected ',', expecting ')

Hello friends I am new to Ruby Rspec

I am testing a Ruby Rspec csv parser for csv manipulation with

describe "bashing outing the strings" do
  it " inputs" do
    expect(guess_csv("100,24,32\n42,52,62", ",", "\"")).to eq([["100", "24", "32"], ["42", "52", "62"]])
  end

and ruby.rb

def parse_csv(csv, separator, quote)
 final_array = []
  lines = ("100,24,32\n42,52,62", ",", "\"",  quote: "'", separator: ",").split(/\,\n/).map(&:parse_csv) do |line|
  line.split(',')
   final_array << line.scan(/\,\n/)
  end
  final_array 
end```



An error occurred while loading spec_helper.
Failure/Error: require 'solution'

An error occurred while loading spec_helper. Failure/Error: require β€˜servertime’

SyntaxError: /chicago/default/lib/servertime.rb:3: syntax error, unexpected β€˜,’, expecting β€˜)’ …lines = (β€œ100,24,32\n42,52,62”, β€œ,”, β€œβ€β€œ, quote: β€œ'”, sepa… … ^ /chicago/default/lib/servertime.rb:3: syntax error, unexpected β€˜,’, expecting β€˜)’ … = (β€œ100,24,32\n42,52,62”, β€œ,”, β€œβ€β€, quote: β€œ'”, separator… … ^ /chicago/default/lib/servertime.rb:3: syntax error, unexpected β€˜,’, expecting β€˜)’ …00,24,32\n42,52,62", β€œ,”, β€œβ€β€œ, quote: β€œ'”, separator: β€œ,”)… … ^ /chicago/default/lib/servertime.rb:3: syntax error, unexpected β€˜,’, expecting β€˜)’ …52,62”, β€œ,”, β€œβ€", quote: β€œ'”, separator: β€œ,”).split(/,\n/… … ^ /chicago/default/lib/servertime.rb:6: both block arg and actual block given

./spec/spec_helper.rb:1:in `require’

./spec/spec_helper.rb:1:in `<top (required)>’

No examples found. No examples found.

Just wondering how to fix it

May I suggest that you post that file for which the error is reported?

1 Like

Hey hhitergcon,

The issue is with the lines variable’s assignment in your parse_csv method. Try changing your parse_csv method to the following:

def parse_csv(csv, separator, quote)
  final_array = []
  lines = csv.split("\n")
  
  lines.each do |line|
    final_array << line.split(separator)
  end
  
  final_array
end

This should work for your Rspec test case. Good luck and happy coding!
Bobby the Bot