Comment exécuter uniquement 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

Je rencontrais des problèmes pour exécuter les spécifications de plugins après avoir lancé

RAILS_ENV=test bin/rake db:migrate

Les migrations du plugin que je testais n’étaient pas exécutées. J’ai ensuite lancé :

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

Et mes migrations de plugin sont maintenant à jour !

Il est intéressant de noter que sans LOAD_PLUGINS=1 et dans l’environnement development, les migrations de plugin s’exécutaient, mais pas dans l’environnement testing.

@sam a ajouté une touche de magie ici, donc si vous exécutez RAILS_ENV=test /bin/rake db:migrate, les plugins seront chargés automatiquement. Mais je pense que la plupart des gens n’utilisent pas les scripts bin/, ce qui fait que ce problème continue d’affecter différentes personnes. Peut-être devrions-nous intégrer la logique directement dans la tâche rake db:migrate plutôt que dans le script bin/ :thinking:

Lorsque nous exécutons normalement la suite de tests, nous ne voulons pas que les plugins soient chargés : souvent, les plugins remplacent des fonctionnalités et pourraient faire échouer les tests du noyau.

Cela me rend très triste… les binstubs facilitent grandement la vie, bin/unicorn contient par exemple beaucoup de magie.

[quote=“sam, post:13, topic:47244”]
bin/unicorn contient par exemple beaucoup de « magie ». [/quote]

Je pense que la plupart des gens (moi en tout cas) utilisent simplement la commande standard

rails s

Heureusement, cela exécute le binstub rails grâce à une certaine magie de Rails.

Le binstub rails de Discourse lance le binstub unicorn :

Malheureusement, rake ne bénéficie pas de la même magie.

Je compte 4 frappes de clavier en plus :stuck_out_tongue: (mais oui, je pourrais ajouter un alias ou utiliser quelque chose comme direnv).