Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 测试由ruby on rails上的number_字段创建的flash消息_Ruby On Rails_Capybara_Form For - Fatal编程技术网

Ruby on rails 测试由ruby on rails上的number_字段创建的flash消息

Ruby on rails 测试由ruby on rails上的number_字段创建的flash消息,ruby-on-rails,capybara,form-for,Ruby On Rails,Capybara,Form For,正在尝试写入验收以测试是否显示错误消息。我在测试表单\u中的数字\u字段类型时遇到问题 组-Index.html.erb <div class='row'> <div class="small-4 columns"> <%= f.label :size %> <%= f.number_field :size, in: 1..12 %> </div> </div> 问题在于,

正在尝试写入验收以测试是否显示错误消息。我在测试表单\u中的数字\u字段类型时遇到问题

组-Index.html.erb

 <div class='row'>
    <div class="small-4 columns">
      <%= f.label :size %>
      <%= f.number_field :size, in: 1..12 %>
    </div>
  </div>

问题在于,如果输入值不在1和12之间,则number_字段会阻止表单提交。它会显示一条闪烁消息,说明数字必须介于1和12之间


因为表单根本没有提交,所以控制器中的我的flash[:error]没有被命中。我不太确定如何测试这个问题

使用Capybara/RSpec,您至少可以编写如下内容:

visit my_form_path
fill_in ... # all the other stuff on the form
select '99', from: 'size'
click_button 'Submit' #or whatever the submit button is called
expect(page).to_not have_content(...) #text on page rendered if form submit works
expect(page).to have_content(...) #text on the form the user should still be on

你是对的,如果浏览器支持HTML5,你将永远看不到flash。Capybara支持不同的浏览器引擎,但我对它不太熟悉,不知道它是否支持任何模仿旧浏览器的引擎。如果是这样的话,你可以换一个旧的浏览器,你可能会看到flash。

上述内容适用于Capybara不支持HTML5的情况,因此它实际上提交了表单。但是从用户的角度来看,验收测试,他们实际上并没有提交表单,所以为水豚提交测试的后一种情况编写测试从用户的角度来看是错误的。我建议使用Selenium驱动程序,但我认为Firefox不支持此元素。我想知道你是否可以用它和聚填充,但我不知道我的深度在那一点上。