spec/collection_spec.rb in outliers-0.5.1 vs spec/collection_spec.rb in outliers-0.6.0

- old
+ new

@@ -34,10 +34,14 @@ subject.exclude_by_key ['resource1'] expect(subject.list).to eq([resource2]) end end + context "#verifications" do + it "should return the shared and collection verifications" + end + context "#filter" do before do subject.instance_variable_set(:@list, [resource1, resource2, resource3]) end @@ -112,39 +116,43 @@ Outliers::Collection.stub :resource_class => resource_class end it "should verify the given verification against the colection" do expect(subject.verify 'none_exist?'). - to eq( { failing_resources: [resource1, resource2], passing_resources: [] } ) + to eq({ resources: [{ id: "resource1", status: 2 }, + { id: "resource2", status: 2 }], passing: false }) end it "should raise unkown verification if the verification does not exist" do expect { subject.verify 'none' }.to raise_error Outliers::Exceptions::UnknownVerification end it "should verify the given verification against the colection with options" do expect(subject.verify 'equals?', ['resource1', 'resource2']). - to eq( { failing_resources: [], passing_resources: [resource1, resource2] } ) + to eq({ resources: [{ id: "resource1", status: 2 }, + { id: "resource2", status: 2 }], passing: true }) end it "should verify the given verification against each resource in the collection" do [resource1, resource2].each {|r| r.define_singleton_method :valid_resource?, lambda { true } } expect(subject.verify 'valid_resource?'). - to eq( { failing_resources: [], passing_resources: [resource1, resource2] } ) + to eq({ resources: [{ id: "resource1", status: 0 }, + { id: "resource2", status: 0 }], passing: true }) end it "should appaned a ? to the policy" do expect(subject.verify 'none_exist'). - to eq( { failing_resources: [resource1, resource2], passing_resources: [] } ) + to eq({ resources: [{ id: "resource1", status: 2 }, + { id: "resource2", status: 2 }], passing: false }) end it "should remove all but the target resources if one is required and given" do subject.targets = ['resource1', 'in-valid'] resource1.should_receive(:method).with('valid_resource?').and_return(stub 'method', :arity => 0) resource1.should_receive(:valid_resource?).and_return false expect(subject.verify 'valid_resource?'). - to eq( { failing_resources: [resource1], passing_resources: [] } ) + to eq({ resources: [{ id: "resource1", status: 1 }], passing: false }) end it "should raise an error if the target resources does not exist" do subject.targets = ['in-valid'] expect { subject.verify 'valid_resource?' }.to raise_error(Outliers::Exceptions::TargetNotFound) @@ -159,19 +167,21 @@ resource1.define_singleton_method :valid_resource?, lambda { true } expect { subject.verify 'valid_resource?', 'unneeded argument' => 3 }. to raise_error(Outliers::Exceptions::NoArgumentRequired) end - it "should return empty passing and failing arrays if no resources exist in list" do + it "should return empty resource array if no resources exist in list" do subject.stub :load_all => [] - expect(subject.verify 'valid_resource?', {}).to eq( { failing_resources: [], passing_resources: [] } ) + expect(subject.verify 'valid_resource?', {}). + to eq( { resources: [], passing: true } ) end it "should verify the given verification against each resource in the collection with options" do resource1.should_receive(:valid_resource?).with('test_arg' => 2).and_return true resource2.should_receive(:valid_resource?).with('test_arg' => 2).and_return true expect(subject.verify 'valid_resource?', 'test_arg' => 2). - to eq( { failing_resources: [], passing_resources: [resource1, resource2] } ) + to eq( { resources: [ { id: "resource1", status: 0}, + { id: "resource2", status: 0}], passing: true} ) end end end