I'm in the course of completing the Pig Latin exercise from TestFirst Teaching, but after I made the Ruby file and attempted to run rake, I got the following error:
austin-winslows-macbook-4:04_pig_latin HypnoBoy$ rake
(in /Users/HypnoBoy/Desktop/Code/learn_ruby)
/Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:45:in `gem_original_require':
/Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin/pig_latin.rb:15: Invalid char `\342' in expression (SyntaxError)
/Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin/pig_latin.rb:15: Invalid char `\200' in expression
/Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin/pig_latin.rb:15: Invalid char `\246' in expression
/Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin/pig_latin.rb:15: syntax error, unexpected tIDENTIFIER, expecting ']'
word[i..-1] + cons.join()[0…i] + "ay"
^
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin/pig_latin_spec.rb:20
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `autorun'
from /usr/bin/rspec:23
rake aborted!
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S rspec /Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin/pig_latin_spec.rb -I/Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin -I/Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin/solution -f documentation -r ./rspec_config failed
(See full trace by running task with --trace)
I think it may have something to do with the version I'm running, but I'm not at all sure.
Mac OSX 10.8.2
Ruby 1.8.7
Rspec 2.13.1
Rake 10.0.4
NOTE! When I run rake on the previous exercises (0-3) they work just fine, but nothing after that works...
EDIT: I updated my rake version, and now when I try to run rake I still get a 'rspec_config failed' error, but I get this as well. HELP!!!
EDIT #2: Here's the source code for my Pig Latin exercise, since it says it's a syntax thing.
def isvowel?(letter)
vowels = ["a", "e", "i", "o", "u"]
vowels.include?(letter)
end
def translate(word)
i = 0
cons = []
while !isvowel?(word[i])
cons << word[i]
i+=1
end
word[i..-1] + cons.join()[0…i] + "ay"
end
def translates(string)
if !string.include?(" ")
translate(string)
else
new = string.split(" ").collect { |word| translate(word) }
end
new.join(" ")
end
المحلول
It's choking on cons.join()[0…i] + "ay" - I noticed that you have a strange looking ... that isn't a standard ...
Did you copy and paste this part of the code? The difference between … (a strange and unwanted character) and ... (the proper ruby operator) is what is breaking it. Simply delete that other character and write the dots in by hand.