Pending Tests
Learn how to make the unit test pass using the pending test.
We'll cover the following
If it bothers us to see the integration test continue to fail while we write the unit tests that will make it pass, RSpec allows us to specify a test as pending or to skip it altogether. In RSpec, any it
method defined without a block is considered to be “pending.”
it "bends steel in its bare hands"
The :pending
argument
We can temporarily mark an it
or describe
block as pending by adding :pending
as a second argument after the string as shown below:
it "bends steel in its bare hands", :pending do
#anything
end
The pending
method
Alternatively, we can use the method pending
in the spec:
it "bends steel in its bare hands" do
pending "not implemented yet"
end
Pending tests failures
In RSpec all pending
specs are actually run if there is code in the block part of the spec. The code is executed, with any failure in the pending spec treated as a pending result rather than a failure result. However, if the code in the pending spec passes, we’ll get an error that effectively means, “We said this was pending, but lo and behold, it works. Maybe it’s not actually pending anymore, so please remove the pending status.”
Skipping tests
If we want the spec to not run, which means that we do not check for whether the spec passes, we employ the preceding syntax but use skip
instead of pending
. Alternatively, we can prefix the method name with x
, as in xit
or xdescribe
. A skipped test will not run, meaning that we won’t get any notification if the test suddenly starts to pass.
Get hands-on with 1400+ tech skills courses.