Class: Object

Inherits:
BasicObject
Includes:
InstanceExecHelper, Spec::ObjectExpectations
Defined in:
lib/spec/runner/instance_exec.rb,
lib/spec/api/expectations.rb,
lib/spec/api/helper/should_base.rb,
lib/spec/test_to_spec/ruby2ruby.rb

Overview

Defined Under Namespace

Modules: InstanceExecHelper

Instance Method Summary collapse

Methods included from Spec::ObjectExpectations

#should

Instance Method Details

#inspect_for_expectation_not_met_errorObject



9
10
11
12
# File 'lib/spec/api/helper/should_base.rb', line 9

def inspect_for_expectation_not_met_error
  return "#{self.class} #{inspect}" if inspect.include? "<"
  return "#{self.class} <#{inspect}>" unless inspect.include? "<"
end

#instance_exec(*args, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/spec/runner/instance_exec.rb', line 5

def instance_exec(*args, &block)
  begin
    old_critical, Thread.critical = Thread.critical, true
    n = 0
    n += 1 while respond_to?(mname="__instance_exec#{n}")
    InstanceExecHelper.module_eval{ define_method(mname, &block) }
  ensure
    Thread.critical = old_critical
  end
  begin
    ret = send(mname, *args)
  ensure
    InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil
  end
  ret
end

#parse_tree(method_name = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/spec/test_to_spec/ruby2ruby.rb', line 23

def parse_tree(method_name=nil)
  if method_name
    m = method(method_name)
    klass = m.defined_in
    method_name = m.name
    return ParseTree.new.parse_tree_for_method(klass, method_name)
  elsif is_a?(Class)
    klass = self
  else
    klass = self.class
  end
  ParseTree.new.parse_tree(klass).first
end

#source(method_name = nil) ⇒ Object



37
38
39
# File 'lib/spec/test_to_spec/ruby2ruby.rb', line 37

def source(method_name=nil)
  RubySource.new RubyToRuby.new.process(parse_tree(method_name))
end