Module: Mock5
- Extended by:
- Mock5
- Included in:
- Mock5
- Defined in:
- lib/mock5.rb,
lib/mock5/api.rb,
lib/mock5/version.rb
Defined Under Namespace
Classes: Api
Constant Summary collapse
- VERSION =
"1.0.3".freeze
Instance Method Summary collapse
- #mock(*args, &block) ⇒ Object
- #mount(*apis) ⇒ Object
- #mounted?(*apis) ⇒ Boolean
- #mounted_apis ⇒ Object
- #unmount(*apis) ⇒ Object
- #unmount_all! ⇒ Object (also: #reset!)
- #with_mounted(*apis) ⇒ Object
Instance Method Details
#mock(*args, &block) ⇒ Object
12 13 14 |
# File 'lib/mock5.rb', line 12 def mock(*args, &block) Api.new(*args, &block) end |
#mount(*apis) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/mock5.rb', line 16 def mount(*apis) (apis.to_set - mounted_apis).each do |api| mounted_apis.add api registry.register_request_stub api.request_stub end end |
#mounted?(*apis) ⇒ Boolean
30 31 32 |
# File 'lib/mock5.rb', line 30 def mounted?(*apis) apis.to_set.subset?(mounted_apis) end |
#mounted_apis ⇒ Object
8 9 10 |
# File 'lib/mock5.rb', line 8 def mounted_apis @_mounted_apis ||= Set.new end |
#unmount(*apis) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/mock5.rb', line 23 def unmount(*apis) (mounted_apis & apis).each do |api| mounted_apis.delete api registry.remove_request_stub api.request_stub end end |
#unmount_all! ⇒ Object Also known as: reset!
41 42 43 |
# File 'lib/mock5.rb', line 41 def unmount_all! unmount *mounted_apis end |
#with_mounted(*apis) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/mock5.rb', line 34 def with_mounted(*apis) mounted = mount(*apis) yield ensure unmount *mounted end |