Capybara select 语句不适用于 Rspec

发布于 2024-10-22 04:42:06 字数 1141 浏览 1 评论 0原文

将 Capybara 与 Rails 3、Rspec 和 Cucumber 一起使用,

当我使用 select 语句时,例如

    select("Unspecified", :from=> 'record_family_')

我收到错误,参数数量错误 (2 for 3)。同样,如果我省略第二个参数,我会得到错误的参数数量(1 代表 3)。无论我使用 RSpec 还是 Cucumber,都会发生这种情况。如果我切换到 Webrat,一切都会正常。

详细信息:Rails 3.0.4、rspec-core 2.5.1、rspec-rails 2.5.0、capybara 0.1.4.2、rack 1.2.1

堆栈跟踪的前几行(路径简化)是:

wrong number of arguments (1 for 3) (ArgumentError)
actionpack-3.0.5/lib/action_view/helpers/form_options_helper.rb:131:in `select'
capybara-0.4.1.2/lib/capybara/dsl.rb:104:in `select'
step_definitions/sim_db_steps.rb:412:in `block in <top (required)>'
cucumber-0.10.0/lib/cucumber/core_ext/instance_exec.rb:48:in `instance_exec'
cucumber-0.10.0/lib/cucumber/core_ext/instance_exec.rb:48:in `block in cucumber_instance_exec'
cucumber-0.10.0/lib/cucumber/core_ext/instance_exec.rb:69:in `cucumber_run_with_backtrace_filtering'
cucumber-0.10.0/lib/cucumber/core_ext/instance_exec.rb:36:in `cucumber_instance_exec'
cucumber-0.10.0/lib/cucumber/rb_support/rb_step_definition.rb:62:in `invoke'

有什么想法吗?

Using Capybara with Rails 3, Rspec and Cucumber,

When I use the select statement, such as

    select("Unspecified", :from=> 'record_family_')

I get an error, wrong number of arguments (2 for 3). Likewise, if I omit the second argument, I get wrong number of arguments (1 for 3). This happens whether I'm using RSpec or Cucumber. If I switch to Webrat, everything works.

Details: Rails 3.0.4, rspec-core 2.5.1, rspec-rails 2.5.0, capybara 0.1.4.2, rack 1.2.1

The first few lines of the stack trace (with the path simplified) are:

wrong number of arguments (1 for 3) (ArgumentError)
actionpack-3.0.5/lib/action_view/helpers/form_options_helper.rb:131:in `select'
capybara-0.4.1.2/lib/capybara/dsl.rb:104:in `select'
step_definitions/sim_db_steps.rb:412:in `block in <top (required)>'
cucumber-0.10.0/lib/cucumber/core_ext/instance_exec.rb:48:in `instance_exec'
cucumber-0.10.0/lib/cucumber/core_ext/instance_exec.rb:48:in `block in cucumber_instance_exec'
cucumber-0.10.0/lib/cucumber/core_ext/instance_exec.rb:69:in `cucumber_run_with_backtrace_filtering'
cucumber-0.10.0/lib/cucumber/core_ext/instance_exec.rb:36:in `cucumber_instance_exec'
cucumber-0.10.0/lib/cucumber/rb_support/rb_step_definition.rb:62:in `invoke'

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

国际总奸 2024-10-29 04:42:06

感谢 Jonas Niklas 指出了这个问题,即名称空间问题。我间接将 ActionView::Helpers::FormOptionsHelper 包含到测试用例中,以便 ActionView select 与 Capybara 发生冲突。

Thanks to Jonas Niklas for pointing out the problem, a name space issue. I had indirectly included ActionView::Helpers::FormOptionsHelper into the test cases so that the ActionView select was conflicting with the Capybara one.

世界等同你 2024-10-29 04:42:06

我也遇到了 select 的名称空间问题(它使用 kernel 而不是 page.select)。我最终不得不改变这一点:

RSpec.configure do |config|
  config.include Capybara::DSL
  config.include ActionView::Helpers::FormOptionsHelper
end

对此:

RSpec.configure do |config|
  config.include ActionView::Helpers::FormOptionsHelper
  config.include Capybara::DSL
end

只需包含的顺序就可以修复它。

I had a name space issue also with select (it was using kernel instead of page.select). I ended up having to change this:

RSpec.configure do |config|
  config.include Capybara::DSL
  config.include ActionView::Helpers::FormOptionsHelper
end

To this:

RSpec.configure do |config|
  config.include ActionView::Helpers::FormOptionsHelper
  config.include Capybara::DSL
end

Just the ordering of the includes fixed it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文