spec/advisory_spec.rb in mrjoy-bundler-audit-0.3.1 vs spec/advisory_spec.rb in mrjoy-bundler-audit-0.3.2
- old
+ new
@@ -6,17 +6,17 @@
let(:root) { Bundler::Audit::Database::VENDORED_PATH }
let(:gem) { 'actionpack' }
let(:id) { 'OSVDB-84243' }
let(:path) { File.join(root,'gems',gem,"#{id}.yml") }
let(:an_unaffected_version) do
- YAML.
- load(File.read(path))['unaffected_versions'].
- map { |item| item.split(/\s*,\s*/) }.
- flatten.
- select { |ver| ver =~ /^(~>|>=|=|<=)/ }.
- first.
- sub(/^.*?(~>|>=|=|<=)\s+/, '')
+ Advisory.load(path).
+ unaffected_versions. # Only care about unaffected versions...
+ first. # And even then, any will do.
+ requirements. # This is where we find versions...
+ first. # Again, any will do.
+ last. # We don't care about the bound, just the version number.
+ to_s # And we'd like it as a string.
end
describe "load" do
let(:data) { YAML.load_file(path) }
@@ -25,9 +25,18 @@
its(:id) { should == id }
its(:url) { should == data['url'] }
its(:title) { should == data['title'] }
its(:cvss_v2) { should == data['cvss_v2'] }
its(:description) { should == data['description'] }
+
+ context "YAML data not representing a hash" do
+ it "should raise an exception" do
+ path = File.expand_path('../fixtures/not_a_hash.yml', __FILE__)
+ expect {
+ Advisory.load(path)
+ }.to raise_exception("advisory data in #{path.dump} was not a Hash")
+ end
+ end
describe "#patched_versions" do
subject { described_class.load(path).patched_versions }
it "should all be Gem::Requirement objects" do