Disable a Group of Tests in Rspec

Disable a group of tests in rspec?

To disable a tree of specs using RSpec 3 you can:

before { skip }
# or
xdescribe
# or
xcontext

You can add a message with skip that will show up in the output:

before { skip("Awaiting a fix in the gem") }

with RSpec 2:

before { pending }

RSpec: Can I disable certain shared examples tests?

One option is to add the allowed upload formats to your controller and have the tests introspect your controllers. This will likely DRY up both the production and test code.

class ApplicationController
def self.upload_formats
[:yaml, :json, :csv]
end
end

class OtherController < ApplicationController
def self.upload_formats
[:yaml, :json]
end
end

shared_examples 'it accepts uploads' do
let(:formats) { described_class.upload_formats }

...
end

This might be too DRY; if self.upload_formats is missing a format the tests will not catch it.


You could add a flag to the shared examples and pass in which formats it should check. If the test for each format is similar, this becomes a simple loop.

shared_examples 'it accepts uploads' do |formats: [:yaml, :json, :csv]|
formats.each do |format|
let(:format) { format }

context "in #{format}" do
...
end
end
end

Most tests will remain unmodified and use the defaults.

it_behaves like 'it accepts uploads'

Your exceptions can specify their formats.

it_behaves like 'it accepts uploads', formats: [:yaml, :json]

If it's more complicated than that, you may wish to break the shared test down into a separate test for each format. The original shared test runs all the individual shared tests. The outliers can pick and choose.

shared_examples 'it accepts uploads in all formats' do
it_behaves_like 'it accepts yaml uploads'
it_behaves_like 'it accepts json uploads'
it_behaves_like 'it accepts csv uploads'
end

Again, most tests remain the same.

it_behaves_like 'it accepts uploads in all formats'

And the outliers can run tests individually.

it_behaves_like 'it accepts yaml uploads'
it_behaves_like 'it accepts json uploads'

This has the additional advantages of breaking up what might be a large shared example, and allowing individual shared examples to be further customized.


And you can combine the two for convenience.

shared_examples 'it accepts uploads' do |formats: [:yaml, :json, :csv]|
it_behaves_like 'it accepts yaml uploads' if formats.include?(:yaml)
it_behaves_like 'it accepts json uploads' if formats.include?(:json)
it_behaves_like 'it accepts csv uploads' if formats.include?(:csv)
end

How to disable testing of rswag files with rspec, but only use them for documentation?

The quickest solution I could figure out was running tests under a specific folder. In my case I have integration tests under spec/ folder and rswag tests under spec/requests/, so I can do it like this: rspec --pattern spec/*_spec.rb

In your case should be rspec --pattern spec/integration/*_spec.rb.

See more about the --pattern option here.

how to skip x number of tests in rspec

I don't think something like this would work, since RSpec runs test in random order by default to ensure they are not dependent on their order. Maybe a fitting solution would be to note down the failing tests and running just those. You can run specific tests like this:

rspec /spec/controllers/example_controller_spec.rb:19

Where 19 is the line that your test is located at. After you fixed all failing tests, you could then rerun the whole test suite to make sure everything is fine.

Programmatically skip a test in RSpec

I asked in the rspec mailing list, and it turns out skip 'reason' does the trick. The example is marked as pending, which is not ideal, but that answers the question.

Rspec run all tests except a specific folder

Use an --exclude-pattern, they're quite convenient:

https://www.relishapp.com/rspec/rspec-core/v/3-3/docs/configuration/exclude-pattern

One of the nice things about them:

The --exclude-pattern flag accepts shell style glob unions

So you could do something like rspec --exclude-pattern "spec/{foldername1,foldername2}/**/*_spec.rb"

Rspec command to skip view specs

You should try something like this -

Use an --exclude-pattern

rspec --exclude-pattern "spec/views/**/*_spec.rb"

https://www.relishapp.com/rspec/rspec-core/v/3-3/docs/configuration/exclude-pattern

Can I stop an RSpec test run in the middle?

One can stop the RSpec test in the middle by pressing ctrl-C twice.



Related Topics



Leave a reply



Submit