How to test Ruby methods that involve puts or gets

What makes the ask_for_number method challenging to test is a dependency. Most methods can be tested by saying, “When I pass in argument X, I expect return value Y.” This one isn’t so straightforward though. This is more like “When the user sees output X and then enters value V, expect subsequent output O.”Instead of accepting arguments, this method gets its value from user input. And instead of necessarily returning a value, this method sometimes simply outputs more text.How can we give this method the values it needs, and how can we observe the way the method behaves when we give it these values?.
How to test Ruby methods that involve puts or gets #ruby #rubydeveloper #rubyonrails #test https://rubyonrails.ba/single/how-to-test-ruby-methods-that-involve-puts-or-gets

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles