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

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. 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 :slight_smile:

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

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

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.

# 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

Another way to do it is via the rake task

bundle exec rake plugin:spec["poll"]

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 but it only covers part of the qunit tests.

This does not work for me but

bundle exec rake plugin:spec poll

does.

I proposed a change to the VAGRANT.md file. Not sure it’s right but… here it is anyway :wink:

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

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)

RAILS_ENV=test bin/rake db:migrate

У меня только что возникли проблемы с запуском спецификаций плагинов после выполнения

RAILS_ENV=test bin/rake db:migrate

Миграции в плагине, который я тестировал, не выполнялись. Тогда я выполнил:

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

И теперь миграции моего плагина применены!

Интересно, что без LOAD_PLUGINS=1 и в окружении development миграции плагинов выполнялись, но в testing они не запускались.

@sam добавил здесь немного магии, так что если вы выполните RAILS_ENV=test /bin/rake db:migrate, плагины будут автоматически загружены. Но я думаю, что большинство людей не используют bin-заглушки, поэтому эта проблема продолжает возникать у разных пользователей. Возможно, нам нужно внедрить эту логику непосредственно в задачу rake db:migrate, а не в bin-заглушку :thinking:

При обычном запуске тестового набора мы не хотим загружать плагины — часто они переопределяют функциональность и могут привести к сбоям основных тестов.

Это меня очень огорчает… binstubs значительно облегчают жизнь, например, bin/unicorn содержит в себе много «магии».

Думаю, большинство людей (ну, по крайней мере я) просто используют стандартную команду:

rails s

К счастью, она запускает binstub rails благодаря некоторой магии Rails:

Binstub rails в Discourse запускает binstub unicorn:

К сожалению, rake не получает преимуществ от той же магии.

Я насчитал всего 4 лишних нажатия клавиш :stuck_out_tongue: (хотя, да, я мог бы добавить алиас или использовать что-то вроде direnv).