哈希,flash和assert_not - 我如何assert_not哈希

时间:2014-10-07 11:00:49

标签: ruby-on-rails

我正在尝试完成Mhartl RoR教程中的练习。

问题要求您完成以下集成测试

assert_not 'flash.FILLIN'

assert_select 'div#FILLIN'
assert_select 'div.FILLIN'

我有一个显示

的闪光灯
{:success => "success message here"}

或出错时,

<% flash.each do |message_type, message| %>

采用标准@ user.errors.fullmessages。

我的问题是:

我如何查找@ users.errors.fullmessages列表,以及assert_not如何报错?

assert_not 'flash.errors'

没有退出:成功...... :(

任何帮助表示赞赏,此练习的链接位于:https://draft.railstutorial.org/book/sign_up#sec-signup_exercises

3 个答案:

答案 0 :(得分:6)

原来它是

assert_not flash.nil?

以及一些有用的地方:Check for array not empty: any?

:)

答案 1 :(得分:3)

assert_not flash.empty?

Michael Hartl说&#34;我更喜欢测试闪光灯不是空的&#34;在 http://3rd-edition.railstutorial.org/book/sign_up#sec-signup_exercises

他在同一个测试中写道 http://3rd-edition.railstutorial.org/book/updating_and_deleting_users#code-successful_edit_test

答案 2 :(得分:0)

要声明特定类型集合没有flash消息(在此示例中为:error),您可以执行以下操作:

assert_predicate flash[:error], :nil?