spec/rley/ptree/terminal_node_spec.rb in rley-0.4.01 vs spec/rley/ptree/terminal_node_spec.rb in rley-0.4.02

- old
+ new

@@ -5,31 +5,26 @@ require_relative '../../../lib/rley/ptree/terminal_node' module Rley # Open this namespace to avoid module qualifier prefixes module PTree # Open this namespace to avoid module qualifier prefixes describe TerminalNode do - let(:sample_symbol) do - OpenStruct.new(name: 'Noun') + let(:sample_symbol) { OpenStruct.new(name: 'Noun') } + let(:sample_token) do + OpenStruct.new(lexeme: 'world', terminal: sample_symbol) end let(:sample_range) { double('fake-range') } - subject { TerminalNode.new(sample_symbol, sample_range) } + subject { TerminalNode.new(sample_token, sample_range) } context 'Initialization:' do - it "shouldn't be already bound to a token" do - expect(subject.token).to be_nil + it "should be bound to a token" do + expect(subject.token).to eq(sample_token) end end # context context 'Provided services:' do it 'should provide a text representation of itself' do - # Case 1: not bound to a token - expected_text = "Noun[?, ?]: '(nil)'" - expect(subject.to_string(0)).to eq(expected_text) - - # Case 2: bound to token - subject.token = OpenStruct.new(lexeme: 'peace') - expected_text = "Noun[?, ?]: 'peace'" + expected_text = "Noun[?, ?]: 'world'" expect(subject.to_string(0)).to eq(expected_text) end end # context end # describe end # module