【问题标题】:Rspec overriding Capybara 'within' method in CucumberRspec在Cucumber中覆盖Capybara'within'方法
【发布时间】:2015-04-08 17:23:49
【问题描述】:

我正在使用黄瓜和水豚测试在大型消费者网站上创建帐户。当我在常规的 pry 会话中运行我的 capybara 代码时,一切正常。但是当我运行黄瓜测试时,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 并尝试在 pry 中运行 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 的别名匹配器以某种方式覆盖了 capybara 的方法。

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

【问题讨论】:

    标签: ruby-on-rails ruby rspec cucumber capybara


    【解决方案1】:
    page.within
    

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

    【讨论】:

      猜你喜欢
      • 2013-01-10
      • 1970-01-01
      • 1970-01-01
      • 2017-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-02
      相关资源
      最近更新 更多