spec/balboa/cli/defaults_spec.rb in balboa-0.1.6 vs spec/balboa/cli/defaults_spec.rb in balboa-0.1.7

- old
+ new

@@ -2,6 +2,186 @@ require 'spec_helper' require 'highline' describe Balboa::CLI::Defaults do + it 'welcomes the user' do + input = StringIO.new + output = StringIO.new + cli = HighLine.new(input, output) + + input << "john@doe.com\n" + input << "john@doe.com\n" + input << "Doe Company\n" + input << "\n" + input << "\n" + input << "\n" + input << "\n" + input.rewind + + described_class.prompt(cli) + + expect(output.string).to include('First run. Please type your settings!') + end + + it 'does not show input password' do + input = StringIO.new + output = StringIO.new + cli = HighLine.new(input, output) + + password = 'motherlode' + + input << "john@doe.com\n" + input << "#{password}\n" + input << "Doe Company\n" + input << "\n" + input << "\n" + input << "\n" + input << "\n" + input.rewind + + described_class.prompt(cli) + + expect(output.string).not_to include(password) + end + + it 'prompts for attributes and fill some with default value' do + input = StringIO.new + output = StringIO.new + cli = HighLine.new(input, output) + + input << "john@doe.com\n" + input << "john@doe.com\n" + input << "Doe Company\n" + input << "\n" + input << "\n" + input << "\n" + input << "\n" + input.rewind + + config = described_class.prompt(cli) + + expect(config).to eq( + 'email' => 'john@doe.com', + 'password' => 'john@doe.com', + 'project' => 'Doe Company', + 'start_at' => '8', + 'lunch_at' => '12', + 'restart_at' => '13', + 'leave_at' => '17', + 'skips' => [] + ) + end + + it 'prompts for password but removes if empty' do + input = StringIO.new + output = StringIO.new + cli = HighLine.new(input, output) + + input << "john@doe.com\n" + input << "\n" + input << "Doe Company\n" + input << "\n" + input << "\n" + input << "\n" + input << "\n" + input.rewind + + config = described_class.prompt(cli) + + expect(config).to eq( + 'email' => 'john@doe.com', + 'project' => 'Doe Company', + 'start_at' => '8', + 'lunch_at' => '12', + 'restart_at' => '13', + 'leave_at' => '17', + 'skips' => [] + ) + end + + it 'prompts for attributes and place them in the right spot' do + input = StringIO.new + output = StringIO.new + cli = HighLine.new(input, output) + + input << "john@doe.com\n" + input << "john@doe.com\n" + input << "Doe Company\n" + input << "13\n" + input << "14\n" + input << "15\n" + input << "16\n" + input.rewind + + config = described_class.prompt(cli) + + expect(config).to eq( + 'email' => 'john@doe.com', + 'password' => 'john@doe.com', + 'project' => 'Doe Company', + 'start_at' => '13', + 'lunch_at' => '14', + 'restart_at' => '15', + 'leave_at' => '16', + 'skips' => [] + ) + end + + it 'prompts for attributes and place them in the right spot' do + input = StringIO.new + output = StringIO.new + cli = HighLine.new(input, output) + + input << "john@doe.com\n" + input << "john@doe.com\n" + input << "Doe Company\n" + input << "13\n" + input << "14\n" + input << "15\n" + input << "16\n" + input.rewind + + file = double('file') + open_args = [Balboa::CONFIG_FILE, 'w'] + config = { + 'email' => 'john@doe.com', + 'password' => 'john@doe.com', + 'project' => 'Doe Company', + 'start_at' => '13', + 'lunch_at' => '14', + 'restart_at' => '15', + 'leave_at' => '16', + 'skips' => [] + } + + expect(File).to receive(:open).with(*open_args).and_yield(file) + expect(file).to receive(:write).with(config.to_yaml) + + described_class.prompt(cli) + end + + it 'prompts for schedule and adapt on each input' do + input = StringIO.new + output = StringIO.new + cli = HighLine.new(input, output) + + input << "john@doe.com\n" + input << "john@doe.com\n" + input << "Doe Company\n" + input << "1\n" + input << "2\n" + input << "4\n" + input << "8\n" + input.rewind + + described_class.prompt(cli) + + expectations = [ + 'First shift: |8|', + 'Lunch: |5|', + 'Second shift: |3|', + 'Leave: |11|' + ] + expect(output.string).to include(*expectations) + end end