not run a spec by default unless flag is set - ruby-on-rails

We have a set of controller specs to ensure that our api is working as anticipated.
I'd also like to add a performance test that is not run by default but could be run (perhaps even as simply as via the line number like rspec spec/controllers/item_controller.rb:50. Some of these could be a couple of seconds so we don't want to be running every time (4 seconds x 30 actions adds up).
Is there a way to exclude a spec or describe block by default but have it be run via line number?

Add a tag to each of your slow tests to identify them, e.g.,
it 'should do something', slow: true do
#does something
end
Then simply run rspec with the exclusive tag option:
rspec --tag ~slow
This will run all tests that don't have the slow tag associated with them. To run the slow tests in conjunction with your other tests simply invoke without the tag option.
It might be preferable to have this as the default behaviour, in which case modify the .rspec configuration file and add the following to it:
--tag ~slow
Now by default when you simply run rspec all tests will run except the ones tagged as being slow. To run the slow tests explicitly set the flag:
rspec --tag slow
Though this will exclude all tests that aren't tagged as being slow.

Related

Run only one test on CircleCI (Rails)

Sometimes I have a broken test on CircleCI, where the error can't be replicated locally. Instead of waiting for the whole suite to run, I'd like to run that one test individually. (I know I can ssh in, but that's time-consuming and running it that way wouldn't exactly replicate the usual automated test sequence.)
My aim is to make a temporary config commit to run just one test (ideally just a test method, but the whole class would be fine too). I can think of two possible solutions: (A) edit app.rake to make the default rake task run a single test; or (B) edit circle.yml to run just the one test from command-line using rake test. Any clue on either of these?

Run single system test

To run a single test in Rails, we normally do:
rails test TEST=test/system/invitation_test.rb
But that doesn't work with system tests. Neither do this work:
rails test:system TEST=test/system/invitation_test.rb
With both those commandos above, all system tests (files) are run.
So my question is, how can I run a single system test?
As a side note, to run (all) system tests in Rails, you need to append :system to test.
rails test:system
While rails test doesn't seem to work if you want to run your system tests (you need to append test with :system), if you only want to run a single test it does seem to work:
rails test test/system/my_little_test.rb

How to Define order of testcase files execution in Rspec?

Is there a way in Rspec by which I can specify the order of exection by giving file input?
I have a .txt file which contain list of files in ordered manner. I want Rspec to execute testing of files in order specified in .txt file.
I am using CAPYBARA with Rspec (USING_CAPYBARA=true rspec -r turnip/rspec -r turnip/capybara spec/features/../../.)
EDIT:
Whenever the features fails on my CI tool, I get the list of file names in sequence which was executed by my CI tool. When I simply run my failing test it works fine, but to debug such issue I need to run the test files in same sequence as the CI tool. So I think if Rspec doesn't provide a way to rerun the specs files in specific sequence I guess I need to write some script for it then
RSpec tells you which seed it used to randomize the order. Look for something like:
Randomized with seed 47311.
You can use that number to re-run specs in the same order:
$ spec spec --seed 47311 # or --order rand:47311
From the documentation:
Use the --order option to tell RSpec how to order the files, groups, and
examples. The available ordering schemes are defined and rand.

Rspec: Skipping an exclusion filter

I have some slow RSpec tests that I've tagged with :slow. I've set RSpec up to skip them default by adding the line config.filter_run_excluding slow: true to my RSpec configuration. And I can run the slow tests by running rspec --tag slow.
But how can I run all the tests using one command, including slow and non-slow tests? I can't figure it out from the docs.
You can find a similar question here : Command line to run all examples in RSpec, including ones that are filtered out?
In few words, this feature doesn't exist on rspec but you can use env variable :
RSpec.configure do |c|
c.filter_run_excluding slow: true unless ENV['ALL']
end
Call ALL=1 rspec will run all the specs including the slow tag.

Why is rake running specs and features twice?

For a couple of months now I have the problem that running rake spec cucumber (or each one separately) runs the specs and/or features always twice. It's kind of annoying, since it makes me wait longer.
Now if I run rspec or cucumber then the specs/or features only run a single time.
I'm not sure what details I could provide here, so I'll just link the repo here https://github.com/deiga/new-Roydon/tree/feature/allow-orders-without-registeration

Resources