require(File.dirname(__FILE__) + "/../lib/ruby_reads_php") describe "Ruby reads PHP" do describe "reading PHP constants" do it "should read simple constant" do rrp = RubyReadsPHP.read(File.dirname(__FILE__) + "/fixtures/simple_constant.php") rrp.constants['MY_CONSTANT'].should eql('my value') end it "should read simple constant with double quotes" do rrp = RubyReadsPHP.read(File.dirname(__FILE__) + "/fixtures/simple_constant_with_double_quotes.php") rrp.constants['MY_CONSTANT'].should eql('my value') end it "should read simple constant with extra spacing" do rrp = RubyReadsPHP.read(File.dirname(__FILE__) + "/fixtures/simple_constant_with_extra_spacing.php") rrp.constants['MY_CONSTANT'].should eql('my value') end it "should read multiple constants" do rrp = RubyReadsPHP.read(File.dirname(__FILE__) + "/fixtures/multiple_constants.php") rrp.constants['MY_CONSTANT'].should eql('my value') rrp.constants['MY_CONSTANT_NUMBER_2'].should eql('my value 2') end it "should read slashes" do rrp = RubyReadsPHP.read(File.dirname(__FILE__) + "/fixtures/simple_constant_with_slashes.php") rrp.constants['MY_CONSTANT'].should eql('http://www.google.com') end it "should cast as integer" do rrp = RubyReadsPHP.read(File.dirname(__FILE__) + "/fixtures/integer.php") rrp.constants['MY_CONSTANT'].should eql(100) end it "should not cast as integer when quoted" do rrp = RubyReadsPHP.read(File.dirname(__FILE__) + "/fixtures/integer_quoted.php") rrp.constants['MY_CONSTANT'].should eql("100") end it "should cast as float" do rrp = RubyReadsPHP.read(File.dirname(__FILE__) + "/fixtures/float.php") rrp.constants['MY_CONSTANT'].should eql(95.5.to_f) end end describe "opening files" do it "should automatically append .php extension" do rrp = RubyReadsPHP.read(File.dirname(__FILE__) + "/fixtures/simple_constant") rrp.constants['MY_CONSTANT'].should eql('my value') end end end