我正在开发 Rails 4 应用程序,我想为 BrainTree 编写一些测试:
在 Rails 4.0.0 中使用 rspec-rails (2.14.0) 和 capybara (2.1.0)
问题出在路线上,以 Braintree 的形式,我通过了一个 :url
<%= form_for :customer, :url => Braintree::TransparentRedirect.url do |f| %>
现在,当我运行这样的功能测试时:
it 'should make new payment info' do
login
visit new_customer_path
page.fill_in 'customer_credit_card_number', :with => '4111111111111111'
page.fill_in 'customer_credit_card_expiration_date', :with => '01/25'
page.fill_in 'customer_credit_card_cvv', :with => '400'
page.click_button 'Save Payment Info'
page.should have_content('Payment Info Confirmation')
page.should have_content('411111******1111')
end
我在路线上遇到错误:
Failure/Error: page.click_button 'Save Payment Info'
ActionController::RoutingError:
No route matches [POST] "/merchants/fvn6vfc5ptyg2xrp/transparent_redirect_requests"
我也在控制器测试中尝试过这个(使用render_views):
it 'should make new payment info' do
sign_in_as_user
visit new_customer_path
page.fill_in 'customer_credit_card_number', :with => '4111111111111111'
page.fill_in 'customer_credit_card_expiration_date', :with => '01/25'
page.fill_in 'customer_credit_card_cvv', :with => '400'
page.click_button 'Save Payment Info'
save_and_open_page
page.should have_content('Payment Info Confirmation')
page.should have_content('411111******1111')
end
路线上同样的错误...
在浏览器的开发环境中它工作正常,我看起来像我表单中的 :url 选项被水豚忽略了?我想知道是否有人可以帮助我解决这个问题?
当我在该项目上运行测试时,我还为 Braintree with Rails 找到了这些示例应用程序:https ://github.com/braintree/braintree_ruby_examples/blob/master/rails3_tr_devise/spec/controllers/customer_controller_spec.rb。也许我的问题与 Rails 和 rspec 的版本有关?
提前谢谢了!!