RSpec does not provide a way to get the number of examples that were
excluded by its inclusion or exclusion filters, but there’s a different
mechanism that will do what you want. Instead of filtering the examples
(which excludes them from consideration entirely), you can skip them, which
prevents the body of the example from running, sets the example’s status to
:pending, will print the example in yellow in the formatter output, and
will count the example in the summary total printed at the end (e.g. “500
examples, 0 failures, 20 pending”). Normally, :skip metadata will cause an
example to be skipped
<https://relishapp.com/rspec/rspec-core/v/3-7/docs/pending-and-skipped-examples/skip-examples#skipping-using-metadata>,
but you’ve overwritten it to cause :skip to cause examples to be filtered
out.
Here’s my suggestion for how to wire this up.
First, tag any examples that depend upon xcode with :uses_xcode (rather
than :skip), e.g.:
it "uses a feature of xcode", :xcode do
# ...end
it "does not use xcode at all" do
# ...end
Then use define_derived_metadata to automatically tag these examples with
:skip if you are not running on OS X:
# spec_helper.rbrequire 'rbconfig'
RSpec.configure do |config|
unless RbConfig::CONFIG['host_os'] =~ /darwin/
config.define_derived_metadata(:xcode) do |meta|
meta[:skip] = "Can only be run on OS X"
end
endend
The “Can only be run on OS X” bit will be printed in the output as the
reason the examples are pending.
HTH,
Myron
On Tue, Dec 19, 2017 at 3:06 AM, Jan P. <[email protected]> wrote:
> RSpec has this nice method to exclude individual tests/examples or whole
> groups by using filter_run_excluding in the config, then tagging the
> examples:
>
> https://relishapp.com/rspec/rspec-core/v/3-7/docs/
> filtering/exclusion-filters
>
> RSpec.configure do |c|
> c.filter_run_excluding :skip => trueend
> RSpec.describe "something" do
> it "does one thing" do
> end
>
> it "does another thing", :skip => true do
> endend
>
> "does one thing" will be checked,
> "does another thing" will not.
>
>
> We are using this, for example, to skip some tests depending on the
> platform the test is run on by wrapping the c.filter_run_excluding :skip
> => true in an if block:
>
> If Mac,
> no exclusions, if Ubuntu,
> exclude tests that do something with Xcode.
>
>
> Right now the numbers of passing examples/test is just lower if the
> exclusion filter is used, but it would be nice to see the actual number of
> tests that are skipped.
>
> Is there a way to get the number of tests skipped by this method during a
> test run?
>
> Thanks,
>
> Jan
>
> --
> You received this message because you are subscribed to the Google Groups
> "rspec" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/rspec/3108ef8e-303d-425b-9b00-ab83dfec7633%40googlegroups.com
> <https://groups.google.com/d/msgid/rspec/3108ef8e-303d-425b-9b00-ab83dfec7633%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/CADUxQmuD4XwYx9MAGgAKhv-VO6GxOBK3hop9TOzbD2MBw-2Ctg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.