# How do I run only discourse/plugins/poll/spec?

**URL:** https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244
**Category:** Development
**Created:** [July 13, 2016, 7:35pm UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244 "2016-07-13T19:35:38Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![dachary](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dachary/32/119731_2.png) [@dachary](https://meta.discourse.org/u/dachary)
#### Post date: [July 13, 2016, 7:35pm UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/1 "2016-07-13T19:35:38Z")

</div>

Hi,

I’d like to only run the tests at discourse/plugins/poll/spec instead of the whole suite with [bundle exec rake autospec p l=5](https://github.com/discourse/discourse/blob/master/docs/VAGRANT.md). How can I do that ?

Ideally that would not be necessary if `autospec` detected changes made to plugins but my understanding is that it’s not yet able to do so.

Thanks in advance for your help 🙂

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [July 13, 2016, 7:58pm UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/2 "2016-07-13T19:58:17Z")

</div>

Not sure how it works with autospec since I’m running the specs manually most of the time.  
In order to run the plugin specs I’m always setting an environment variable in my IDE: `LOAD_PLUGINS=1`

---

<div class="post-metadata">

### Author: ![dachary](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dachary/32/119731_2.png) [@dachary](https://meta.discourse.org/u/dachary)
#### Post date: [July 13, 2016, 8:26pm UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/3 "2016-07-13T20:26:59Z")

</div>

> [@gerhard](#):
>
> I’m running the specs manually most of the time.

Cool ! How would you manually run the spec of the poll plugin ? My IDE is the CLI 🙂

---

<div class="post-metadata">

### Author: ![dachary](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dachary/32/119731_2.png) [@dachary](https://meta.discourse.org/u/dachary)
#### Post date: [July 13, 2016, 8:33pm UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/4 "2016-07-13T20:33:36Z")

</div>

I tried

```
bundle exec rake autospec plugins/poll/spec/*

```

but it shows

> Randomized with seed 8681 …_…_…\*…

etc. which suggests it runs more than what I’d expect.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [July 13, 2016, 8:40pm UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/5 "2016-07-13T20:40:28Z")

</div>

```bash
# this runs just the specs in one file
LOAD_PLUGINS=1 bundle exec rspec plugins/poll/spec/controllers/posts_controller_spec.rb

# this runs all the specs of the poll plugin
LOAD_PLUGINS=1 bundle exec rspec plugins/poll/spec

```

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [July 13, 2016, 9:00pm UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/6 "2016-07-13T21:00:21Z")

</div>

Another way to do it is via the rake task

> <https://github.com/discourse/discourse/blob/main/lib/tasks/plugin.rake#L47-L48>

`bundle exec rake plugin:spec["poll"]`

---

<div class="post-metadata">

### Author: ![dachary](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dachary/32/119731_2.png) [@dachary](https://meta.discourse.org/u/dachary)
#### Post date: [July 13, 2016, 9:14pm UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/7 "2016-07-13T21:14:33Z")

</div>

It works, thanks ! Where would be the most relevant topic for this information ? Or maybe there is a file in the git repository that should be updated ? The closest thing I found is the [Beginner’s Guide to Creating Discourse Plugins Part 6: Acceptance Tests](https://meta.discourse.org/t/beginner-s-guide-to-creating-discourse-plugins-part-6-acceptance-tests/32619) but it only covers part of the qunit tests.

---

<div class="post-metadata">

### Author: ![dachary](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dachary/32/119731_2.png) [@dachary](https://meta.discourse.org/u/dachary)
#### Post date: [July 13, 2016, 9:16pm UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/8 "2016-07-13T21:16:24Z")

</div>

> [@tgxworld](#):
>
> bundle exec rake plugin:spec[“poll”]

This does not work for me but

```
bundle exec rake plugin:spec poll

```

does.

---

<div class="post-metadata">

### Author: ![dachary](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dachary/32/119731_2.png) [@dachary](https://meta.discourse.org/u/dachary)
#### Post date: [July 13, 2016, 9:27pm UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/9 "2016-07-13T21:27:27Z")

</div>

I proposed a [change to the VAGRANT.md file](https://github.com/discourse/discourse/pull/4326). Not sure it’s right but… here it is anyway 😉

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [May 3, 2019, 3:53am UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/10 "2019-05-03T03:53:39Z")

</div>

The best way to do this is use autospec, it now works properly even with symlinked plugins

```plaintext
bin/rake autospec

```

Save `plugin.rb` file or plugin spec file and it will run.

Be sure to run all plugin migrations with (which will happen magically if you run)

```plaintext
RAILS_ENV=test bin/rake db:migrate

```

---

<div class="post-metadata">

### Author: ![markvanlan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/markvanlan/32/160087_2.png) [@markvanlan](https://meta.discourse.org/u/markvanlan)
#### Post date: [November 19, 2019, 6:15pm UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/11 "2019-11-19T18:15:16Z")

</div>

I was just having issues running plugin specs after running

```plaintext
RAILS_ENV=test bin/rake db:migrate

```

The migrations in the plugin I was testing, were not being run. I then ran:

```plaintext
LOAD_PLUGINS=1 RAILS_ENV=test bundle exec rake db:migrate

```

And now my plugin migrations are up!

It is interesting that **without** `LOAD_PLUGINS=1` and in `development` environment, plugin migrations ran, but in `testing` the migrations were not.

---

<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: [November 19, 2019, 6:24pm UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/12 "2019-11-19T18:24:25Z")

</div>

@sam added some magic here, so if you do `RAILS_ENV=test /bin/rake db:migrate` then it will automatically load plugins. But I think most people don’t use the bin stubs, so this issue keeps happening to different people. Maybe we need to embed the logic in the db:migrate rake task, rather than in the bin stub 🤔

> [@markvanlan](#):
>
> It is interesting that **without** `LOAD_PLUGINS=1` and in `development` environment, plugin migrations ran, but in `testing` the migrations were not.

When we run the test suite normally, we don’t want plugins to be loaded - often plugins override functionality and would cause the core tests to fail.

> <https://github.com/discourse/discourse/blob/858cf5836cbd74e11e551359507b9d99403c7c7f/config/application.rb#L264-L268>

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [November 19, 2019, 11:35pm UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/13 "2019-11-19T23:35:29Z")

</div>

> [@david](#):
>
> But I think most people don’t use the bin stubs,

This makes me very sad … binstubs make life much easier, `bin/unicorn` has a lot of magic in it for example.

---

<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: [November 20, 2019, 12:20am UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/14 "2019-11-20T00:20:23Z")

</div>

> [@sam](#):
>
> `bin/unicorn` has a lot of magic in it for example.

I think most people (well, at least me) just use the standard

```plaintext
rails s

```

Luckily that runs the `rails` binstub thanks to some rails magic

> <https://github.com/rails/rails/blob/79bc9e81c3d47be6336223be39cb3bcaeddc0a39/railties/lib/rails/app_loader.rb#L11>

Discourse’s rails binstub launches the unicorn binstub:

> <https://github.com/discourse/discourse/blob/main/bin/rails#L12>

Unfortunately `rake` does not benefit from the same magic

> [@sam](#):
>
> binstubs make life much easier

I count 4 extra keystrokes 😛 (but yes I could add an alias, or use something like direnv)

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [August 5, 2024, 4:48pm UTC](https://meta.discourse.org/t/how-do-i-run-only-discourse-plugins-poll-spec/47244/15 "2024-08-05T16:48:41Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
