Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

International chars using RSpec with Ruby on Rails

I have just started using RSpec and I copied the very simple test on the RSpec github repo just to make sure things are working as expected:

require 'spec_helper'

describe 'Home Page' do
  it "Welcomes the user" do
    visit '/products'
    page.should have_content("Welcome")
  end
end

The problems begin when I change the string to something like "Olá" or "Caçamba". Any string with a special character. When I do that, I get the following error:

invalid multibyte char (US-ASCII) (SyntaxError)
invalid multibyte char (US-ASCII)
syntax error, unexpected $end, expecting ')'
page.should have_content("Olá")

Any ideas on how to fix it? Maybe some configuration option? Thanks a lot

like image 880
avlnx Avatar asked Jul 04 '12 14:07

avlnx


1 Answers

Most likely you're missing a magic comment at the top of your file:

# encoding: UTF-8

Without this directive Ruby tries to interpret your file with the default US-ASCII encoding and fails since this character set does not include symbols like á or ç.

Here's a blog post on default source encoding in Ruby by James Edward Gray II.

like image 184
KL-7 Avatar answered Sep 28 '22 20:09

KL-7