Skip to content

Commit

Permalink
changed failure report to array and started slicing lower portions
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Newton committed Jan 15, 2018
1 parent 87a25ff commit d75361e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions lib/jcr/evaluate_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def initialize success, reason
class EvalConditions
attr_accessor :mapping, :callbacks, :trace, :trace_stack, :failures
def initialize mapping, callbacks, trace = false
@failures = {}
@failures = []
@mapping = mapping
@trace = trace
@trace_stack = []
Expand All @@ -68,14 +68,14 @@ def initialize mapping, callbacks, trace = false
end

def report_failure failure
stack_level = trace_stack.length
stack_level = trace_stack.length - 1
@failures[ stack_level ] = Array.new unless @failures[ stack_level ]
@failures[ stack_level ] << failure
end

def report_success
stack_level = trace_stack.length
@failures.delete( stack_level )
stack_level = trace_stack.length - 1
@failures.slice!( stack_level..-1 )
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/jcr/jcr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def self.failure_report ctx
else
report << "- Failures for root rule at line #{failed_root.pos[0]}"
end
failed_root.failures.sort.map do |stack_level, failures|
failed_root.failures.each_with_index do |failures,stack_level|
if failures.length > 1
report << " - failure at rule level #{stack_level} caused by one of the following #{failures.length} reasons"
else
Expand Down
2 changes: 1 addition & 1 deletion lib/jcr/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@

module JCR

VERSION = "0.8.2"
VERSION = "0.8.3"

end
14 changes: 7 additions & 7 deletions spec/trace_fails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,45 +55,45 @@
data = JSON.parse( '["bar"]')
e = ctx.evaluate( data )
expect( ctx.failed_roots[0].failures.length ).to eq( 2 )
expect( ctx.failed_roots[0].failures[0].length ).to eq( 1 )
expect( ctx.failed_roots[0].failures[1].length ).to eq( 1 )
expect( ctx.failed_roots[0].failures[2].length ).to eq( 1 )
end

it 'should have two fail level w/ one fail' do
ctx = JCR::Context.new( '[ 0..2 *2 ]', false )
data = JSON.parse( '[1, "bar"]')
e = ctx.evaluate( data )
expect( ctx.failed_roots[0].failures.length ).to eq( 2 )
expect( ctx.failed_roots[0].failures[0].length ).to eq( 1 )
expect( ctx.failed_roots[0].failures[1].length ).to eq( 1 )
expect( ctx.failed_roots[0].failures[2].length ).to eq( 1 )
end

it 'should have two fail level w/ one fail also' do
ctx = JCR::Context.new( '[ 0..2 *2 ]', false )
data = JSON.parse( '["bar", 1]')
e = ctx.evaluate( data )
expect( ctx.failed_roots[0].failures.length ).to eq( 2 )
expect( ctx.failed_roots[0].failures[0].length ).to eq( 1 )
expect( ctx.failed_roots[0].failures[1].length ).to eq( 1 )
expect( ctx.failed_roots[0].failures[2].length ).to eq( 1 )
end

it 'should have two fail level w/ or' do
ctx = JCR::Context.new( '[ "foo" | "bar" ]', false )
data = JSON.parse( '["baz"]')
e = ctx.evaluate( data )
expect( ctx.failed_roots[0].failures.length ).to eq( 2 )
expect( ctx.failed_roots[0].failures[1].length ).to eq( 1 )
expect( ctx.failed_roots[0].failures[2].length ).to eq( 2 )
expect( ctx.failed_roots[0].failures[0].length ).to eq( 1 )
expect( ctx.failed_roots[0].failures[1].length ).to eq( 2 )
end

it 'should have two fail level w/ two fail' do
ctx = JCR::Context.new( '[ ("foo" | "bar"), 0..2 ]', false )
data = JSON.parse( '["baz", 3]')
e = ctx.evaluate( data )
expect( ctx.failed_roots[0].failures.length ).to eq( 3 )
expect( ctx.failed_roots[0].failures[0].length ).to eq( 1 )
expect( ctx.failed_roots[0].failures[1].length ).to eq( 1 )
expect( ctx.failed_roots[0].failures[2].length ).to eq( 1 )
expect( ctx.failed_roots[0].failures[3].length ).to eq( 2 )
expect( ctx.failed_roots[0].failures[2].length ).to eq( 2 )
end

end

0 comments on commit d75361e

Please sign in to comment.