From 49a6f8e0fb0712ca277948f2af73bc9d03d8d954 Mon Sep 17 00:00:00 2001 From: masa21kik Date: Mon, 9 Jun 2014 00:32:34 +0900 Subject: [PATCH] add spec for cli --- spec/json_cli/cli_spec.rb | 68 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 spec/json_cli/cli_spec.rb diff --git a/spec/json_cli/cli_spec.rb b/spec/json_cli/cli_spec.rb new file mode 100644 index 0000000..639453b --- /dev/null +++ b/spec/json_cli/cli_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' +require 'tempfile' + +describe JsonCli::CLI do + let(:cli) { described_class.new } + + shared_examples_for 'cli' do + before do + @result_file = Tempfile.new(File.basename(__FILE__)) + end + + after do + @result_file.close! + end + + it 'output expected JSON' do + args.map! { |f| File.join(FIXTURE_DIR, f) } + options.merge!(output: @result_file.path) + cli.invoke(command, args, options) + expect_file_path = File.join(FIXTURE_DIR, expect_file) + expect(File.read(@result_file.path)).to eq File.read(expect_file_path) + end + end + + context 'join' do + describe '#left_join' do + let(:args) { %w(attribute.json logfile.json) } + let(:options) { { join_key: '_id' } } + let(:command) { 'left_join' } + let(:expect_file) { 'join_logfile_attribute_id.json' } + it_behaves_like 'cli' + end + + describe '#right_join' do + let(:args) { %w(logfile.json attribute.json) } + let(:options) { { join_key: '_id' } } + let(:command) { 'right_join' } + let(:expect_file) { 'join_logfile_attribute_id.json' } + it_behaves_like 'cli' + end + + describe '#inner_join' do + let(:args) { %w(attribute.json logfile.json) } + let(:options) { { join_key: '_id' } } + let(:command) { 'inner_join' } + let(:expect_file) { 'inner_join_logfile_attribute_id.json' } + it_behaves_like 'cli' + end + end + + context 'unwind' do + describe '#unwind_array' do + let(:args) { %w(logfile.json) } + let(:options) { { unwind_key: 'tags' } } + let(:command) { 'unwind_array' } + let(:expect_file) { 'unwind_logfile_tags.json' } + it_behaves_like 'cli' + end + + describe '#unwind_hash' do + let(:args) { %w(logfile.json) } + let(:options) { { unwind_key: 'words' } } + let(:command) { 'unwind_hash' } + let(:expect_file) { 'unwind_logfile_words.json' } + it_behaves_like 'cli' + end + end +end