spec/ref2bibtex_spec.rb in ref2bibtex-0.0.3 vs spec/ref2bibtex_spec.rb in ref2bibtex-0.1.0
- old
+ new
@@ -1,60 +1,116 @@
require 'spec_helper'
describe Ref2bibtex do
- context '#request' do
+ context '.request' do
let(:request) { Ref2bibtex.request(payload: [CITATIONS[:first]]) }
- specify '#Ref2bibtex.request makes a query_ok request' do
+ specify 'makes a query_ok request' do
expect(request['query_ok']).to eq(true)
end
- specify '#Ref2bibtex.request returns Hash' do
+ specify 'returns Hash' do
expect(request.class).to eq(Hash)
end
- specify '#Ref2bibtex.request results is an Array' do
+ specify 'results is an Array' do
expect(request['results'].class).to eq(Array)
end
- specify '#Ref2bibtex.request results is an Array of Hashes' do
+ specify 'results is an Array of Hashes' do
expect(request['results'].first.class).to eq(Hash)
end
- specify '#Ref2bibtex.request results is an Array of Hashes, each one having a doi' do
+ specify 'results is an Array of Hashes, each one having a doi' do
expect(request['results'].first['doi']).to be_truthy
end
end
- context '#get_doi' do
- specify 'Ref2bibtex.get_doi() takes a full citation and returns a string' do
+ context '.get_doi' do
+ specify 'takes a full citation and returns a string' do
expect(Ref2bibtex.get_doi(CITATIONS[:first])).to eq('http://dx.doi.org/10.3897/zookeys.20.205')
end
specify 'a citation that can not be resolved returns false' do
- expect(Ref2bibtex.get_doi(CITATIONS[:fifth])).to eq(false)
+ expect(Ref2bibtex.get_doi(CITATIONS[:eighth])).to eq(false)
end
specify 'a badly formed DOI returns false' do
expect(Ref2bibtex.get_doi('asfas')).to eq(false)
end
end
- context '#get_bibtex' do
+ context '.get_bibtex' do
let(:response) { Ref2bibtex.get_bibtex('http://dx.doi.org/10.3897/zookeys.20.205')}
- specify 'Ref2bibtex.get_bibtex() takes a full citation and returns bibtex' do
+ specify 'takes a full citation and returns bibtex' do
expect(response).to match(/author\s=/)
expect(response).to match(/title\s=/)
expect(response).to match(/year\s=\s2009/)
end
specify 'a bad doi returns false' do
expect(Ref2bibtex.get_bibtex('asfasf')).to eq(false)
end
end
- specify "a citation that can not be resolved returns false" do
- expect(Ref2bibtex.get(CITATIONS[:fifth])).to eq(false)
+ specify "a citation that can not be resolved returns false from .get" do
+ expect(Ref2bibtex.get(CITATIONS[:eighth])).to eq(false)
end
+ context 'score' do
+ specify 'can be returned with .get_score' do
+ expect(Ref2bibtex.get_score(CITATIONS[:first])).to be > 0
+ end
+
+ context 'interpretation' do
+ before(:all) {
+ @scores = CITATIONS.keys.inject({}) { |hsh, c|
+ hsh.merge!(
+ c => Ref2bibtex.get_score(CITATIONS[c])
+ )
+ }
+ }
+
+ specify 'mangled text is worse than good text' do
+ expect( @scores[:second] > @scores[:seventh] ).to be_truthy
+ end
+
+ context 'default @@cutoff is reasonable and slightly conservative' do
+ let(:good_citations) { [:first, :second, :third, :fourth, :sixth] }
+ let(:bad_citations) { CITATIONS.keys - good_citations }
+
+ specify 'for good citations' do
+ good_citations.each do |c|
+ expect(@scores[c]).to be > Ref2bibtex.cutoff
+ end
+ end
+
+ specify 'for bad citations' do
+ bad_citations.each do |c|
+ if @scores[c]
+ expect(@scores[c]).to be < Ref2bibtex.cutoff
+ end
+ end
+ end
+ end
+ end
+
+ context 'cutoff' do
+ after(:all) {
+ Ref2bibtex.reset_cutoff
+ }
+
+ specify 'can be used to reject good matches' do
+ Ref2bibtex.cutoff = 1000
+ expect(Ref2bibtex.get_doi(CITATIONS[:first])).to eq(false)
+ end
+
+ specify 'can be used to accept bad matches' do
+ Ref2bibtex.cutoff = 1
+ expect(Ref2bibtex.get_doi(CITATIONS[:fifth])).to be_truthy
+ end
+
+ end
+
+ end
end