Class: Mana::Mock
- Inherits:
-
Object
- Object
- Mana::Mock
- Defined in:
- lib/mana/mock.rb
Overview
Defined Under Namespace
Classes: Stub
Instance Attribute Summary collapse
-
#stubs ⇒ Object
readonly
Returns the value of attribute stubs.
Instance Method Summary collapse
-
#initialize ⇒ Mock
constructor
Initialize with an empty stub list.
-
#match(prompt_text) ⇒ Object
Find the first stub that matches the given prompt text.
-
#prompt(pattern, **values, &block) ⇒ Object
Register a stub: when a prompt matches
pattern, returnvaluesor callblock.
Constructor Details
#initialize ⇒ Mock
Initialize with an empty stub list
20 21 22 |
# File 'lib/mana/mock.rb', line 20 def initialize @stubs = [] end |
Instance Attribute Details
#stubs ⇒ Object (readonly)
Returns the value of attribute stubs.
17 18 19 |
# File 'lib/mana/mock.rb', line 17 def stubs @stubs end |
Instance Method Details
#match(prompt_text) ⇒ Object
Find the first stub that matches the given prompt text. Regexp patterns use match?, String patterns use include?.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mana/mock.rb', line 31 def match(prompt_text) @stubs.find do |stub| case stub.pattern # Regex: full pattern match when Regexp then prompt_text.match?(stub.pattern) # String: substring match when String then prompt_text.include?(stub.pattern) end end end |