Skip to content

Commit

Permalink
minor test refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Mar 7, 2015
1 parent 48bceaf commit 9a8f628
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions spec/commands/tree_commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ def forest
{'a' => {'b' => {'a' => '1'}}}
end

def rename_key(from, to)
JSON.parse run_cmd(:tree_rename_key, key: from, name: to, format: 'json', arguments: [forest.to_json])
end

it 'renames root node' do
renamed = JSON.parse run_cmd(:tree_rename_key, key: 'a', name: 'x', format: 'json', arguments: [forest.to_json])
expect(renamed).to eq(forest.tap { |f| f['x'] = f.delete('a') })
expect(rename_key('a', 'x')).to eq(forest.tap { |f| f['x'] = f.delete('a') })
end
it 'renames node' do
renamed = JSON.parse run_cmd(:tree_rename_key, key: 'a.b', name: 'x', format: 'json', arguments: [forest.to_json])
expect(renamed).to eq(forest.tap { |f| f['a']['x'] = f['a'].delete('b') })
expect(rename_key('a.b', 'x')).to eq(forest.tap { |f| f['a']['x'] = f['a'].delete('b') })
end
it 'renames leaf' do
renamed = JSON.parse run_cmd(:tree_rename_key, key: 'a.b.a', name: 'x', format: 'json', arguments: [forest.to_json])
expect(renamed).to eq(forest.tap { |f| f['a']['b']['x'] = f['a']['b'].delete('a') })
expect(rename_key('a.b.a', 'x')).to eq(forest.tap { |f| f['a']['b']['x'] = f['a']['b'].delete('a') })
end
end

Expand Down

0 comments on commit 9a8f628

Please sign in to comment.