Ruby on rails 控制器测试错误消息:";ActionView::Template::错误:资产";MyString“;在资产管道中不存在”;

Ruby on rails 控制器测试错误消息:";ActionView::Template::错误:资产";MyString“;在资产管道中不存在”;,ruby-on-rails,ruby,unit-testing,ruby-on-rails-5,Ruby On Rails,Ruby,Unit Testing,Ruby On Rails 5,这是失败的测试代码: test "should get index" do get products_url assert_response :success end 错误信息为ActionView::Template::错误:资产“MyString”不在资产管道中 WTF?您必须确保装置中存在图像 遇到了同样的问题,但找到了一个简单的解决方案。 First I fixed in/test/fixture/products.yml one: title: MyStr

这是失败的测试代码:

  test "should get index" do
    get products_url
    assert_response :success
  end
错误信息为ActionView::Template::错误:资产“MyString”不在资产管道中


WTF?

您必须确保装置中存在图像

遇到了同样的问题,但找到了一个简单的解决方案。 First I fixed in/test/fixture/products.yml

one:
  title: MyString
  description: MyText
  image_url: lorem.jpg
  price: 9.99

two:
  title: MyString
  description: MyText
  image_url: lorem.jpg
  price: 9.99

最后,我实际上在我的资产/图像中添加了一个名为“lorem.jpg”的图像。我觉得很困惑,因为他们在书中根本没有提到这一点,但希望这个小小的指针能让你回到正轨上。

只要读一下上面提到的控制器上的测试叫做功能测试,而不是单元,单元是用于模型的。只要遵循错误信息的提示,如果从视图模板中删除:那么测试将无误通过。–Bartosz Wais 11分钟前又思考了5分钟后,看起来“MyString”是fixture的属性。您可能错误地运行了
bin/rails测试,而书中说运行
bin/rails测试:models
。在本章后面,他们将讨论这个错误以及如何解决它。对于那些感兴趣的人来说,这本书是:使用Rails@MichaelMinton接得好,我也有同样的问题。这本书没有简单地提到它:)。