public
Description: Convert Php to Ruby (Will soon die and be reborn as something different..)
Homepage: http://ionize.farleyknight.com
Clone URL: git://github.com/farleyknight/ionize.git
Click here to lend your support to: ionize and make a donation at www.pledgie.com !
ionize / spec / extension / object_spec.rb
100644 59 lines (46 sloc) 1.375 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'rubygems'
require 'ext/ionize_php_ext'
require 'lib/ionize/environment'
 
require 'rubygems'
 
Kernel.module_eval { alias :calling :lambda }
 
 
describe "Working with objects" do
  before do
    Ionize::Php.session_start!
    Ionize::Php.eval(%Q{
class Vegetable {
var $edible;
var $color;
 
function Vegetable($edible, $color="green")
{
$this->edible = $edible;
$this->color = $color;
}
 
function is_edible()
{
return $this->edible;
}
 
function what_color()
{
return $this->color;
}
}
})
  end
 
  after do
    Ionize::Php.session_end!
  end
 
  it "should define a class and access it later" do
    Ionize::Php.eval(%Q{ class A { } })
    result = Ionize::Php.eval(%Q{ return new A(); })
 
    result.should_not be_nil
  end
 
  it "should have a list of instance variables" do
    veggie = Ionize::Php.eval(%Q{ return new Vegetable(true, "blue"); })
    veggie.instance_variables_hash.should == {"color" => "blue", "edible" => true}
  end
 
  it "should call an object's function" do
    veggie = Ionize::Php.eval(%Q{ return new Vegetable(true, "blue"); })
    veggie.call_function_n('is_edible').should == true
    veggie.call_function_n('what_color').should == "blue"
  end
end