# encoding: utf-8 require "spec_helper" module Corrector describe Parse do describe ".new" do before do create :prefix, from: "КИЛО", to: "К", scope: "UNITS" create :word, from: "МЕТРОВ", to: "М", scope: "UNITS" create :word, from: "МЕТРА", to: "М", scope: "UNITS" create :word, from: "ЧАС", to: "Ч", scope: "UNITS" create :phrase, from: "КМ В Ч", to: "КМ/Ч", scope: "UNITS" end specify do expect(Parse.new "Километров/час", scope: "UNITS").to eq "КМ/Ч" end specify do expect(Parse.new "Километра в час", scope: "UNITS").to eq "КМ/Ч" end specify do expect(Parse.new "3 километра", scope: "UNITS").to eq "3 КМ" end specify do expect(Parse.new "100 метров/час", scope: "UNITS").to eq "100 М/Ч" end it "caches db requests in a same scope", :caching do str = "Километров/час" Parse.new str, scope: "UNITS" [Word, Prefix, Phrase] .each { |klass| expect(klass).not_to receive(:scan) } Parse.new str, scope: "UNITS" end it "doesn't use cache from another scope", :caching do str = "Километров/час" Parse.new str, scope: "UNITS" [Word, Prefix, Phrase] .each { |klass| expect(klass).to receive(:scan).at_least(:once) } Parse.new str, scope: "CURRENCIES" end end describe "#source" do it "stores a source" do source = "abcd" expect(Parse.new(source, scope: "UNITS").source).to eq source end end end end