spec/handlers/ruby/legacy/base_spec.rb in yard-0.8.7.6 vs spec/handlers/ruby/legacy/base_spec.rb in yard-0.9.0

- old
+ new

@@ -2,12 +2,14 @@ include Parser::Ruby::Legacy describe YARD::Handlers::Ruby::Legacy::Base, "#handles and inheritance" do before do - Handlers::Ruby::Legacy::Base.stub!(:inherited) - Handlers::Ruby::Legacy::MixinHandler.stub!(:inherited) # fixes a Ruby1.9 issue + allow(Handlers::Ruby::Legacy::Base).to receive(:inherited) + if RUBY_VERSION > '1.8.7' + allow(Handlers::Ruby::Legacy::MixinHandler).to receive(:inherited) # fixes a Ruby1.9 issue + end @processor = Handlers::Processor.new(OpenStruct.new(:parser_type => :ruby18)) end after(:all) do Handlers::Base.clear_subclasses @@ -15,49 +17,49 @@ def stmt(string) Statement.new(TokenList.new(string)) end - it "should only handle Handlers inherited from Ruby::Legacy::Base class" do + it "only handles Handlers inherited from Ruby::Legacy::Base class" do class IgnoredHandler < Handlers::Base handles "hello" end class NotIgnoredHandlerLegacy < Handlers::Ruby::Legacy::Base handles "hello" end - Handlers::Base.stub!(:subclasses).and_return [IgnoredHandler, NotIgnoredHandlerLegacy] - @processor.find_handlers(stmt("hello world")).should == [NotIgnoredHandlerLegacy] + allow(Handlers::Base).to receive(:subclasses).and_return [IgnoredHandler, NotIgnoredHandlerLegacy] + expect(@processor.find_handlers(stmt("hello world"))).to eq [NotIgnoredHandlerLegacy] end - it "should handle a string input" do + it "handles a string input" do class TestStringHandler < Handlers::Ruby::Legacy::Base handles "hello" end - TestStringHandler.handles?(stmt("hello world")).should be_true - TestStringHandler.handles?(stmt("nothello world")).should be_false + expect(TestStringHandler.handles?(stmt("hello world"))).to be true + expect(TestStringHandler.handles?(stmt("nothello world"))).to be false end - it "should handle regex input" do + it "handles regex input" do class TestRegexHandler < Handlers::Ruby::Legacy::Base handles /^nothello$/ end - TestRegexHandler.handles?(stmt("nothello")).should be_true - TestRegexHandler.handles?(stmt("not hello hello")).should be_false + expect(TestRegexHandler.handles?(stmt("nothello"))).to be true + expect(TestRegexHandler.handles?(stmt("not hello hello"))).to be false end - it "should handle token input" do + it "handles token input" do class TestTokenHandler < Handlers::Ruby::Legacy::Base handles TkMODULE end - TestTokenHandler.handles?(stmt("module")).should be_true - TestTokenHandler.handles?(stmt("if")).should be_false + expect(TestTokenHandler.handles?(stmt("module"))).to be true + expect(TestTokenHandler.handles?(stmt("if"))).to be false end - it "should parse a do/end or { } block with #parse_block" do + it "parses a do/end or { } block with #parse_block" do class MyBlockHandler < Handlers::Ruby::Legacy::Base handles /\AmyMethod\b/ def process parse_block(:owner => "test") end @@ -68,15 +70,15 @@ def self.reset; @@reached = false end def self.reached?; @@reached ||= false end def process; @@reached = true end end - Handlers::Base.stub!(:subclasses).and_return [MyBlockHandler, MyBlockInnerHandler] + allow(Handlers::Base).to receive(:subclasses).and_return [MyBlockHandler, MyBlockInnerHandler] Parser::SourceParser.parser_type = :ruby18 Parser::SourceParser.parse_string "myMethod do inner end" - MyBlockInnerHandler.should be_reached + expect(MyBlockInnerHandler).to be_reached MyBlockInnerHandler.reset Parser::SourceParser.parse_string "myMethod { inner }" - MyBlockInnerHandler.should be_reached + expect(MyBlockInnerHandler).to be_reached Parser::SourceParser.parser_type = :ruby end end