title: Ruby on Rails RSpec Error: Encoding::UndefinedConversionErrors
body: <p>I'm following along with Michael Hartl's <a href="http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#fig%3aheroku_app_31" rel="nofollow" title="Ruby on Rails Tutorial">Ruby on Rails Tutorial</a>. I've completed the tutorial, but now when I try to run the command</p>
  
  <pre><code>bundle exec rspec spec/
  </code></pre>
  
  <p>I get a whole bunch of Encoding::UndefinedConversionErrors. Here's an example:</p>
  
  <pre><code> 101) Authentication AuthenticationPages signin with valid information followed by signout 
     Failure/Error: let(:user) { FactoryGirl.create(:user) }
     ActiveRecord::StatementInvalid:
     Encoding::UndefinedConversionError: "\xDC" from ASCII-8BIT to UTF-8: INSERT INTO "users" ("created_at", "email", "name", "password_digest", "remember_token", "updated_at") VALUES (?, ?, ?, ?, ?, ?)
     # ./spec/requests/authentication_pages_spec.rb:33:in `block (5 levels) in &lt;top (required)&gt;'
     # ./spec/requests/authentication_pages_spec.rb:34:in `block (5 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>I've searched similar problems on Stack Overflow, but the problems involved file I/O, so the solutions there didn't really apply to my problem. I've done some reading of the test.log file after running rspec, and I got a hint that it could have something to do with the way my data is being uploaded to the server, some kind of weird conversion error going on there. </p>
  
  <p>Here is what I have in database.yml to define my test database:</p>
  
  <pre><code>test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000
  encoding: UTF8
  </code></pre>
  
  <p>I'm running Rails 4.0.0, Ruby 2.0.0 and using an sqlite3 database. The sqlite gem I have in my Gemfile is: <code>gem 'sqlite3', '1.3.8'</code>. The gem in my Gemfile for rspec is the following: <code>gem 'rspec-rails', '2.13.1'</code>.</p>
  
  <p>Essentially, I'm trying to figure out why these errors are occurring and how to make them stop happening, and I'm not really sure about either.</p>
  
  <p>EDIT: Here are the contents of my factories.rb file:</p>
  
  <pre><code>#encoding: utf-8
  
  FactoryGirl.define do
    factory :user do
    sequence(:name) { |n| "Person #{n}" }
    sequence(:email) { |n| "person_#{n}@example.com" }
    password "foobar"
    password_confirmation"foobar"
  
    factory :admin do
     admin true
    end
   end
  
   factory :micropost do
    content "Lorem ipsum"
    user
   end
  end
  </code></pre>
  
  <p>I've also noticed that my development.sqlite3 and test.sqlite3 had some ASCII characters in it. Using Notepad++, I tried to re-encode the documents as UTF-8, but then I got an error that required I reset and re-migrate my database. After I did all that, the development and test SQLITE3 files were back to containing ASCII characters. I'm not sure if that could have something to do with it.</p>