Ruby library to record and replay object interactions
27-Jun-2019 2076
Impersonator is a Ruby library to record and replay object interactions.When testing, you often find services that are expensive to invoke, and you need to use a double instead. Creating stubs and mocks for simple scenarios is easy, but, for complex interactions, things get messy fast. Stubbing elaborated canned response and orchestrating multiple expectations quickly degenerates in brittle tests that are hard to write and maintain.Impersonator comes to the rescue. Given an object and a list of methods to impersonate:The first time each method is invoked, it will record its invocations, including passed arguments, return values, and yielded values. This is known as record mode.The next times, it will reproduce the recorded values and will validate that the method was invoked with the same arguments, in a specific order and the exact number of times. This is known as replay mode.Impersonator only focuses on validating invocation signature and reproducing output values, which is perfect for many services. It won't work for services that trigger additional logic that is relevant to the test (e.g., if the method sends an email, the impersonated method won't send it).
Ruby library to record and replay object interactions #ruby #rubydeveloper #rubyonrails #library #record #replay #object #interactions #library #record https://rubyonrails.ba/link/ruby-library-to-record-and-replay-object-interactions