Module: Ammeter::RSpec::Rails::GeneratorExampleHelpers
- Defined in:
- lib/ammeter/rspec/generator/example/generator_example_helpers.rb
Overview
Delegates to Rails::Generators::TestCase to work with RSpec.
Instance Method Summary collapse
-
#set_shell_prompt_responses(generator, command_args = {}) ⇒ Object
Sets return values for basic shell commands (ex. ask, yes?, no?).
Instance Method Details
#set_shell_prompt_responses(generator, command_args = {}) ⇒ Object
Sets return values for basic shell commands (ex. ask, yes?, no?). Does this by mocking return values using RSpec’s ‘and_return` method
Parameters =====
Generator w/ @shell attribute Hash { command_name: input_value, ask: “Testing”, yes?: true } The values for each element in the hash can be set as an array as well. This will allow for different return values upon each call.
ex. set_shell_prompt_responses(generator, { yes?: [true, false] }) would respond with true to the first yes? call, but false to the second
21 22 23 24 25 |
# File 'lib/ammeter/rspec/generator/example/generator_example_helpers.rb', line 21 def set_shell_prompt_responses(generator, command_args={}) command_args.each do |k,v| allow(generator.shell).to receive(k.to_sym).and_return(*v) end end |