【发布时间】:2017-08-14 15:01:29
【问题描述】:
我正在构建一个使用活动记录但不使用 Rails 的 Ruby 项目。在我的一项测试中,我正在尝试以下内容:
it "fails with no driver name" do
command = "Driver"
expect {command_file.process_driver command}.to raise_error(ActiveRecord::RecordInvalid)
end
这是我试图调用的方法
def process_driver command
driver_name = command.split[1]
Driver.create! :name => driver_name
end
我希望将:name => nil 传递给Driver.create!,这应该会抛出RecordInvalid,但我会得到I18n::InvalidLocaleData。这是回溯
expected ActiveRecord::RecordInvalid, got #<I18n::InvalidLocaleData: can not load translations from /Users/me/.rbenv/versions/2.3.1/lib/r...ems/activesupport-5.1.3/lib/active_support/locale/en.yml: expects it to return a hash, but does not> with backtrace:
# ./command_file.rb:81:in `process_driver'
# ./command_file.rb:63:in `block in process'
# ./command_file.rb:51:in `each'
# ./command_file.rb:51:in `each_with_index'
# ./command_file.rb:51:in `process'
# ./spec/command_file_spec.rb:60:in `block (5 levels) in <top (required)>'
# ./spec/command_file_spec.rb:60:in `block (4 levels) in <top (required)>'
# ./spec/spec_helper.rb:75:in `block (3 levels) in <top (required)>'
# ./spec/spec_helper.rb:74:in `block (2 levels) in <top (required)>'
这是我的Gemfile
source 'https://rubygems.org'
gem 'sqlite3', '~> 1.3', '>= 1.3.13'
gem 'activerecord', '~> 5.1', '>= 5.1.3'
gem 'pry', '~> 0.10.4'
gem 'rspec', '~> 3.6'
gem 'factory_girl', '~> 4.5'
group :test do
gem 'database_cleaner'
end
我没有自己的语言环境文件。
知道发生了什么吗?我没有在这个项目中尝试任何形式的翻译。我也不明白为什么active_support 提供的语言环境文件会失败。如果可能的话,我很乐意以某种方式简单地禁用 i18n,但我不知道该怎么做。任何想法是什么问题?
【问题讨论】:
-
您有任何
.yml或配置文件吗?你能附上.gemfile吗? -
@MaxL。我没有
.yml或配置文件。我已将我的Gemfile添加到问题中 -
您的
config/locales文件夹中有任何内容吗?可能是空的en.yml文件? -
@SergioTulentsev 我没有
config/locales文件夹。我什至不打算进行国际化。 -
您能否验证您的计算机上是否存在 {your-ruby-gempath}/active_support-5.1.3/lib/active_support/locale/en.yml 文件?您是否使用 rb env 切换了 ruby 版本 - 您是否需要使用当前版本的 ruby 运行
bundle install才能安装 active_support?或者切换回正确的 rb env ruby 版本?
标签: ruby activerecord internationalization activesupport