Last active
July 19, 2020 07:34
-
-
Save DannyBen/6ad4ade97961856dc63efe3138046fcc to your computer and use it in GitHub Desktop.
Revisions
-
DannyBen revised this gist
Jul 19, 2020 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ Run with: ```shell $ bundle $ bundle exec rspec tty-prompt-test.rb ``` -
DannyBen created this gist
Jul 19, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ # frozen_string_literal: true source "https://rubygems.org" git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } gem "tty-prompt", github: 'piotrmurach/tty-prompt' gem "rspec" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ Run with: ```shell $ bundle exec rspec tty-prompt-test.rb ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ require 'tty-prompt' require "tty/prompt/test" class Subject def prompt @prompt ||= TTY::Prompt.new end def run "#{name} #{destiny}" end def name prompt.ask "Name:" end def destiny prompt.select("Destiny:", %w(Scorpion Kano Jax)) end end describe Subject do let(:prompt) { TTY::Prompt::Test.new } before do prompt.on :keypress do |e| prompt.trigger :keyup if e.value == "k" prompt.trigger :keydown if e.value == "j" end allow(subject).to receive(:prompt).and_return prompt end it "works" do prompt.input << "Danny" << "\n" << "j" << "\n" prompt.input.rewind expect(subject.run).to eq "Danny Kano" end it "works for sure" do prompt.input << "Danny" << "\n" << "j" << "j" << "\n" prompt.input.rewind expect(subject.run).to eq "Danny Jax" end end