A Deep Dive into RSpec Tests in Ruby on Rails
blog.appsignal.com
blog.appsignal.com
If you do, why? How is it better in your view?
https://github.com/rswag/rswag
I'm currently using thoughtbot/json_matchers w/ partials of my OpenAPI spec, but its not nearly as user friendly:
I would've enjoyed it more if it didn't try so hard to mimic a JSON schema language as an embedded DSL in ruby.
It's verbose and error prone, with the dubious benefit of looking familiar.
https://www.rubydoc.info/github/rspec/rspec-core/RSpec%2FCor...
And it suggests using let (instead of the better let!) which when chained makes the execution of the code incredibly unpredictable for a human.
I suggest sticking only to instance variables and before blocks, so that overriding lets is not a practice that appear in your system and also won't push you toward abstracting your tests too much in an effort to improve performance
It omits entirely the warning and says "use this when assigning variable". Yeah you can make an argument either way, but given how dogmatic this website is, it's literally pushing toward using let. The consequence is that you get tests written with let everywhere.
I would outright say do NOT use let, like at all, your tests will be better without them:
- A test abstraction could live in the actual code so that it's properly tested, it's plain ruby and can be used by other developers wanting to test code related to yours
- A test will have all the setup close to its execution phase, making it easier to read
- Instance variables override don't exist