Clay Morton
Clay Morton

Reputation: 330

How to separate Rails Rspec tests that make api calls

I am writing rspec features tests that make live api calls. I want the capacity to run all non-api tests with the simple command rspec, and then some way to call the live api tests separately. Perhaps there is a way to use ARGV or to exclude some tests from the general rspec namespace and still have full features test capabilities. Any thoughts?

Upvotes: 4

Views: 608

Answers (1)

Mikhail Nikalyukin
Mikhail Nikalyukin

Reputation: 11967

You need to tag your API specs, take a look at the RSpec documentation: https://www.relishapp.com/rspec/rspec-core/v/2-4/docs/command-line/tag-option

If you want to use environment variables for filtering:

spec_helper.rb

RSpec.configure do |c|
  c.filter_run_excluding api: true unless ENV['ALL']
end

With this setup rspec spec command will filter out all the specs marked as api.

If you want to run whole suite including API specs ALL=true rspec spec.

Upvotes: 3

Related Questions