运行规格时发生非描述性错误,取决于种子 [英] Undescriptive error when running spec, occurs dependent on seed

查看:78
本文介绍了运行规格时发生非描述性错误,取决于种子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个功能规范来测试我的应用程序中正确的多租户行为。它以两个不同的用户身份登录,通过填写表格并将其提交给每个用户来创建新的 Presentation ,并每次确认只有房客自己的演示文稿可见

I have written a feature spec to test for correct multitenancy behaviour within my application. It signs in as two different users, creates a new Presentation by filling in a form and submitting it as each user, and confirms every time that only the tenant's own Presentations are visible to them.

此规范有时可以通过,有时不能通过。真正令人困惑的是发生的错误:

This spec passes fine sometimes, and sometimes doesn't. What is really confusing is the error that occurs:

Failure/Error: click_button "Präsentation erstellen"
TypeError:
  can't cast ActiveSupport::HashWithIndifferentAccess to
# ./app/controllers/presentations_controller.rb:21:in `create'
# ./spec/features/presentation_management_spec.rb:22:in `block (3 levels) in <top (required)>'

粘贴时出现错误,字面意思是无法将ActiveSupport :: HashWithIndifferentAccess强制转换为并就此停止。上下文中引用的行:

and that is not a error at pasting, it literally says can't cast ActiveSupport::HashWithIndifferentAccess to and just stops there. The referenced lines in context:

./ app / controllers / presentations_controller.rb

18 def create
19  @presentation = Presentation.new(presentation_params)
20  
21  if @presentation.save
22    flash_for(@presentation, :create)
23    redirect_to @presentation
24  else
25    render :new
26  end
27 end

./ spec / features / presentation_management_spec.rb

16 sign_in @user1
17
18 visit new_presentation_path
19 fill_in "Titel", with: title1
20 fill_in "Standard-Foliendauer", with: "60"
21
22 click_button "Präsentation erstellen"
23
24 page.should have_content "erfolgreich erstellt"
25 page.should have_content title1

我不知道该错误在这里有什么意义,我只是单击一个按钮创建一个新的演示文稿并保存。保存本身会引发错误。怎么样?为什么?

and I don't see how that error makes any sense here, I'm just clicking a button that will create a new Presentation and save it. The saving itself throws the error. How? Why?

更糟糕的是,此仅与某些rspec种子一起发生。例如, 48719 运行良好:

To make it worse, this only occurs with some rspec seeds. For instance, 48719 runs fine:

..........................................................................................

Finished in 48.17 seconds
90 examples, 0 failures

Randomized with seed 48719

这意味着仅在某些规格执行顺序时发生错误。但是错误根本不是描述性的,我也不知道该怎么办。我尝试过重置所有数据库,重新启动我的整个服务器,打印出按下按钮的页面,注释掉不同的行,但没有任何改变,甚至暗示可能出了问题。

Which means that this error occurs only with some execution orders of the specs. But the error isn't descriptive at all, and I don't know what to do. I've tried resetting all databases, restarting my entire server, printing out the page where the button is pressed, commenting different lines out, and nothing would change, or even hint at what might be wrong.

这是我的演示文稿模型:

Here's my Presentation model:

 class Presentation < ActiveRecord::Base
  store_accessor :properties, :bg_color, :bg_image

  validates :title, presence: true
  validates :default_duration, presence: true, numericality: { greater_than_or_equal_to: 1 }

  def to_s
    title
  end

end

编辑:在失败的情况下,我检查了测试日志并发现了 this

EDIT: I checked the test logs and found this in a failing case:

  SQL (1.3ms)  INSERT INTO "presentations" ("created_at", "default_duration", "properties", "title", "updated_at") VALUES ($1, $2,
$3, $4, $5) RETURNING "id"  [["created_at", Tue, 04 Feb 2014 20:56:26 UTC +00:00], ["default_duration", 60.0], ["properties", {"bg_
color"=>"#ffffff"}], ["title", "Example Presentation yo"], ["updated_at", Tue, 04 Feb 2014 20:56:26 UTC +00:00]]
TypeError: can't cast ActiveSupport::HashWithIndifferentAccess to : INSERT INTO "presentations" ("created_at", "default_duration",
"properties", "title", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"
   (1.6ms)  ROLLBACK TO SAVEPOINT active_record_1
Completed 500 Internal Server Error in 10ms

,这里唯一的哈希是 { bg_c​​olor =>#ffffff} ,分配给 properties 属性字段是 hstore 类型。也许这是hstore的问题,这也许可以解释为什么Rails错误输出无法将任何内容抛到不能将...投射到的原因,因为它不是数据类型Rails真正能真正理解吗?

and the only Hash here would be {"bg_color"=>"#ffffff"}, assigned to properties. The properties field is an hstore type. Maybe this is an issue with hstore, which might explain why the Rails error output was inable to put anything behind the can't cast ... to, because it's not a data type Rails truly natively understands?

编辑2

我刚刚得到了尝试在Rails控制台上创建新的 Presentation 时,发生了与开发中完全相同的错误。我最初的想法是我可能在 search_path 中省略了 hstore 模式,但是添加它并没有任何好处。

I just now got the exact same error in development while trying to create a new Presentation on the rails console. My initial thought was that I had maybe left out the hstore schema in the search_path, but adding it did no good.

这确认这不是测试编写方式的问题,而是实际的编码问题。我不确定此时该怎么做。

This confirms that it's not an issue of how the tests are written, but an actual coding problem. I'm not sure what to do at this point.

推荐答案

我认为您在正确的解决方案上将属性作为准备好的语句保存到您的hstore数据类型中。也许这个答案会帮助您。 :)

I think you're on the right track that its related to saving the properties to your hstore data type as a prepared statement. Perhaps this answer will help you. :)

https://stackoverflow.com/a/11074481/793330

这篇关于运行规格时发生非描述性错误,取决于种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆