Rspec 覆盖黄瓜中的水豚'within'方法



我正在测试在一个大型消费者网站上使用黄瓜和水豚创建一个帐户。当我在一个常规的窥探会话中运行我的水豚代码时,一切都正常。但当我运行黄瓜测试时,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并尝试在priry中运行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

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

相关内容

最新更新