From 6a3f2ca007823190e755154c5e0df48f6a38cae7 Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Sun, 7 May 2017 17:11:42 +0200 Subject: [PATCH] add first tests for cli --- .travis.yml | 7 ++++++- test/test_cli.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ test/tests.rb | 7 ------- 3 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 test/test_cli.rb delete mode 100644 test/tests.rb diff --git a/.travis.yml b/.travis.yml index faa5c04..89d29f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,9 @@ install: - gem install mpw-9999.gem script: - rubocop - - ruby ./test/tests.rb + - ruby ./test/init.rb + - ruby ./test/test_config.rb + - ruby ./test/test_item.rb + - ruby ./test/test_mpw.rb + - ruby ./test/test_translate.rb + - ruby ./test/test_cli.rb diff --git a/test/test_cli.rb b/test/test_cli.rb new file mode 100644 index 0000000..0db3ffa --- /dev/null +++ b/test/test_cli.rb @@ -0,0 +1,50 @@ +#!/usr/bin/ruby + +require 'fileutils' +require 'test/unit' + +class TestConfig < Test::Unit::TestCase + def setup + @password = 'password' + end + + def test_00_init_config + FileUtils.rm_rf("#{Dir.home}/.config/mpw") + FileUtils.rm_rf("#{Dir.home}/.gnupg") + + output = `echo "#{@password}\n#{@password}" | mpw config --init test@example.com` + assert_match('The config file has been created', output) + assert_match('Your GPG key has been created ;-)', output) + end + + def test_01_add_item + host = 'example.com' + + output = `echo #{@password} | mpw add --host #{host} -r` + assert_match('Item has been added!', output) + + output = `echo #{@password} | mpw list` + assert_match(host, output) + end + + def test_02_update_item + host_old = 'example.com' + host_new = 'example2.com' + + output = `echo #{@password} | mpw update -p #{host_old} --host #{host_new}` + assert_match('Item has been updated!', output) + + output = `echo #{@password} | mpw list` + assert_match(host_new, output) + end + + def test_03_delete_item + host = 'example2.com' + + output = `echo "#{@password}\ny" | mpw delete -p #{host}` + assert_match('The item has been removed!', output) + + output = `echo #{@password} | mpw list` + assert_no_match(/#{host}/, output) + end +end diff --git a/test/tests.rb b/test/tests.rb deleted file mode 100644 index 7f3fc7d..0000000 --- a/test/tests.rb +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/ruby - -require_relative 'init.rb' -require_relative 'test_config.rb' -require_relative 'test_item.rb' -require_relative 'test_mpw.rb' -require_relative 'test_translate.rb'