diff options
-rw-r--r-- | Rakefile | 5 | ||||
-rw-r--r-- | test/acceptance/acceptance.rb | 62 | ||||
-rw-r--r-- | test/acceptance/acceptance_test.rb | 69 | ||||
-rw-r--r-- | test/acceptance/at_color_output_using_erb_templates.rb | 17 | ||||
-rw-r--r-- | test/acceptance/at_echo_false.rb | 23 | ||||
-rw-r--r-- | test/acceptance/at_readline.rb | 37 |
6 files changed, 213 insertions, 0 deletions
@@ -27,3 +27,8 @@ end Gem::PackageTask.new(SPEC) do |package| # do nothing: I just need a gem but this block is required end + +desc "Run some interactive acceptance tests" +task :acceptance do + load "test/acceptance/acceptance.rb" +end diff --git a/test/acceptance/acceptance.rb b/test/acceptance/acceptance.rb new file mode 100644 index 0000000..edef458 --- /dev/null +++ b/test/acceptance/acceptance.rb @@ -0,0 +1,62 @@ +#!/usr/bin/env ruby +# coding: utf-8 + +current_dir = File.dirname(File.expand_path(__FILE__)) + +# All acceptance test files begins with 'at_' +acceptance_test_files = Dir["#{current_dir}/at_*"] + +# Load each acceptance test file making +# all tests to be run +acceptance_test_files.each { |file| load file } + +# Print a report + +report = <<EOF + +=== +Well done! + +Below you have a report with all the answers you gave. +It has also some environment information to help us debugging. + +If any of the tests have not passed on your environment, +please copy/past the text bellow and send to us. + +If you are familiar with GitHub you can report the failing test +as a GitHub issue at https://github.com/JEG2/highline/issues. +If possible, always check if your issue is already reported +by someone else. If so, just report that you are also affected +on the same alredy open issued. + +If you are more confortable with e-mail, you could send it to +james@grayproductions.net + +=== HighLine Acceptance Tests Report +Date: #{Time.now.utc} +HighLine::VERSION: #{HighLine::VERSION} +Terminal: #{$terminal.terminal.class} +RUBY_DESCRIPTION: #{RUBY_DESCRIPTION rescue 'not available'} +Readline::VERSION: #{Readline::VERSION rescue 'not availabe'} +ENV['SHELL']: #{ENV['SHELL']} +ENV['TERM']: #{ENV['TERM']} +ENV['TERM_PROGRAM']: #{ENV['TERM_PROGRAM']} + +Answers: +#{HighLine::AcceptanceTest.answers_for_report} +EOF + +puts report + +timestamp = Time.now.strftime('%Y%m%d%H%M%S') +filename = "highlinetests-#{timestamp}.log" + +File.open "#{filename}", 'w+' do |f| + f.puts report +end + +puts +puts "You can also see the above information in" +puts "a timestamped file named #{filename}" +puts "at the current directory." +puts diff --git a/test/acceptance/acceptance_test.rb b/test/acceptance/acceptance_test.rb new file mode 100644 index 0000000..0b321a6 --- /dev/null +++ b/test/acceptance/acceptance_test.rb @@ -0,0 +1,69 @@ +# coding: utf-8 + +require 'highline/import' + +class HighLine::AcceptanceTest + @@answers ||= {} + + def self.check(&block) + caller_file = File.basename(caller[0].split(":")[0]) + + test = new + yield test + test.caller_file = caller_file + test.check + end + + def self.answers + @@answers + end + + def self.answers_for_report + answers.map do |file, answer| + "#{file}: #{answer}" + end.join("\n") + end + + # A test description to be shown to user. + # It should express what the user is + # expected to check. + attr_accessor :desc + + # A test action to be checked by the user + attr_accessor :action + + # A text asking the confirmation if + # the action worked (y) or not (n). + attr_accessor :question + + # Automatically filled attribute pointing + # to the file where the current test + # source is located. So we could check + # at the report what tests passed or failed. + attr_accessor :caller_file + + def check + # Print a header with the test description + puts "=====" + puts " #{caller_file}" + puts "=====" + puts + puts desc + + # Execute the proc/lambda assigned to action + puts "---" + puts + action.call + puts + puts "---" + puts + + # Gather the user feedback about the test + print question + answer = STDIN.gets.chomp + answer = "y" if answer.empty? + @@answers[caller_file] = answer + + puts + end +end diff --git a/test/acceptance/at_color_output_using_erb_templates.rb b/test/acceptance/at_color_output_using_erb_templates.rb new file mode 100644 index 0000000..c45f264 --- /dev/null +++ b/test/acceptance/at_color_output_using_erb_templates.rb @@ -0,0 +1,17 @@ +# coding: utf-8 + +require_relative 'acceptance_test' + +HighLine::AcceptanceTest.check do |t| + t.desc = + "This step checks if coloring " \ + "with erb templates is working ok.\n" \ + "You should see the word _grass_ " \ + "colored in green color" + + t.action = Proc.new do + say "The <%= color('grass', :green) %> should be green!" + end + + t.question = "Do you see the word 'grass' on green color (y/n)? " +end diff --git a/test/acceptance/at_echo_false.rb b/test/acceptance/at_echo_false.rb new file mode 100644 index 0000000..2466b8d --- /dev/null +++ b/test/acceptance/at_echo_false.rb @@ -0,0 +1,23 @@ +# coding: utf-8 + +require_relative 'acceptance_test' + +HighLine::AcceptanceTest.check do |t| + t.desc = + "This step checks if the 'echo = false' " \ + "setting is effective in hiding the user " \ + "typed characters.\n" \ + "This functionality is useful when asking " \ + "for passwords.\n" \ + "When typing the characters you should not " \ + "see any of them on the screen." + + t.action = Proc.new do + answer = ask "Enter some characters and press <enter>: " do |q| + q.echo = false + end + puts "You've entered -> #{answer} <-" + end + + t.question = "Were the characters adequately hidden when you typed them (y/n)? " +end diff --git a/test/acceptance/at_readline.rb b/test/acceptance/at_readline.rb new file mode 100644 index 0000000..8a66f09 --- /dev/null +++ b/test/acceptance/at_readline.rb @@ -0,0 +1,37 @@ +# coding: utf-8 + +require_relative 'acceptance_test' + +HighLine::AcceptanceTest.check do |t| + t.desc = + "This step checks if the readline autocomplete " \ + "feature is working. \n" \ + "The test has 5 options you can choose from: " \ + "save, sample, exec, exit and load.\n" \ + "If you type the first character of one of them and then press \n" \ + "the <TAB> key you should see the options available for autocomplete.\n\n" \ + "For example, if I type 's' and then I press <TAB> I should see a list\n" \ + "with 'save' and 'sample' as possible options for autocomplete.\n\n" \ + "Although, if I type 'l' and then press the <TAB> key it should be \n" \ + "readly autcompleted as 'load', because 'load' is the only option\n" \ + "that begins with the 'l' letter in this particular case.\n\n" \ + "If I don't type any character but press <TAB> two times, I should\n" \ + "be able to see ALL available options.\n\n" \ + "Please, play with Readline autocomplete for a while, pressing <ENTER>\n" \ + "to see that it really gets the selected answer.\n" \ + "When ready, just type 'exit' and the loop will finish.\n\n" \ + "Don't forget to answer 'y' (yes) or 'n' (no) to the question at the end." + + t.action = Proc.new do + loop do + cmd = + ask "Enter command: ", %w{ save sample exec exit load } do |q| + q.readline = true + end + say("Executing \"#{cmd}\"...") + break if cmd == "exit" + end + end + + t.question = "Did the Readline autocomplete work fine (y/n)? " +end |