I have run my program and everything works great. I am now trying to write some tests and I keep getting this error:
Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8
I am not using any weird characters to my knowledge. I dont even know where to begin with this error. I tried adding these two lines to the environment.rb file:
Encoding.default_internal = Encoding::UTF_8
Encoding.default_external = Encoding::UTF_8
and that did not help. Here is the test I am trying to run:
require 'test_helper'
class UserTest < ActiveSupport::TestCase
test "should require all fields" do
u = User.new
assert_false u.valid?
end
end
here is my users.yml file:
one:
name: MyString
password: MyString
two:
name: MyString
password: MyString
<% (1..5).each do |i| %>
user_<%= i %>:
name: user_<%= i %>
password: user_<%= i %>
<% end %>
here is my stack trace:
Creating sqlite :memory: database
-- create_table("comment_votes", {:force=>true})
-> 0.0021s
-- create_table("comments", {:force=>true})
-> 0.0013s
-- add_index("comments", ["post_id"], {:name=>"index_comments_on_post_id"})
-> 0.0005s
-- create_table("posts", {:force=>true})
-> 0.0015s
-- create_table("users", {:force=>true})
-> 0.0013s
-- create_table("votes", {:force=>true})
-> 0.0010s
-- initialize_schema_migrations_table()
-> 0.0009s
-- assume_migrated_upto_version(20111005200722, ["db/migrate"])
-> 0.0013s
Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8
1 tests, 0 assertions, 0 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
Test suite finished: 0.058747 seconds
Process finished with exit code 1
Are your passwords salted? And does the salt, by any chance, use random bytes that may not conform to UTF-8 or US-ASCII? This has caught me out before. I had to
force_encoding("BINARY")on my password salts.