【问题标题】:Testing Stripe works with js: true, but it makes other components work incorrectly测试 Stripe 与 js 一起工作:是的,但它使其他组件无法正常工作
【发布时间】:2015-04-25 00:39:21
【问题描述】:

测试条带框架需要打开 Javascript,但是当我在 it 方法中发送 js: true 时,其他组件如 visitfill_in 将停止以之前的方式工作。

这是我的代码:

def sign_up(subdomain)
    visit root_url(subdomain: false)
    visit new_account_path
    fill_in 'Name', with: 'Ryan'
    fill_in 'Email', with: 'test@test.com'
    fill_in 'Password', with: 'password'
    fill_in 'Password confirmation', with: 'password'
    fill_in 'Subdomain', with: subdomain
    click_button 'Create Account'
end

sign_up 方法中,visit new_account_pathjs: true 之前可以工作,但现在不行了。

我正在转js: true,方法如下:

it 'shows the user can upgrade his account with valid card number, expiration and CVC', js: true do
    fill_in "card_number", :with => "4242424242424242"
    fill_in "card_expiry_month", :with => "05"
    fill_in "card_expiry_year", :with => "2015"
    fill_in "card_cvc", :with => "123"
    click_button 'Upgrade Your Account'
    expect(page).to have_content "Update Your Payment Information"
end

我一直在寻找解决方案很长一段时间,但到目前为止无法解决这个问题。

【问题讨论】:

  • 那条线上到底是什么失败了?您是否收到错误消息或其他信息?
  • Failure/Error: click_button 'Upgrade Your Account' Stripe::InvalidRequestError: 这是我得到的错误。
  • 好的,stripe 需要知道允许的 url 列表吗?测试期间使用的 url 是这些允许的 url 之一吗?
  • 我不知道你在问什么:但是有什么方法可以在不执行 js: true 的情况下测试 stripe。因为当我做js: true 时,它会导致问题:它不允许我fill_in 一些我在问题中描述的元素。

标签: ruby-on-rails testing rspec stripe-payments


【解决方案1】:

根据您的评论,您从 stripe 的 API 收到错误:Stripe::InvalidRequestError

根据他们的 API (https://stripe.com/docs/api#errors):

当您的请求无效时会出现无效请求错误 参数。

我敢打赌,您对 Stripe 的请求实际上有问题,而不是您编写的 Capybara (?) 规范。

我写了一篇关于使用 RSpec 和 Capybara for Stripe 编写验收测试的博客文章。你可以view it here

【讨论】:

  • @ArslanAli 你在使用 turbolinks 吗?
  • 是的。我是!但这和测试有关系吗?
  • 我已经阅读了其他几个堆栈溢出/github 问题,其中详细说明了 turbolinks 和条带存在问题。也许尝试禁用 turbolinks,看看问题是否在您的测试中仍然存在
猜你喜欢
  • 2015-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-31
  • 2020-09-11
  • 2019-02-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多