Rspec 覆盖 Cucumber 中的 Capybara 'within' 方法

Rspec overriding Capybara 'within' method in Cucumber

我正在测试使用黄瓜和水豚在大型消费者网站上创建帐户。当我 运行 我的水豚代码在常规的窥探会话中时,一切正常。但是当我 运行 黄瓜测试时, within 块似乎没有 运行 并且没有填写注册表单。

env.rb

require 'capybara/cucumber'
require 'selenium-webdriver'

Before do
  Capybara.default_driver = :selenium
end

test.feature

Scenario: Test consumer site account creation
* I create a new example.com account

step_definition.rb

When(/^I create a new account$/) do
  visit 'http://example.com/myaccount'
  find("#cboxClose").click if page.has_css?("#cboxClose")

  require 'pry';binding.pry
  within("form[name='newCustomer']") do
    random_letters = SecureRandom.urlsafe_base64(5)
    fill_in "Email Address", :with => "test-#{random_letters}@example.com"
    fill_in "Create Password", :with => "Password123"
    fill_in "Confirm Password", :with => "Password123"
    click_on "Create Account"
  end
end

当我 运行 cucumber 并尝试 运行 撬开 within 块时,我得到这个:

#<RSpec::Matchers::AliasedMatcher:0x007ff5e86b16e8
 @base_matcher=
  #<RSpec::Matchers::BuiltIn::BeWithin:0x007ff5e86b1710
   @delta="form[name='newCustomer']">,
 @description_block=
  #<Proc:0x007ff5e4c34d08@/Users/anthonychung/.rvm/gems/ruby-2.1.2/gems/rspec-expectations-3.2.0/lib/rspec/matchers.rb:245 (lambda)>>

所以我怀疑 RSpec 的别名匹配器以某种方式覆盖了水豚的内部方法。

当我尝试执行 within(:css, "form[etc.]") 时,出现参数错误 ArgumentError: wrong number of arguments (2 for 1)

page.within

我觉得自己很笨,但至少我想通了。