require 'spec_helper'

describe Metrics::Spelling do

  it "#detect_language" do
    record = { notes: "This is a text." }
    metric = Metrics::Spelling.new
    expect(metric.detect_language(record)).to eq(:english)
  end

  it "should determine the number of spelling mistakes" do
    record = { notes: "Is this a aaaatext?" }
    metric = Metrics::Spelling.new
    score, analysis = metric.compute(record)
    accessor = [:notes]
    expect(score).to be(0.75) 
    expect(analysis[accessor]).to eq({ score: 0.75, misspelled: ['aaaatext'] })
  end

  it "should also work on nested records" do
    record = { resources: { description: 'This is a text.' } }
    metric = Metrics::Spelling.new
    score, analysis = metric.compute(record)
    accessor = [:resources, :description]
    expect(score).to be(1.0) 
    expect(analysis[accessor]).to eq({ score: 1.0, misspelled: []})
  end

end

Add unit test for the spelling metric
Add unit test for the spelling metric

I have added a unit test for the spelling metric in order to make sure
the refactoring works as intended.

Signed-off-by: Konrad Reiche <4ff0213f56e2082fcd8c882d04c546881c579ce4@gmail.com>
