Implementing a Basic Confidence-Checking System
Learn to implement a basic confidence-checking system in our application on how to avoid duplicative tests for our Rails application.
We'll cover the following...
We could just throw #CONFIDENCE CHECK
before these assertions, but we don’t think this sort of code comment is nearly as useful as actual code. Let’s make a method that will indicate which assertions are checking that we can run our test and which assertions are the actual test.
We’ll do that by assuming the existence of a method called confidence_check
that takes a block and executes the code inside that block.
# test/controllers/widgets_controller_test.rb× # refute_nil widget× # assert_redirected_to widget_path(widget)→ confidence_check do→ refute_nil widget→ assert_redirected_to widget_path(widget)→ end
Now, the test makes it clear that refute_nil
and assert_redirected_to
are only there to double-check that the basics are working before we do the real assertion, which follows.
In addition to demarcating the code, we need to see a ...