spec/sequitur/grammar_visitor_spec.rb in sequitur-0.1.23 vs spec/sequitur/grammar_visitor_spec.rb in sequitur-0.1.24

- old
+ new

@@ -4,79 +4,78 @@ # Load the class under test require_relative '../../lib/sequitur/grammar_visitor' module Sequitur # Re-open the module to get rid of qualified names -describe GrammarVisitor do - # Use a double(mock) as a grammar - let(:fake) { double('fake-grammar') } + describe GrammarVisitor do + # Use a double(mock) as a grammar + let(:fake) { double('fake-grammar') } - context 'Standard creation & initialization:' do - # Default instantiation rule - subject { GrammarVisitor.new(fake) } + context 'Standard creation & initialization:' do + # Default instantiation rule + subject { GrammarVisitor.new(fake) } - it 'should be initialized with a grammar argument' do - expect { GrammarVisitor.new(fake) }.not_to raise_error - end + it 'should be initialized with a grammar argument' do + expect { GrammarVisitor.new(fake) }.not_to raise_error + end - it 'should know the grammar to visit' do - expect(subject.grammar).to eq(fake) - end + it 'should know the grammar to visit' do + expect(subject.grammar).to eq(fake) + end - it "shouldn't have subscribers at start" do - expect(subject.subscribers).to be_empty - end - end # context + it "shouldn't have subscribers at start" do + expect(subject.subscribers).to be_empty + end + end # context + context 'Subscribing:' do + # Default instantiation rule + subject { GrammarVisitor.new(fake) } - context 'Subscribing:' do - # Default instantiation rule - subject { GrammarVisitor.new(fake) } + let(:listener1) { double('fake-formatter1') } + let(:listener2) { double('fake-formatter2') } - let(:listener1) { double('fake-formatter1') } - let(:listener2) { double('fake-formatter2') } + it 'should allow subscriptions' do + subject.subscribe(listener1) + expect(subject.subscribers.size).to eq(1) + expect(subject.subscribers).to eq([listener1]) - it 'should allow subscriptions' do - subject.subscribe(listener1) - expect(subject.subscribers.size).to eq(1) - expect(subject.subscribers).to eq([listener1]) + subject.subscribe(listener2) + expect(subject.subscribers.size).to eq(2) + expect(subject.subscribers).to eq([listener1, listener2]) + end - subject.subscribe(listener2) - expect(subject.subscribers.size).to eq(2) - expect(subject.subscribers).to eq([listener1, listener2]) - end + it 'should allow un-subcriptions' do + subject.subscribe(listener1) + subject.subscribe(listener2) + subject.unsubscribe(listener2) + expect(subject.subscribers.size).to eq(1) + expect(subject.subscribers).to eq([listener1]) + subject.unsubscribe(listener1) + expect(subject.subscribers).to be_empty + end + end # context - it 'should allow un-subcriptions' do - subject.subscribe(listener1) - subject.subscribe(listener2) - subject.unsubscribe(listener2) - expect(subject.subscribers.size).to eq(1) - expect(subject.subscribers).to eq([listener1]) - subject.unsubscribe(listener1) - expect(subject.subscribers).to be_empty - end - end # context + context 'Notifying visit events:' do + # Default instantiation rule + subject do + instance = GrammarVisitor.new(fake) + instance.subscribe(listener1) + instance + end - context 'Notifying visit events:' do - # Default instantiation rule - subject do - instance = GrammarVisitor.new(fake) - instance.subscribe(listener1) - instance - end + # Use doubles/mocks to simulate formatters + let(:listener1) { double('fake-formatter1') } + let(:listener2) { double('fake-formatter2') } + let(:mock_production) { double('fake-production') } - # Use doubles/mocks to simulate formatters - let(:listener1) { double('fake-formatter1') } - let(:listener2) { double('fake-formatter2') } - let(:mock_production) { double('fake-production') } + it 'should react to the start_visit_grammar message' do + # Notify subscribers when start the visit of the grammar + expect(listener1).to receive(:before_grammar).with(fake) - it 'should react to the start_visit_grammar message' do - # Notify subscribers when start the visit of the grammar - expect(listener1).to receive(:before_grammar).with(fake) - - subject.start_visit_grammar(fake) - end - end # context -end # describe + subject.start_visit_grammar(fake) + end + end # context + end # describe end # module # End of file