spec/lib/application_spec.rb in picky-2.7.0 vs spec/lib/application_spec.rb in picky-3.0.0.pre1

- old
+ new

@@ -1,31 +1,35 @@ # encoding: utf-8 # require 'spec_helper' -describe Application do +describe Picky::Application do describe "integration" do it "should run ok" do lambda { - class MinimalTestApplication < Application - books = Index::Memory.new :books, source: Sources::DB.new('SELECT id, title FROM books', :file => 'app/db.yml') + class MinimalTestApplication < described_class + books = Picky::Indexes::Memory.new :books, + source: Picky::Sources::DB.new( + 'SELECT id, title FROM books', + :file => 'app/db.yml' + ) books.define_category :title rack_adapter.stub! :exclaim # Stopping it from exclaiming. - route %r{^/books} => Search.new(books) + route %r{^/books} => Picky::Search.new(books) end - Tokenizers::Index.default.tokenize 'some text' - Tokenizers::Query.default.tokenize 'some text' + Picky::Tokenizers::Index.default.tokenize 'some text' + Picky::Tokenizers::Query.default.tokenize 'some text' }.should_not raise_error end it "should run ok" do lambda { # Here we just test if the API can be called ok. # - class TestApplication < Application + class TestApplication < described_class indexing removes_characters: /[^a-zA-Z0-9\s\/\-\"\&\.]/, stopwords: /\b(and|the|of|it|in|for)\b/, splits_text_on: /[\s\/\-\"\&\.]/, removes_characters_after_splitting: /[\.]/, normalizes_words: [[/\$(\w+)/i, '\1 dollars']], @@ -34,94 +38,97 @@ searching removes_characters: /[^a-zA-Z0-9äöü\s\/\-\,\&\"\~\*\:]/, stopwords: /\b(and|the|of|it|in|for)\b/, splits_text_on: /[\s\/\-\,\&]+/, normalizes_words: [[/Deoxyribonucleic Acid/i, 'DNA']], - substitutes_characters_with: CharacterSubstituters::WestEuropean.new, + substitutes_characters_with: Picky::CharacterSubstituters::WestEuropean.new, maximum_tokens: 5 - books_index = Index::Memory.new :books, - source: Sources::DB.new('SELECT id, title, author, isbn13 as isbn FROM books', :file => 'app/db.yml') + books_index = Picky::Indexes::Memory.new :books, + source: Picky::Sources::DB.new( + 'SELECT id, title, author, isbn13 as isbn FROM books', + :file => 'app/db.yml' + ) books_index.define_category :title, - similarity: Similarity::DoubleMetaphone.new(3) # Up to three similar title word indexed. + similarity: Picky::Similarity::DoubleMetaphone.new(3) # Up to three similar title word indexed. books_index.define_category :author, - similarity: Similarity::Soundex.new(2) + similarity: Picky::Similarity::Soundex.new(2) books_index.define_category :isbn, - partial: Partial::None.new # Partially searching on an ISBN makes not much sense. + partial: Picky::Partial::None.new # Partially searching on an ISBN makes not much sense. - geo_index = Index::Memory.new :geo do - source Sources::CSV.new(:location, :north, :east, file: 'data/ch.csv', col_sep: ',') + geo_index = Picky::Indexes::Memory.new :geo do + source Picky::Sources::CSV.new(:location, :north, :east, file: 'data/ch.csv', col_sep: ',') indexing removes_characters: /[^a-z]/ category :location, - similarity: Similarity::Metaphone.new(4) + similarity: Picky::Similarity::Metaphone.new(4) ranged_category :north1, 1, precision: 3, from: :north ranged_category :east1, 1, precision: 3, from: :east end rack_adapter.stub! :exclaim # Stopping it from exclaiming. - route %r{^/books} => Search.new(books_index) - route %r{^/buks} => Search.new(books_index) do + route %r{^/books} => Picky::Search.new(books_index) + route %r{^/buks} => Picky::Search.new(books_index) do searching removes_characters: /[buks]/ end end }.should_not raise_error end end describe 'finalize' do before(:each) do - Application.stub! :check + described_class.stub! :check end it 'checks if all is ok' do - Application.should_receive(:check).once.with + described_class.should_receive(:check).once.with - Application.finalize + described_class.finalize end it 'tells the rack adapter to finalize' do - Application.rack_adapter.should_receive(:finalize).once.with + described_class.rack_adapter.should_receive(:finalize).once.with - Application.finalize + described_class.finalize end end describe 'check' do it 'does something' do - Application.should_receive(:warn).once.with "\nWARNING: No routes defined for application configuration in Class.\n\n" + described_class.should_receive(:warn).once.with "\nWARNING: No routes defined for application configuration in Class.\n\n" - Application.check + described_class.check end end describe 'delegation' do it "should delegate route" do - Application.rack_adapter.should_receive(:route).once.with :path => :query + described_class.rack_adapter.should_receive(:route).once.with :path => :query - Application.route :path => :query + described_class.route :path => :query end end describe 'rack_adapter' do it 'should be there' do - lambda { Application.rack_adapter }.should_not raise_error + lambda { described_class.rack_adapter }.should_not raise_error end it "should return a new FrontendAdapters::Rack instance" do - Application.rack_adapter.should be_kind_of(FrontendAdapters::Rack) + described_class.rack_adapter.should be_kind_of(Picky::FrontendAdapters::Rack) end it "should cache the instance" do - Application.rack_adapter.should == Application.rack_adapter + described_class.rack_adapter.should == described_class.rack_adapter end end describe 'call' do before(:each) do @routes = stub :routes - Application.stub! :rack_adapter => @routes + described_class.stub! :rack_adapter => @routes end it 'should delegate' do @routes.should_receive(:call).once.with :env - Application.call :env + described_class.call :env end end end \ No newline at end of file