$ruby --version
ruby 1.9.3dev (2011-09-23 revision 33323) [i686-linux]
gem 'rails', '3.2.9'
group :test do
gem 'cucumber-rails', require: false
gem 'capybara', '~> 2.0.3'
gem 'rspec-rails'
gem 'database_cleaner'
gem 'factory_girl'
gem "ffaker"
gem "capybara-firebug", "~> 1.3.0"
gem 'ruby-debug19'
end
在我的一个Cucumber Step中,我试图断言一个下拉元素 (< select>标记)使用Capybara API选择了特定选项 使用以下代码。
within('#myForm') do
page.has_select?("#event_type", selected: @event_type).should be_true
end
但是我收到了这个错误:
expected: true value
got: false (RSpec::Expectations::ExpectationNotMetError)
我在我的场景中使用 @firebug 标签(capybara-firebug)检查了DOM 并发现所需的选项(由@event_type持有)正在被选中 但是在DOM中的下拉列表中,“selected”属性没有得到 添加到select标签,我猜这会导致期望失败。
我在这里找到了类似的参考:https://github.com/jnicklas/capybara/issues/171 提到有修复的提交,但我想提交不是 合并到我正在使用的水豚版本。我正在尝试挖掘源代码 并发现https://github.com/jnicklas/capybara/issues/171中提到的修补程序 并没有出现在Capybara的代码库中。
任何正文都可以让我知道如何断言选择标签有一个 是否选择了特定选项?
注意:在我的Gem文件中使用capybara时没有任何版本:
gem 'capybara'
Capybara版本2.1.0已启动安装,但失败并显示错误:
capybara requires Ruby version >= 1.9.3
虽然我有所需的ruby版本。
以下是
的输出 $ rvm info
ruby-1.9.3-rc1:
system:
uname: "Linux jigneshgohel-Inspiron-N5110 3.2.0-40-generic-pae #64-Ubuntu SMP Mon Mar 25 21:44:41 UTC 2013 i686 i686 i386 GNU/Linux"
bash: "/bin/bash => GNU bash, version 4.2.24(1)-release (i686-pc-linux-gnu)"
zsh: " => not installed"
rvm:
version: "rvm 1.13.4 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
updated: "11 months 4 days 14 hours 20 minutes 18 seconds ago"
ruby:
interpreter: "ruby"
version: "1.9.3dev"
date: "2011-09-23"
platform: "i686-linux"
patchlevel: "2011-09-23 revision 33323"
full_version: "ruby 1.9.3dev (2011-09-23 revision 33323) [i686-linux]"
homes:
gem: "/home/jigneshgohel/.rvm/gems/ruby-1.9.3-rc1"
ruby: "/home/jigneshgohel/.rvm/rubies/ruby-1.9.3-rc1"
binaries:
ruby: "/home/jigneshgohel/.rvm/rubies/ruby-1.9.3-rc1/bin/ruby"
irb: "/home/jigneshgohel/.rvm/rubies/ruby-1.9.3-rc1/bin/irb"
gem: "/home/jigneshgohel/.rvm/rubies/ruby-1.9.3-rc1/bin/gem"
rake: "/home/jigneshgohel/.rvm/gems/ruby-1.9.3-rc1/bin/rake"
environment:
PATH: "/home/jigneshgohel/.rvm/gems/ruby-1.9.3-rc1/bin:/home/jigneshgohel/.rvm/gems/ruby-1.9.3-rc1@global/bin:/home/jigneshgohel/.rvm/rubies/ruby-1.9.3-rc1/bin:/home/jigneshgohel/.rvm/bin:/usr/local/heroku/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/media/work/Environment/Languages/Java/jdk1.7.0_04/bin:/media/work/Environment/BuildTools/apache-maven-3.0.4/bin:/media/work/Environment/BuildTools/apache-ant-1.8.3/bin"
GEM_HOME: "/home/jigneshgohel/.rvm/gems/ruby-1.9.3-rc1"
GEM_PATH: "/home/jigneshgohel/.rvm/gems/ruby-1.9.3-rc1:/home/jigneshgohel/.rvm/gems/ruby-1.9.3-rc1@global"
MY_RUBY_HOME: "/home/jigneshgohel/.rvm/rubies/ruby-1.9.3-rc1"
IRBRC: "/home/jigneshgohel/.rvm/rubies/ruby-1.9.3-rc1/.irbrc"
RUBYOPT: ""
gemset: "
以下是输出:
$rvm list
rvm rubies
=* ruby-1.9.3-rc1 [ i686 ]
# => - current
# =* - current && default
# * - default
答案 0 :(得分:1)
我不使用黄瓜,但在你的例子中
within('#myForm') do
page.has_select?("#event_type", selected: @event_type).should be_true
end
这取决于你的dom,但你不必在id选择器中使用'#', 并且'selected:'应该是选项中的文本,而不是值。
所以它应该是(假设@event_type是你为文本显示的内容)
within('#myForm') do
page.has_select?("event_type", selected: @event_type).should be_true
end
或者我更喜欢
page.should have_select('event_type', selected: @event_type)