spec/results_spec.rb in outliers-0.3.3 vs spec/results_spec.rb in outliers-0.5.0.beta1

- old
+ new

@@ -1,40 +1,89 @@ require 'spec_helper' describe Outliers::Result do + let(:resource1) {stub 'resource1', id: 1} + let(:resource2) {stub 'resource2', id: 2} + context "passing" do - subject { Outliers::Result.new evaluation: 'evalme', + subject { Outliers::Result.new account_name: 'cnt', + arguments: ['test123'], failing_resources: [], - passing_resources: ['key1', 'key2'], - resource: 'instance', - verification: 'vpc' } - - it "should return passed" do - expect(subject.to_s).to eq 'passed' - end + name: 'evalme', + passing_resources: [resource1, resource2], + provider_name: 'aws', + resource_name: 'instance', + verification_name: 'vpc' } it "should return true for passing verification" do expect(subject.passed?).to be_true end it "should return false for failing verification" do expect(subject.failed?).to be_false end it "should return the result information" do - expect(subject.passing_resources).to eq(['key1', 'key2']) + expect(subject.passing_resources).to eq([resource1, resource2]) end + + + it "should return the result information" do + expect(subject.account_name).to eq('cnt') + expect(subject.failing_resources).to eq([]) + expect(subject.name).to eq('evalme') + expect(subject.passing_resources).to eq([resource1, resource2]) + expect(subject.provider_name).to eq('aws') + expect(subject.resource_name).to eq('instance') + expect(subject.verification_name).to eq('vpc') + end + + context "#name" do + subject { Outliers::Result.new({}) } + + it "should set the name to unspecified if not set" do + expect(subject.name).to eq('unspecified') + end + end + + context "#to_json" do + it "should return the results as json" do + resources = [ { 'id' => 1, 'passing' => 1 }, { 'id' => 2, 'passing' => 1 } ] + json = { 'account_name' => 'cnt', + 'arguments' => ['test123'], + 'name' => 'evalme', + 'provider_name' => 'aws', + 'resource_name' => 'instance', + 'verification_name' => 'vpc', + 'resources' => resources }.to_json + expect(subject.to_json).to eq(json) + end + end + + context "#to_hash" do + it "should return the results as hash" do + resources = [ { 'id' => 1, 'passing' => 1 }, { 'id' => 2, 'passing' => 1 } ] + hash = { 'account_name' => 'cnt', + 'arguments' => ['test123'], + 'name' => 'evalme', + 'provider_name' => 'aws', + 'resource_name' => 'instance', + 'verification_name' => 'vpc', + 'resources' => resources } + expect(subject.to_hash).to eq(hash) + end + end end context "failing" do - subject { Outliers::Result.new evaluation: 'evalme', - failing_resources: ['key3', 'key4'], + subject { Outliers::Result.new account_name: 'cnt', + arguments: ['test123'], + failing_resources: [resource1, resource2], + name: 'evalme', passing_resources: [], - resource: 'instance', - verification: 'vpc' } - it "should return failed" do - expect(subject.to_s).to eq 'failed' - end + provider_name: 'aws', + resource_name: 'instance', + verification_name: 'vpc' } it "should return false for passing verification" do expect(subject.passed?).to be_false end