What are the advantages and disadvantages of using expectations over assertions with MiniTest?

StackOverflow https://stackoverflow.com/questions/20063341

  •  31-07-2022
  •  | 
  •  

Question

I'm new to BDD and MiniTest and would like to know why using expectations may be better or worse than using assertions. Are expectations simply more readable? It looks like if expectations are used messages can't be included.

The MiniTest documentation doesn't provide any clarity on what expectations are for and I wasn't able to find much written on why these two styles exist.

I did find that expectations may be referred to as "fluent assertions" in the question Is there a "should" minitest gem?

Was it helpful?

Solution

The question of readability is subjective. This is really a matter of preference. Some prefer assertions:

ruby assert_equal "Joe Smith", person.name

While others will prefer expectations:

ruby person.name.must_equal "Joe Smith"

Expectations are neither better nor worse than assertions. In fact, under the hood they are the same thing. The expectation method calls the assertion method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top