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
8 Likes

Another way to do it is via the rake task

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

bundle exec rake plugin:spec["poll"]

9 Likes

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.

1 Like

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

1 Like

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
5 Likes

I was just having issues running plugin specs after running

RAILS_ENV=test bin/rake db:migrate

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

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.

5 Likes

@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 :thinking:

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.

7 Likes

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

5 Likes

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

rails s

Luckily that runs the rails binstub thanks to some rails magic

Discourse’s rails binstub launches the unicorn binstub:

Unfortunately rake does not benefit from the same magic

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

7 Likes

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