Ruby on rails ActiveRecord::Fixture::FormatError:解析时发生YAML错误
我正在尝试在ruby上创建我的第一个应用程序的一个示例。。。 这是我的测试文件Ruby on rails ActiveRecord::Fixture::FormatError:解析时发生YAML错误,ruby-on-rails,ruby,fixture,Ruby On Rails,Ruby,Fixture,我正在尝试在ruby上创建我的第一个应用程序的一个示例。。。 这是我的测试文件 require File.dirname(__FILE__) + '/../test_helper' class SupplierTest < ActiveSupport::TestCase fixtures :suppliers def test_name supplier=Supplier.create(:name => 'juan'
require File.dirname(__FILE__) + '/../test_helper'
class SupplierTest < ActiveSupport::TestCase
fixtures :suppliers
def test_name
supplier=Supplier.create(:name => 'juan' , :province => nil)
assert_equal 'juan' , supplier.get_name
end
end
结果是
Psych::SyntaxError: (<unknown>): could not find expected ':' while scanning a simple key at line 8 column 1
Psych::SyntaxError:():在扫描第8行第1列的简单键时找不到预期的“:”
YAML需要在:
和值之间留一个空格,因此请尝试将设备更新为:
juan:
id: 1
name: juan
province:
(在省中写入
nil
将导致值为“nil”
。保留为空将导致值为真nil
我已更改了添加空格的装置,但现在显示ActiveRecord::fixture::FormatError:再次检查YAML的格式是否正确,如果正确,检查这是否是您的问题:使用任何在线或离线工具检查YAML语法和正确性。例如:yaml-online-parser.appspot.com要在yaml中显式表达Ruby的nil
,请使用。
juan:
id: 1
name: juan
province: