2014-01-17 31 views
2

我正在使用Rails 3.2.13和ruby 1.9.3。我不斷收到以下錯誤:Rails- RSPEC不完整的多字節字符錯誤

Failure/Error: @user = Fabricate :user, role_ids: [role.id] 
PG::Error: 
    incomplete multibyte character 
# ./spec/controllers/api_controllers/projects_controller_spec.rb:6:in `block (2 levels) in <top (required)>' 

關於錯誤令人沮喪的是它間歇性地發生。有時我可以在沒有發生的情況下運行測試10次,然後每次都發生其他時間。

圍繞projects_controller_spec.rb文件的第6行的代碼中錯誤發生時看起來像這樣:

require 'spec_helper' 

describe Api::V1::ProjectsController do 
    before do 
    role = Fabricate :data_collector_role 
    @user = Fabricate :user, role_ids: [role.id] # this is line 6 
    @project = Fabricate.build(:project, proposal: Fabricate(:full_proposal)) 
    @project.save(validate: false) 
    @permission = Fabricate :permission, user: @user, project: @project 
    @project2 = Fabricate.build(:project, proposal: Fabricate(:full_proposal)) 
    @project2.save(validate: false) 
    request.env["HTTP_ACCEPT"] = 'application/json' 
    request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(@user.api_key) 
    end 

被調用上線的上方6製造者看起來是這樣的:

​​

相同的代碼在其他不適用於API控制器的規範中被調用,並且它們在100%的時間內都能正常工作。

時不時RSPEC完全崩潰,並提供了以下錯誤:

 Failure/Error: get :show, { id: @project.id } 
    ActiveRecord::StatementInvalid: 
/Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/formatters/base_text_formatter.rb:182:in `split': invalid byte sequence in UTF-8 (ArgumentError) 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/formatters/base_text_formatter.rb:182:in `dump_failure_info' 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/formatters/base_text_formatter.rb:175:in `dump_failure' 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/formatters/base_text_formatter.rb:19:in `block in dump_failures' 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/formatters/base_text_formatter.rb:17:in `each' 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/formatters/base_text_formatter.rb:17:in `each_with_index' 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/formatters/base_text_formatter.rb:17:in `dump_failures' 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/reporter.rb:98:in `block in notify' 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/reporter.rb:97:in `each' 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/reporter.rb:97:in `notify' 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/reporter.rb:81:in `finish' 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/reporter.rb:36:in `report' 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:25:in `run' 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:66:in `rescue in run' 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:62:in `run' 
from /Users/michael/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun' 
+0

檢查,如果這頂幫助http://stackoverflow.com/questions/9167468/rails-3-how-to-handle-pg-error-incomplete-multibyte-character – PriteshJ

+1

@PriteshJ在測試的任何地方都沒有非UTF-8字符可能是造成問題。謝謝你指出,雖然 – bambinz

回答

0

添加到您的文件規範/控制器/ api_controllers/projects_controller_spec.rb

# !/usr/bin/env ruby 
# encoding: utf-8 
+0

Trix是爲孩子們,愚蠢的兔子。 –

+0

很遺憾,沒有幫助 – bambinz

+0

更新了答案,再試一次。 –

相關問題