spec/citeproc/js/engine_spec.rb in citeproc-js-0.0.2 vs spec/citeproc/js/engine_spec.rb in citeproc-js-0.0.6

- old
+ new

@@ -1,132 +1,131 @@ +# -*- coding: utf-8 -*- + require 'spec_helper' module CiteProc module JS describe 'Engine' do + + let(:items) { load_items('items') } + + let(:processor) do + p = Processor.new(:style => 'apa') + p.update(items) + p + end + before(:all) do Style.root = File.expand_path('../../../fixtures/styles', __FILE__) Locale.root = File.expand_path('../../../fixtures/locales', __FILE__) end - - let(:subject) do - Engine.new do |e| - p = double(:processor) - p.stub(:options).and_return { Processor.defaults } - p.stub(:items).and_return { load_items('items') } - e.processor = p - end + + let(:engine) do + processor.engine = Engine.new(processor) end - + it { should_not be nil } - - describe '#style' do - let(:apa) { load_style('apa') } - it 'accepts a style name' do - subject.style = :apa - subject.style.to_s.should == apa - end - it 'accepts a style name with extension' do - subject.style = 'apa.csl' - subject.style.to_s.should == apa - end - it 'accepts a full style' do - subject.style = apa - subject.style.to_s.should == apa - end - end - + + describe '#version' do it 'returns a 1.x version string' do - subject.version.should =~ /^1\.[\d\.]+/ + engine.version.should =~ /^1\.[\d\.]+/ end end describe '#name' do it 'returns "citeproc-js"' do - subject.name.should == 'citeproc-js' + engine.name.should == 'citeproc-js' end end - + describe '#type' do it 'returns "CSL"' do - subject.type.should == 'CSL' + engine.type.should == 'CSL' end end - - context 'when started' do - let(:subject) do - Engine.new do |e| - p = double(:processor) - p.stub(:options).and_return { Processor.defaults } - p.stub(:items).and_return { load_items('items') } - e.processor = p - e.style = :apa - e.locales = :'en-US' - e.start - end + + + describe '#processor_version' do + it 'returns the citeproc-js version' do + engine.processor_version.should =~ /^[\d\.]+$/ end + end - describe '#processor_version' do - it 'returns the citeproc-js version' do - subject.processor_version.should =~ /^[\d\.]+$/ - end + describe '#flags' do + it 'returns a hash of flags' do + engine.flags.should have_key('sort_citations') end - - describe '#flags' do - it 'returns a hash of flags' do - subject.flags.should have_key('sort_citations') - end + end + + describe '#namespace=' do + it 'sets the abbreviation namespace' do + lambda { engine.namespace = :default }.should_not raise_error end + end - describe '#default_namespace=' do - it 'sets the abbreviation namespace' do - lambda { subject.default_namespace = :default }.should_not raise_error - end + describe '#registry' do + it 'is a hash' do + engine.registry.should be_a(Hash) end + end - describe '#registry' do - it 'is a hash' do - subject.registry.should be_a(Hash) - end + describe '#update_items' do + it 'given a list of ids, loads the corresponding items into the engine' do + expect { engine.update_items(['ITEM-1']) }.to + change { engine.registry[:inserts].length }.by(1) end - - describe '#update_items' do - it 'given a list of ids, loads the corresponding items into the engine' do - expect { subject.update_items(['ITEM-1']) }.to - change { subject.registry[:inserts].length }.by(1) - end + end + + describe '#bibliography' do + it 'returns an empty bibliography by default' do + engine.bibliography.should be_empty end - describe '#bibliography' do - it 'returns an empty bibliography by default' do - subject.bibliography[1].should be_empty - end + describe 'when items were updated' do + before(:each) { engine.update_items(['ITEM-1']) } - describe 'when items were processed' do - before(:each) { subject.update_items(['ITEM-1']) } - - it 'returns the bibliography when at least one item was processed' do - subject.bibliography[1].should_not be_empty - end + it 'returns the bibliography when at least one item was processed' do + engine.bibliography.should_not be_empty end - end - - describe '#sorted_registry_items' do - it 'returns an empty bibliography by default' do - subject.sorted_registry_items.should be_empty + + it 'the bibliography contains the processed items' do + engine.bibliography[0].should match(/Boundaries of Dissent/) end + end + end - describe 'when items were processed' do - before(:each) { subject.update_items(['ITEM-1']) } - - it 'returns the bibliography when at least one item was processed' do - subject.sorted_registry_items.should_not be_empty - end - end + describe '#append' do + + it 'returns the citation id and string for the item' do + engine.append(CitationData.new([{:id => 'ITEM-1'}]))[0][1].should == '(D’Arcus, 2006)' end + it 'increases the citation index on subsequent calls' do + x = engine.append(CitationData.new([{:id => 'ITEM-1'}]))[0][0] + engine.append(CitationData.new([{:id => 'ITEM-1'}]))[0][0].should > x + end + + it 'includes the locator' do + engine.append(CitationData.new([{:id => 'ITEM-1', :locator => 'PAGE'}]))[0][1].should match(/PAGE/) + end + end - end - end + describe '#sorted_registry_items' do + it 'returns an empty bibliography by default' do + engine.sorted_registry_items.should be_empty + end + + describe 'when items were processed' do + before(:each) { engine.update_items(['ITEM-1']) } + + it 'returns the bibliography when at least one item was processed' do + engine.sorted_registry_items.should_not be_empty + end + end + end + + end + + end end \ No newline at end of file