diff options
| -rw-r--r-- | lib/tom_tom.rb | 2 | ||||
| -rw-r--r-- | spec/lib/tom_tom_spec.rb | 12 | 
2 files changed, 9 insertions, 5 deletions
| diff --git a/lib/tom_tom.rb b/lib/tom_tom.rb index 9158b7a28..91f1a3800 100644 --- a/lib/tom_tom.rb +++ b/lib/tom_tom.rb @@ -17,7 +17,7 @@ module TomTom    end    def self.enabled? -    api_key.present? +    api_key.present? && /[a-zA-Z0-9]{32}/ === api_key    end    def self.batch(way_costs) diff --git a/spec/lib/tom_tom_spec.rb b/spec/lib/tom_tom_spec.rb index 71584e242..4571609c3 100644 --- a/spec/lib/tom_tom_spec.rb +++ b/spec/lib/tom_tom_spec.rb @@ -1,15 +1,19 @@  RSpec.describe TomTom do    describe ".enabled?" do      it "returns true when API key is set" do -      TomTom.instance_variable_set(:@api_key, 'fake key') - +      dummy_key = ['a'..'z','A'..'Z',0..9].map(&:to_a).flatten.sample(32).join +      allow(TomTom).to receive(:api_key).and_return dummy_key        expect(TomTom.enabled?).to be true      end      it "returns false without an API key" do -      TomTom.instance_variable_set(:@api_key, '') +      allow(TomTom).to receive(:api_key).and_return '' +      expect(TomTom.enabled?).to be_falsy +    end -      expect(TomTom.enabled?).to be false +    it "returns false when API key is malformed" do +      allow(TomTom).to receive(:api_key).and_return 'it will not work' +      expect(TomTom.enabled?).to be_falsy      end    end  end | 
