# 为您的插件添加额外的 gem 进行测试

**URL:** https://meta.discourse.org/t/requiring-an-additional-gem-in-your-plugin-for-testing/373028
**Category:** Development
**Created:** [2025年七月5日 16:18 UTC](https://meta.discourse.org/t/requiring-an-additional-gem-in-your-plugin-for-testing/373028 "2025-07-05T16:18:20Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![elmuerte](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elmuerte/32/456517_2.png) [@elmuerte](https://meta.discourse.org/u/elmuerte)
#### Post date: [2025年七月5日 16:18 UTC](https://meta.discourse.org/t/requiring-an-additional-gem-in-your-plugin-for-testing/373028/1 "2025-07-05T16:18:21Z")

</div>

要在你的插件中需要一个额外的 gem，你应该在你的 `plugin.rb` 中添加 `gem "gem-name" ...`。但是如果我在测试期间需要一个额外的 gem 呢？

我只需要它在测试执行期间，所以我不希望将其添加到我的 `plugin.rb` 中。

我不能在 spec 文件或 `plugin_helper.rb` 中做同样的 `gem "gem-name" ...` 技巧，因为这会产生错误

```plaintext
Gem::LoadError:
  rspec-collection_matchers is not part of the bundle. Add it to your Gemfile.

```

我想添加 `rspec-collection_matchers` gem。当然，我可以绕过它并产生不太好的期望值。我想知道是否有一种构造可以让我包含额外的 gem 在测试期间。
