Skip to content

Commit e582cd2

Browse files
committed
Added RSpec tests to validate the advisories.
1 parent 5080075 commit e582cd2

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

.rspec

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--colour

spec/advisory_example.rb

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
require 'spec_helper'
2+
require 'yaml'
3+
4+
shared_examples_for 'Advisory' do |path|
5+
advisory = YAML.load_file(path)
6+
7+
describe path do
8+
let(:gem) { File.basename(File.dirname(path)) }
9+
let(:cve) { File.basename(path).chomp('.yml') }
10+
11+
describe "gem" do
12+
subject { advisory['gem'] }
13+
14+
it { should be_kind_of(String) }
15+
it { should == gem }
16+
end
17+
18+
describe "cve" do
19+
subject { advisory['cve'] }
20+
21+
it { should be_kind_of(String) }
22+
it { should == cve }
23+
end
24+
25+
describe "url" do
26+
subject { advisory['url'] }
27+
28+
it { should be_kind_of(String) }
29+
it { should_not be_empty }
30+
end
31+
32+
describe "title" do
33+
subject { advisory['title'] }
34+
35+
it { should be_kind_of(String) }
36+
it { should_not be_empty }
37+
end
38+
39+
describe "description" do
40+
subject { advisory['description'] }
41+
42+
it { should be_kind_of(String) }
43+
it { should_not be_empty }
44+
end
45+
46+
describe "cvss_v2" do
47+
subject { advisory['cvss_v2'] }
48+
49+
it "may be nil or a Float" do
50+
[NilClass, Float].should include(subject.class)
51+
end
52+
53+
case advisory['cvss_v2']
54+
when Float
55+
context "when a Float" do
56+
it { ((0.0)..(10.0)).should include(subject) }
57+
end
58+
end
59+
end
60+
61+
describe "patched_versions" do
62+
subject { advisory['patched_versions'] }
63+
64+
it { should be_kind_of(Array) }
65+
it { should_not be_empty }
66+
67+
advisory['patched_versions'].each do |version|
68+
describe version do
69+
subject { version.split(', ') }
70+
71+
it "should contain valid RubyGem version requirements" do
72+
lambda {
73+
Gem::Requirement.new(version)
74+
}.should_not raise_error(ArgumentError)
75+
end
76+
end
77+
end
78+
end
79+
end
80+
end

spec/gems_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'spec_helper'
2+
require 'advisory_example'
3+
4+
describe "gems" do
5+
Dir.glob('gems/*/*.yml') do |path|
6+
include_examples 'Advisory', path
7+
end
8+
end

spec/spec_helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'rspec'

0 commit comments

Comments
 (0)