Class: EvalIn::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/eval_in/mock.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



9
10
11
12
13
14
# File 'lib/eval_in/mock.rb', line 9

def initialize(options={})
  @result          = options.fetch :result,          nil
  @languages       = options.fetch :languages,       Hash.new
  @on_call         = options.fetch(:on_call)         { lambda { |*args| @result || evaluate_with_tempfile(*args) } }
  @on_fetch_result = options.fetch(:on_fetch_result) { lambda { |*args| @result || EvalIn.fetch_result(*args)    } }
end

Instance Method Details

#call(code, options = {}) ⇒ Object



16
17
18
19
# File 'lib/eval_in/mock.rb', line 16

def call(code, options={})
  language_name = EvalIn::Client.language_or_error_from options
  @on_call.call(code, options)
end

#fetch_result(raw_url, options = {}) ⇒ Object



21
22
23
# File 'lib/eval_in/mock.rb', line 21

def fetch_result(raw_url, options={})
  @on_fetch_result.call(raw_url, options)
end