Write cleaner, self-documented tests by defining methods in RSpec
01-Jul-2022 1024
When we write clean Ruby code, we try to pull out methods with descriptive names that do small amounts of work. It’s possible to do the same in RSpec, just as we would in a less “fluent” test framework like Ruby’s standard testing library Minitest.RSpec’s describe and context methods define anonymous classes that behave like any other Ruby class as far as scope. Nested blocks even inherit methods from their containers and can use super. Each it block is more like a method, creating an instance of its outer describe/ context and executing in that scope.
Write cleaner, self-documented tests by defining methods in RSpec #ruby #rubydeveloper #rubyonrails #Write #cleaner, #self-documented #tests #defining #methods #RSpec #rspec #tests https://rubyonrails.ba/link/write-cleaner-self-documented-tests-by-defining-methods-in-rspec