# Conseils pour écrire des tests Ruby pour les plugins

**URL:** <https://meta.discourse.org/t/advice-on-writing-ruby-tests-for-plugins/108110>\
**Category:** Development\
**Created:** [Février 1, 2019, 9:52 UTC](https://meta.discourse.org/t/advice-on-writing-ruby-tests-for-plugins/108110 "2019-02-01T09:52:27Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [Février 1, 2019, 10:18 UTC](https://meta.discourse.org/t/advice-on-writing-ruby-tests-for-plugins/108110/2 "2019-02-01T10:18:57Z")

</div>

> [@kleinfreund](#):
>
> `bundle exec rake plugin:spec["disraptor"]` : Errors with
> 
> ```plaintext
> zsh: no matches found: plugin:spec[disraptor]
> 
> ```

You need to use the **directory** name for you plugin here. So if it’s under `/plugins/discourse-disraptor`, then you run `bundle exec rake plugin:spec[discourse-distraptor]`

> [@kleinfreund](#):
>
> This makes the method untestable because I would need to test actual plugin data from the store which I cannot rely on being there

Why not just put the data in the database? Before testing the `get_routes` function, run this:

```plaintext
PluginStore.set(MyPlugin::PLUGIN_NAME, 'key', 'valuefortest')

```

The database is cleaned up automatically after each individual test. (tests run in a DB transaction, which is rolled back automatically)

---

_[View the full topic](https://meta.discourse.org/t/advice-on-writing-ruby-tests-for-plugins/108110)._
