From 2ab0eea0479b390e81b278cdac26bac5b28e8292 Mon Sep 17 00:00:00 2001 From: Christian Boos Date: Sat, 2 Jun 2018 17:07:16 +0200 Subject: [PATCH] Refactor legacy token list tests to avoid toplevel include This toplevel include proved to be problematic for the follow-up test, running yard on yard source. --- spec/parser/ruby/legacy/token_list_spec.rb | 33 +++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/spec/parser/ruby/legacy/token_list_spec.rb b/spec/parser/ruby/legacy/token_list_spec.rb index d2c8d7e93..d084256c8 100644 --- a/spec/parser/ruby/legacy/token_list_spec.rb +++ b/spec/parser/ruby/legacy/token_list_spec.rb @@ -1,9 +1,13 @@ # frozen_string_literal: true -include YARD::Parser::Ruby::Legacy -include YARD::Parser::Ruby::Legacy::RubyToken +# Note: including YARD::Parser::Ruby::Legacy at top-level is problematic +# for other tests (e.g cli/yard_on_yard_spec.rb) RSpec.describe YARD::Parser::Ruby::Legacy::TokenList do + Legacy = YARD::Parser::Ruby::Legacy + TokenList = Legacy::TokenList + LT = Legacy::RubyToken + describe "#initialize / #push" do it "accepts a tokenlist (via constructor or push)" do expect { TokenList.new(TokenList.new) }.not_to raise_error @@ -11,8 +15,9 @@ end it "accept a token (via constructor or push)" do - expect { TokenList.new(Token.new(0, 0)) }.not_to raise_error - expect(TokenList.new.push(Token.new(0, 0), Token.new(1, 1)).size).to eq 2 + expect { TokenList.new(LT::Token.new(0, 0)) }.not_to raise_error + expect(TokenList.new.push(LT::Token.new(0, 0), + LT::Token.new(1, 1)).size).to eq 2 end it "accepts a string and parse it as code (via constructor or push)" do @@ -30,15 +35,15 @@ it "does not interpolate string data" do x = TokenList.new('x = "hello #{world}"') expect(x.size).to eq 6 - expect(x[4].class).to eq TkDSTRING + expect(x[4].class).to eq LT::TkDSTRING expect(x.to_s).to eq 'x = "hello #{world}"' + "\n" end it "handles label syntax" do x = TokenList.new('a:1,b:2') - expect(x[0].class).to eq TkLABEL + expect(x[0].class).to eq LT::TkLABEL expect(x[0].text).to eq 'a:' - expect(x[3].class).to eq TkLABEL + expect(x[3].class).to eq LT::TkLABEL expect(x[3].text).to eq 'b:' end end @@ -46,13 +51,13 @@ describe "#to_s" do before do @t = TokenList.new - @t << TkDEF.new(1, 1, "def") - @t << TkSPACE.new(1, 1) - @t << TkIDENTIFIER.new(1, 1, "x") - @t << TkStatementEnd.new(1, 1) - @t << TkSEMICOLON.new(1, 1) << TkSPACE.new(1, 1) - @t << TkBlockContents.new(1, 1) - @t << TkSPACE.new(1, 1) << TkEND.new(1, 1, "end") + @t << LT::TkDEF.new(1, 1, "def") + @t << LT::TkSPACE.new(1, 1) + @t << LT::TkIDENTIFIER.new(1, 1, "x") + @t << LT::TkStatementEnd.new(1, 1) + @t << LT::TkSEMICOLON.new(1, 1) << LT::TkSPACE.new(1, 1) + @t << LT::TkBlockContents.new(1, 1) + @t << LT::TkSPACE.new(1, 1) << LT::TkEND.new(1, 1, "end") @t[0].set_text "def" @t[1].set_text " " @t[2].set_text "x"