Como posso executar apenas 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

Estava tendo problemas para executar os specs de plugins após rodar

RAILS_ENV=test bin/rake db:migrate

As migrações do plugin que eu estava testando não estavam sendo executadas. Então, executei:

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

E agora as migrações do meu plugin estão atualizadas!

É interessante que sem LOAD_PLUGINS=1 e no ambiente development, as migrações do plugin foram executadas, mas em testing elas não foram.

@sam adicionou um pouco de mágica aqui, então se você executar RAILS_ENV=test /bin/rake db:migrate, os plugins serão carregados automaticamente. Mas acho que a maioria das pessoas não usa os stubs do bin, então esse problema continua acontecendo com diferentes pessoas. Talvez precisemos incorporar a lógica na tarefa rake db:migrate, em vez de nos stubs do bin :thinking:

Quando executamos a suíte de testes normalmente, não queremos que os plugins sejam carregados — frequentemente os plugins sobrescrevem funcionalidades e causariam falhas nos testes do núcleo.

Isso me deixa muito triste… os binstubs tornam a vida muito mais fácil, por exemplo, o bin/unicorn tem muita mágica nele.

Acho que a maioria das pessoas (bem, pelo menos eu) usa apenas o padrão

rails s

Felizmente, isso executa o binstub do rails graças a alguma mágica do Rails

O binstub do Rails do Discourse inicia o binstub do unicorn:

Infelizmente, o rake não se beneficia da mesma mágica

Eu conto 4 teclas extras :stuck_out_tongue: (mas sim, eu poderia adicionar um alias ou usar algo como direnv)