如何使用Rails 3中的Capybara从选择框中选择日期? [英] How to select date from a select box using Capybara in Rails 3?

查看:130
本文介绍了如何使用Rails 3中的Capybara从选择框中选择日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RSpec和Capybara在Rails 3项目中为控制器编写一个规范,并且我想从选择框中选择当前日期。我试过:

  select Date.today,from from => '出生日期'

但规范失败,我收到错误:



失败/错误:选择Date.today,from from =>'出生日期'
NoMethodError:
undefined方法`to_xpath'为星期一,2011年7月18日:日期



如何解决?



PS在视图文件中,我使用simple_form_for标签,选择框由代码生成:

  f.input:date_of_birth 


解决方案

您需要在html的选择菜单中指定确切的值。所以如果你的选择有像2011/01/01的值,那么你需要写:

  select'2011/01 / 01',:from => '出生日期'

您的代码失败,因为您传递日期对象。


I'm writing a spec for a controller in Rails 3 project using RSpec and Capybara, and I want to select current date from a select box. I tried:

select Date.today, :from => 'Date of birth'

but the spec fails and I get error:

Failure/Error: select Date.today, :from => 'Date of birth' NoMethodError: undefined method `to_xpath' for Mon, 18 Jul 2011:Date

How to fix it?

P.S. In view file I use simple_form_for tag and the select box is generated by code:

f.input :date_of_birth

解决方案

You need to specify the exact value as it's in the select menu in html. So if your select has values like "2011/01/01" then you need to write:

select '2011/01/01', :from => 'Date of birth'

Your code fails because you pass a date object.

这篇关于如何使用Rails 3中的Capybara从选择框中选择日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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