我如何只运行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 存根,所以这个问题会不断出现在不同的人身上。也许我们需要将逻辑嵌入到 db:migrate rake 任务中,而不是放在 bin 存根中:

当我们正常运行测试套件时,我们不希望加载插件——通常插件会覆盖功能,导致核心测试失败。

这让我非常难过……binstubs 让生活轻松很多,例如 bin/unicorn 里就包含了很多魔法。

我想大多数人(至少我是这样)只是使用标准的

rails s

幸运的是,由于 Rails 的一些“魔法”,这会运行 rails binstub。

Discourse 的 Rails binstub 会启动 unicorn binstub:

遗憾的是,rake 无法享受同样的“魔法”。

我数了数,只多了 4 次按键 :P(不过确实可以添加别名,或者使用像 direnv 这样的工具)