v0.10.0
This new version brings some new additions:
New Linter Rule:
Function Call in async assertions
The linter now warns about using Eventually
or Consistently
with a function call. This is because when doing that, Eventually
checks the same returned value again and again, instead of polling by calling the function.
For example:
func slowInt() int {
time.Sleep(time.Second)
return 42
}
It("should test that slowInt returns 42, eventually", func() {
Eventually(slowInt()).WithPolling(time.Millisecond * 100).WithTimeout(time.Second * 2).Equal(42)
})
In the above code, Eventually receives 42 as its argument. Then it polls this value to check if it equal
42. What we really wanted here is:
It("should test that slowInt returns 42, eventually", func() {
Eventually(slowInt).WithPolling(time.Millisecond * 100).WithTimeout(time.Second * 2).Equal(42)
})
Now, Eventually
calls the function until it returns the required value.
Note: The linter ignores function calls that return a function or a channel.
To suppress this warning entirely, add the --suppress-async-assertion=true
command line flag, or the ginkgo-linter:ignore-async-assert-warning
comment.
Improvements and Bug Fixes
Bug Fix: len() comparison
When comparing len() result with a number; e.g.
Expect(len(x) == 5).Should(BeTrue())
the linter used to wrongly fix suggested to replace to
Expect(len(x)).To(Equal(5))
which is also a wrong pattern.
Now, the linter will suggest:
Expect(x).To(HaveLen(5))
Avoid double negative assertions
For patterns like
Expect(boolVal).ShouldNot(Equal(false))
or
Expect(boolVal).ShouldNot(BeFalse())
the linter will suggest
Expect(boolVal).Should(BeTrue())
Support the WithOffset() method
The linter used to ignore patterns like
Expect(len(x)).WithOffset(1).Should(Equal(3))
Now, the linter will catch these patterns as well. For the above code, the linter will suggest
Expect(x).WithOffset(1).Should(HaveLen(3))