【发布时间】:2018-01-17 07:52:57
【问题描述】:
这是我的 static_pages_controller_test,
require 'test_helper'
class StaticPagesControllerTest < ActionDispatch::IntegrationTest
test "should get home" do
get static_pages_home_url
assert_response :success
end
test "should get help" do
get static_pages_help_url
assert_response :success
end
test "should get about" do
get static_pages_about_url
assert_response :success
end
end
错误:
StaticPagesControllerTest#test_should_get_home: ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE 约束失败:users.email: INSERT INTO "users" ("created_at", “updated_at”、“id”)值('2018-01-17 05:49:27.300065'、'2018-01-17 05:49:27.300065', 298486374)
我将 user.yml 更改为,
one:
email: test1@test.com
two:
email: test2@test.com
错误:
StaticPagesControllerTest#test_should_get_about: ActiveRecord::Fixture::FormatError: 夹具键不是哈希: C:/Sites/IntenetChatSystem/test/fixtures/users.yml, 键: ["one", “电子邮件”,我是两个“]
我很困惑我该怎么办,请给一些建议
【问题讨论】:
-
您可能会收到此错误,因为您的 users.yml 没有正确缩进。 guides.rubyonrails.org/testing.html "每个夹具都有一个名称,后跟一个以冒号分隔的键/值对的缩进列表。记录通常用空行分隔。"
-
您的 user.yml 是否正确缩进?请确保一个以下的电子邮件应在内部缩进 1 个。这意味着 1 和 2 应该是 0 缩进,而 email 应该是 1。
标签: ruby-on-rails ruby-on-rails-3 unit-testing