Sha256: e58a5f68d3965a8b3d3682d61c3fc8abc075ab798036c65937fac4e9bba86791

Contents?: true

Size: 1.92 KB

Versions: 10

Compression:

Stored size: 1.92 KB

Contents

require File.join(File.dirname(__FILE__), 'test_helper')

describe "MethodInspector" do
  before { MethodInspector.instance = nil }

  def method_inspector
    MethodInspector.instance
  end

  it "non commands module can't set anything" do
    remove_constant :Blah
    eval "module Blah; end"
    method_inspector.current_module = Blah
    Inspector.enable
    Blah.module_eval("desc 'test'; def test; end; options :a=>1; def test2; end")
    Inspector.disable
    method_inspector.store[:desc].empty?.should == true
    method_inspector.store[:options].empty?.should == true
  end

  it "handles anonymous classes" do
    Inspector.enable
    Class.new.module_eval "def blah; end"
    Inspector.disable
    method_inspector.store.should == nil
  end

  describe "commands module with" do
    def parse(string)
      Inspector.enable
      ::Boson::Commands::Zzz.module_eval(string)
      Inspector.disable
      method_inspector.store
    end

    before_all { eval "module ::Boson::Commands::Zzz; end" }

    it "desc sets descriptions" do
      parsed = parse "desc 'test'; def m1; end; desc 'one'; desc 'more'; def m2; end"
      parsed[:desc].should == {"m1"=>"test", "m2"=>"more"}
    end

    it "options sets options" do
      parse("options :z=>'b'; def zee; end")[:options].should == {"zee"=>{:z=>'b'}}
    end

    it "option sets options" do
      parse("option :z, 'b'; option :y, :boolean; def zee; end")[:options].should ==
        {"zee"=>{:z=>'b', :y=>:boolean}}
    end

    it "option(s) sets options" do
      parse("options :z=>'b'; option :y, :string; def zee; end")[:options].should ==
        {"zee"=>{:z=>'b', :y=>:string}}
    end

    it "option(s) option overrides options" do
      parse("options :z=>'b'; option :z, :string; def zee; end")[:options].should ==
        {"zee"=>{:z=>:string}}
    end

    it "config sets config" do
      parse("config :z=>true; def zee; end")[:config].should == {"zee"=>{:z=>true}}
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
boson-1.3.0 test/method_inspector_test.rb
boson-1.2.4 test/method_inspector_test.rb
boson-1.2.3 test/method_inspector_test.rb
boson-1.2.2 test/method_inspector_test.rb
boson-1.2.1 test/method_inspector_test.rb
boson-1.2.0 test/method_inspector_test.rb
boson-1.1.1 test/method_inspector_test.rb
boson-1.1.0 test/method_inspector_test.rb
boson-1.0.1 test/method_inspector_test.rb
boson-1.0.0 test/method_inspector_test.rb