spec/dictionary_spec.rb in ffi-hunspell-0.5.0 vs spec/dictionary_spec.rb in ffi-hunspell-0.6.0

- old
+ new

@@ -47,15 +47,53 @@ subject { described_class.new(affix_path,dic_path) } after { subject.close } it "should provide the encoding of the dictionary files" do - expect(subject.encoding).to be Encoding::ISO_8859_1 + expect(subject.encoding).to be_instance_of Encoding end it "should check if a word is valid" do expect(subject.valid?('dog')).to be true expect(subject.valid?('dxg')).to be false + end + + describe "#add_dic" do + let(:extra_dic) { File.join(File.dirname(__FILE__),'fixtures/extra.dic') } + + if FFI::Hunspell.respond_to?(:Hunspell_add_dic) + context "when libhunspell supports add_dic" do + before do + subject.add_dic(extra_dic) + end + + it "should add an extra dictionary" do + expect(subject.add_dic(extra_dic)).to be 0 + end + + context "when the given extra dictionary file cannot be found" do + it do + expect { subject.add_dic('foo') }.to raise_error(ArgumentError) + end + end + + it "should validate a word from the extra dictionary" do + expect(subject.valid?('dxg')).to be true + end + + it "should validate an affixed word based on an affix flag from base affix file" do + expect(subject.valid?('dxgs')).to be true + end + end + else + context "when libhunspell does not support add_dic" do + it "should raise an error" do + expect { + subject.add_dic(extra_dic) + }.to raise_error(NotImplementedError) + end + end + end end describe "#add" do it "should add a word" do expect(subject.add('cat')).to be 0