简体   繁体   English

Rails 4 / RSpec-创建我自己的自定义参数以通过以包含/排除某些测试是否运行?

[英]Rails 4 / RSpec - Create my own custom arguments to pass to include/exclude certain tests from running?

My app uses Braintree to process payments. 我的应用程序使用Braintree处理付款。 Unfortunately the fake_braintree gem is depreciated with the current braintree API, so I am forced to hit the braintree sandbox servers with my tests, which is extremely slow (if anyone can help with that issue or recommend an alternative, that'd be awesome too). 不幸的是,fake_braintree gem已被当前的Braintree API折旧了,因此我被迫在我的测试中进入Braintree沙箱服务器,这非常慢(如果有人可以帮助解决该问题或推荐替代方案,那也很棒) 。

My question is, could I group or tag all my tests that hit Braintree servers, and not run them by default, and specify an argument to run all tests including those? 我的问题是,我可以对所有打过Braintree服务器的测试进行分组或标记,而不是默认情况下不运行它们,并指定一个参数以运行包括这些的所有测试吗? So ideally I'd want the 'rspec' command to skip those tests, and then running 'rspec --include-braintree' to run all my tests, including the ones that hit the braintree servers. 因此,理想情况下,我希望'rspec'命令跳过那些测试,然后运行'rspec --include-braintree'来运行我的所有测试,包括那些击中了脑树服务器的测试。

I feel like this would be a good happy medium so I don't sit around waiting on external API calls every time I run my test suite. 我觉得这将是一个很好的选择,所以我不必每次运行测试套件时都在等待外部API调用。

Yes, you can use: 是的,您可以使用:

# spec/spec_helper.rb
RSpec.configure do |config|
  config.filter_run_excluding braintree: true unless ENV['BRAINTREE']
end

Mark a test with the tag (or an entire block if you want): 用标签标记测试(如果需要,则标记整个块):

it "does stuff", braintree: true do
end

And you can easily do: BRAINTREE=1 rspec to run tests including braintree tests 您可以轻松做到: BRAINTREE=1 rspec可以运行包括braintree测试在内的测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM