Class: Zafu::MockHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/zafu/mock_helper.rb

Overview

This is the ‘src_helper’ used when none is provided. Its main purpose is to provide some information during testing.

Instance Method Summary collapse

Constructor Details

#initialize(strings = {}) ⇒ MockHelper

Returns a new instance of MockHelper.



5
6
7
# File 'lib/zafu/mock_helper.rb', line 5

def initialize(strings = {})
  @strings = strings
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/zafu/mock_helper.rb', line 25

def method_missing(sym, *args)
  arguments = args.map do |arg|
    if arg.kind_of?(Hash)
      res = []
      arg.each do |k,v|
        unless v.nil?
          res << "#{k}:#{v.inspect.gsub(/'|"/, "|")}"
        end
      end
      res.sort.join(' ')
    else
      arg.inspect.gsub(/'|"/, "|")
    end
  end
  res = "[#{sym} #{arguments.join(' ')}]"
end

Instance Method Details

#get_template_text(opts) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/zafu/mock_helper.rb', line 9

def get_template_text(opts)
  src    = opts[:src]
  folder = (opts[:base_path] && opts[:base_path] != '') ? opts[:base_path][1..-1].split('/') : []
  src = src[1..-1] if src[0..0] == '/' # just ignore the 'relative' or 'absolute' tricks.
  url = (folder + src.split('/')).join('_')
  if test = @strings[url]
    return [test['src'], url.split('_').join('/')]
  else
    nil
  end
end

#template_url_for_asset(opts) ⇒ Object



21
22
23
# File 'lib/zafu/mock_helper.rb', line 21

def template_url_for_asset(opts)
  "/test_#{opts[:type]}/#{opts[:src]}"
end