我刚刚注意到,设置了默认值后,在请求前无法更改值。RSpec请求测试 - 在模拟发送请求之前分配更改值
当我检查处理此请求的方法内的值时,它显示event.data.object.closed = false
。
以下代码仅仅是一个例子。
require 'rails_helper'
describe "stripe_invoice_created_webhook", type: :request do
let(:invoice){ create(:invoice, account_id: account.id) }
let(:account){ create(:account,
stripe_customer_id: event.data.object.customer)}
let(:event){ StripeMock.mock_webhook_event('invoice.created', {
closed: false
}) }
it 'responds 200 to invoice_created webhook with valid endpoint' do
event.data.object.closed = true
post '/stripe-events', event.as_json
expect(response.status).to eq 200
end
end
任何想法如何正确发送一些
===更新(2016年11月17日)===========
的主要问题是前更改值如何有效更改模拟值?
我可以写每个类似的东西。
event = StripeMock.mock_webhook_event('invoice.created', {closed: true })
它的工作原理,主要问题是,我怎样才能使它更清洁与let(:foo)
像往常一样?
你能分享你想要编写代码测试? –