Sha256: 2ee1698bc8b5c2ce4446fdc88f0453bf924525deeb96bd959cebabf0b770342b

Contents?: true

Size: 616 Bytes

Versions: 5

Compression:

Stored size: 616 Bytes

Contents

def object_attributes_match_table!(obj, table)
  row_pairs = table.raw.each_slice(2)
  attribute_exprs = row_pairs.map( &:first ).reduce( :+ )
  expected_exprs  = row_pairs.map( &:last  ).reduce( :+ )

  actuals   = attribute_exprs .map{ |expr| eval_obj_expression(obj, expr) }
  expecteds = expected_exprs  .map{ |expr| eval( expr ) }

  actual_hash   = Hash[ attribute_exprs.zip( actuals   ) ]
  expected_hash = Hash[ attribute_exprs.zip( expecteds ) ]
  expect( actual_hash ).to eq( expected_hash )
end

def eval_obj_expression(obj, expr)
  expr = ".#{expr}" unless expr.start_with?('[')
  eval("obj#{expr}")
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
son_jay-0.5.2 features/support/attribute_value_verification.rb
son_jay-0.5.1 features/support/attribute_value_verification.rb
son_jay-0.5.0 features/support/attribute_value_verification.rb
son_jay-0.4.1 features/support/attribute_value_verification.rb
son_jay-0.4.0 features/support/attribute_value_verification.rb