Beginner’s Guide to Creating Discourse Plugins Part 6: Acceptance Tests



q: how to run the ruby tests tests for a plugin?

i am trying to run the tests for discourse-github-linkback, but i have no idea how.

After some stackoverflow i tried this (and i got some errors):

~/discourse$ bundle exec rspec ./plugins/discourse-github-linkback/spec/lib/github_linkback_spec.rb 

An error occurred while loading ./plugins/discourse-github-linkback/spec/lib/github_linkback_spec.rb.
Failure/Error: CoreExt::ActiveSupport.without_bootsnap_cache { super }

  uninitialized constant GithubLinkback
# ./plugins/discourse-github-linkback/spec/lib/github_linkback_spec.rb:3:in `<top (required)>'
# ------------------
# --- Caused by: ---
# NameError:
#   uninitialized constant GithubLinkback
#   ./plugins/discourse-github-linkback/spec/lib/github_linkback_spec.rb:3:in `<top (required)>'
No examples found.

Randomized with seed 60987

Finished in 0.02025 seconds (files took 3.36 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

Randomized with seed 60987

Note that i see the plugin in the local discourse dev admin page, so i hope it is correctly installed (into ~discourse/plugins/

(Sam Saffron) #12

Simplest way, run bin/rake autospec, and save the file


From what i see, doing cd ~/discourse and then running

runs all the tests for discourse.

On my ubuntu 18.04 VM with i5 6500, this has been running for half an hour already.
It feels wrong to run the whole tests suite when i only want to run the tests in that one plugin.
(this is especially so when i probably will modify my tests again, at least a few times)

Did i do something wrong?

(Sam Saffron) #14

Let me guess, you are symlinking your plugin vs checking out directly to the path under plugins



tbp@tbp-linux-dev:~$ cd ~/discourse/plugins/
git clone -b allow-all-user-repositories-wildcard
tbp@tbp-linux-dev:~/discourse/plugins$ ll
total 40
drwxr-xr-x 10 tbp tbp 4096 mai 13 21:48 ./
drwxr-xr-x 20 tbp tbp 4096 mai 13 21:18 ../
drwxr-xr-x  6 tbp tbp 4096 mai 13 20:29 discourse-details/
drwxr-xr-x  6 tbp tbp 4096 mai 13 21:48 discourse-github-linkback/
drwxr-xr-x  6 tbp tbp 4096 mai 13 20:29 discourse-local-dates/
drwxr-xr-x  9 tbp tbp 4096 mai 13 20:29 discourse-narrative-bot/
drwxr-xr-x  7 tbp tbp 4096 mai 13 20:29 discourse-nginx-performance-report/
drwxr-xr-x  5 tbp tbp 4096 mai 13 20:29 discourse-presence/
drwxr-xr-x  3 tbp tbp 4096 mai 13 20:29 lazyYT/
drwxr-xr-x  9 tbp tbp 4096 mai 13 20:29 poll/

(Sam Saffron) #16

Can you confirm you tried saving the spec file once it was running, cause it is meant to interrupt stuff and start running the plugin spec?


since the initial bin/rake autospec is still running, there was/is no “save spec file” message yet.
also, by running bin/rake autospec --help, i saw no --save option.

I didn’t understand what save the file meant, so my full command was bin/rake autospec > spec.rb <- probably this is wrong

(Sam Saffron) #18

I meant in Vim or whatever you use, save the spec file, there is a watcher on it that will invoke the spec runner once it is saved.

Also see: How do I run only discourse/plugins/poll/spec?


Finally i did it :^).

With the help of that link, i ran the tests by using this command:
bundle exec rake plugin:spec["discourse-github-linkback"]
and, ofc, i was in ~/discourse when doing that.

Thanks for all your help @sam!

(1st PR for discourse-plugin babyyyyy :tada:)


My Qunit-Tests aren’t executed or at least they don’t show me any output.
They finish with the following:

No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself.
Check the details on how to adjust your build configuration on:

Travis.CI Result - Travis CI - Test and Deploy Your Code with Confidence
Test-File - GitHub - kokoro-ko/discourse-humble-box

I am not that skilled with CI yet and haven’t found my mistake by now.

(David Taylor) #21

Do your tests pass if you visit /qunit on your development environment? How about if you run rake plugin:qunit[discouse-humble-box]?

LOAD_PLUGINS=1 QUNIT_SKIP_CORE=1 QUNIT_SINGLE_PLUGIN='discouse-humble-box' /home/ravenstorm/.rbenv/versions/2.5.3/bin/rake qunit:test
Chrome is not installed. Download from
rake aborted!
Command failed with status (1): [LOAD_PLUGINS=1 QUNIT_SKIP_CORE=1 QUNIT_SIN...]
/home/ravenstorm/discourse/lib/tasks/plugin.rake:117:in `block in <main>'
Tasks: TOP => plugin:qunit

(Penar Musaraj) #23

Install Chrome and then give it another try.


Oh sorry i’ve pasted an old error code which i had stored in a pastebin :frowning_face:

navigate to http://localhost:60099/qunit?qunit_single_plugin=discouse-humble-box&qunit_skip_core=1&seed=187998423095278311109560784485973475676
Tests timed out
rake aborted!
Command failed with status (124): [node /home/ravenstorm/discourse/vendor/ass...]
/home/ravenstorm/discourse/lib/tasks/qunit.rake:89:in `block in <main>'
Tasks: TOP => qunit:test
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [LOAD_PLUGINS=1 QUNIT_SKIP_CORE=1 QUNIT_SIN...]
/home/ravenstorm/discourse/lib/tasks/plugin.rake:117:in `block in <main>'
Tasks: TOP => plugin:qunit

(Penar Musaraj) #25

Try running the test in the browser as David suggested earlier. So, in your browser, when the server is running, go to your-local-site/qunit. Very often, for me, timeouts in the Terminal have errors in JS that I could see and fix after visiting /qunit on the browser.


Thats one of the problems :smiley:

I can’t find acceptance tests on my /qunit

Even after turning on all modules and filtering it with box and humble nothing is here :slightly_frowning_face:

(David Taylor) #28

Try renaming the folder to test/javascripts/acceptance - that extra s is quite important!

You might need to do rm -rf tmp, and then restart your development server for the changes to take effect.

(Penar Musaraj) #29

Do what David said above (rename the folder to javascripts), but ALSO, change the name of your plugin in plugin.rb to discourse-humble-box to match the folder name. I did these two changes, and I see tests locally:


Yea i’ve seen those as well now, but these aren’t really eye-opening results tbh.

But gotta dig deeper and lookup why these errors are shown.

Thanks for the help guys.
For example the second test case… if i am testing it myself by hand… it works, but running it on qunit it fails :frowning:

Ok, got a brief idea whats bringing me the errors and it confuses me:
http://localhost:9292/ in my browser has the plugin installed and working
http://localhost:9292/qunit the test shows, that the plugin is not even installed

I thought these two are using the same enviroment ?
Could this be caused by my local dev-enviroment since it’s not using docker and I’m not able to install the plugin like Install Plugins in Discourse ? It’s just sitting in the plugins folder like the others.


Any idea how this is possible ?