1

我的报告有问题(涵盖带有规格测试的模型)。我的宝石:

group :development, :test do
  gem 'factory_girl_rails', '3.4.0'
  gem 'rspec-rails', '2.11.0'
  gem 'guard-rspec', '1.2.0'
  gem 'guard-bundler', '1.0.0'
  gem 'guard-cucumber'
  gem "shoulda-matchers", '1.1.0'
end

group :test do
  gem 'simplecov', :require => false
  #gem "simplecov-rcov", "~> 0.2.3"
gem 'cucumber-rails', require: false
  gem 'database_cleaner'
  gem "capybara"
  gem 'json_spec'
end

错误信息:

Finished in 1.21 seconds
9 examples, 0 failures
/var/lib/gems/1.9.1/gems/json-1.7.5/lib/json/common.rb:285:in `encode': "\xD1" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)
    from /var/lib/gems/1.9.1/gems/json-1.7.5/lib/json/common.rb:285:in `generate'
    from /var/lib/gems/1.9.1/gems/json-1.7.5/lib/json/common.rb:285:in `pretty_generate'
    from /var/lib/gems/1.9.1/gems/simplecov-0.6.4/lib/simplecov/result_merger.rb:77:in `block in store_result'
    from /var/lib/gems/1.9.1/gems/simplecov-0.6.4/lib/simplecov/result_merger.rb:75:in `open'
    from /var/lib/gems/1.9.1/gems/simplecov-0.6.4/lib/simplecov/result_merger.rb:75:in `store_result'
    from /var/lib/gems/1.9.1/gems/simplecov-0.6.4/lib/simplecov.rb:48:in `result'
    from /var/lib/gems/1.9.1/gems/simplecov-0.6.4/lib/simplecov/configuration.rb:133:in `block in at_exit'
    from /var/lib/gems/1.9.1/gems/simplecov-0.6.4/lib/simplecov/defaults.rb:51:in `call'
    from /var/lib/gems/1.9.1/gems/simplecov-0.6.4/lib/simplecov/defaults.rb:51:in `block in <top (required)>'

如何解决?请帮忙!

更新
我所做的:1)卸载并重新安装了所有宝石http://axonflux.com/uninstalling-and-reinstalling-all-ruby-gems
2)删除了 .rvn 目录
3)注释掉了一些宝石

group :development do
#  gem 'growl'
group :test do
# gem 'json_spec'
  gem 'simplecov', :require => false
  #gem "simplecov-rcov", "~> 0.2.3"

4) 安装 rvn
在任何这些阶段都没有运气....
必须找到那些违规角色的确切位置!

更新
尝试设置 Encoding.default_external = :'ASCII-8BIT' | :'UTF-8' 在 boot.rb 中。没运气

更新 试图通过运行脚本来解决问题

  #!/bin/bash
    FROM=us-ascii
    TO=UTF-8
    ICONV="iconv -f $FROM -t $TO"
    # Convert
    find gazsev32/ -type f -name "*" | while read fn; do
    cp ${fn} ${fn}.bak
    $ICONV < ${fn}.bak > ${fn}
    rm ${fn}.bak
    done

更新
最后,恐怕是时候重新安装我的系统了。出现系统错误

4

1 回答 1

1

UTF-8 编码

你的踪迹说:

/var/lib/gems/1.9.1/gems/json-1.7.5/lib/json/common.rb:285:in `encode': "\xD1" 从 ASCII-8BIT 到 UTF-8(编码::未定义的转换错误)

这显然是一个编码错误,这是 Ruby 1.9 下的常见问题。有时可以通过确保您具备以下条件来解决:

# encoding: utf-8

在源文件的顶部,但如果不是,您可能需要使用shell 中的/usr/bin/iconv或一些 Ruby 蛮力删除违规字符,然后再尝试将代码转换为 JSON。问题显然出在您的 JSON 库中,但有问题的字符可能在您的源代码中的其他地方。

于 2012-10-25T13:02:00.750 回答