Sha256: 2b38e7d18e33a1ed78bb7f82b810878f37783b9255281788c2497f2c639d3f68

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

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

describe "MethodInspector" do
  before_all { MethodInspector.mod_store = {} }
  describe "commands module with" do
    it "not all method attributes set causes method_locations to be set" do
      MethodInspector.stubs(:find_method_locations).returns(["/some/path", 10])
      parsed = parse "desc 'yo'; def yo; end; options :yep=>1; def yep; end; " +
        "option :b, :boolean; config :a=>1; desc 'z'; options :a=>1; def az; end"
      parsed[:method_locations].key?('yo').should == true
      parsed[:method_locations].key?('yep').should == true
      parsed[:method_locations].key?('az').should == false
    end

    it "no find_method_locations doesn't set method_locations" do
      MethodInspector.stubs(:find_method_locations).returns(nil)
      parse("def bluh; end")[:method_locations].key?('bluh').should == false
    end
  end

  describe "scrape_arguments" do
    def args_from(file_string)
      MethodInspector.scrape_arguments(file_string, "blah")
    end

    it "parses arguments of class method" do
      args_from("    def YAML.blah( filepath )\n").should == [['filepath']]
    end

    it "parses arguments with no spacing" do
      args_from("def bong; end\ndef blah(arg1,arg2='val2')\nend").should == [["arg1"], ['arg2', "'val2'"]]
    end

    it "parses arguments with spacing" do
      args_from("\t def blah(  arg1=val1, arg2 = val2)").should == [["arg1","val1"], ["arg2", "val2"]]
    end

    it "parses arguments without parenthesis" do
      args_from(" def blah arg1, arg2, arg3={}").should == [['arg1'], ['arg2'], ['arg3','{}']]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
boson-more-0.2.1 test/more_method_inspector_test.rb
boson-more-0.2.0 test/more_method_inspector_test.rb
boson-more-0.1.0 test/more_method_inspector_test.rb