class RailsMocks::Stub
Attributes
stub[R]
Public Class Methods
new(stub)
click to toggle source
# File lib/rails_mocks/stub.rb, line 7 def initialize(stub) @stub = stub end
Public Instance Methods
execute(scope)
click to toggle source
# File lib/rails_mocks/stub.rb, line 11 def execute(scope) scope.allow(allow).to(receiver) end
Private Instance Methods
_and_return()
click to toggle source
# File lib/rails_mocks/stub.rb, line 38 def _and_return fetch_data(:and_return) end
_receive()
click to toggle source
# File lib/rails_mocks/stub.rb, line 30 def _receive stub[:receive] end
_with()
click to toggle source
# File lib/rails_mocks/stub.rb, line 34 def _with fetch_data(:with) end
allow()
click to toggle source
# File lib/rails_mocks/stub.rb, line 19 def allow stub[:allow].constantize end
fetch_data(key)
click to toggle source
# File lib/rails_mocks/stub.rb, line 42 def fetch_data(key) data = stub.fetch(key, {}) body = data[:body] return double(body) if wrap_double?(data) body end
receiver()
click to toggle source
# File lib/rails_mocks/stub.rb, line 23 def receiver receiver = receive(_receive) receiver.with(_with) if _with receiver.and_return(_and_return) if _and_return receiver end
wrap_double?(data)
click to toggle source
# File lib/rails_mocks/stub.rb, line 49 def wrap_double?(data) data[:double] end