IronRuby.Tests.Tests.RubyHosting1C C# (CSharp) Method

RubyHosting1C() public method

public RubyHosting1C ( ) : void
return void
        public void RubyHosting1C() {
            // Main singleton in a scope-unbound code doesn't define method_missing:
            AssertExceptionThrown<MemberAccessException>(
                () => Engine.Execute("class << self; remove_method(:method_missing); end")
            );
            

            // Main singleton in a scope-bound code defines method_missing:
            Engine.Execute("class << self; remove_method(:method_missing); end", Engine.CreateScope());

            var scope = Engine.CreateScope();
            Engine.Execute("self.tmp = 1", scope);
            Assert(scope.ContainsVariable("tmp"));
            
            AssertExceptionThrown<MissingMethodException>(() => Engine.Execute("self.tmp = 1"));


            // method_missing on top-level scope is defined dynamically, not at compile time:
            var compiled = Engine.CreateScriptSourceFromString("some_variable").Compile();
            scope = Engine.CreateScope();

            scope.SetVariable("some_variable", 123);
            Assert(compiled.Execute<int>(scope) == 123);
            
            AssertExceptionThrown<MissingMethodException>(() => compiled.Execute());

            scope.SetVariable("some_variable", "foo");
            Assert(compiled.Execute<string>(scope) == "foo");

            // we throw correct exceptions:
            scope = Engine.CreateScope();
            scope.SetVariable("bar", 1);
            AssertExceptionThrown<MissingMethodException>(() => Engine.Execute("foo 1,2,3"));
            AssertExceptionThrown<MissingMethodException>(() => Engine.Execute("foo 1,2,3", scope));
            AssertExceptionThrown<ArgumentException>(() => Engine.Execute("bar 1,2,3", scope));
            AssertExceptionThrown<ArgumentException>(() => Engine.Execute("bar *[1,2,3]", scope));
            AssertExceptionThrown<ArgumentException>(() => Engine.Execute("scope *[1,2,3]", scope));
            Assert(Engine.Execute<int>("bar *[]", scope) == 1);
        }
Tests