diff options
Diffstat (limited to 'test/acceptance/acceptance_test.rb')
-rw-r--r-- | test/acceptance/acceptance_test.rb | 106 |
1 files changed, 54 insertions, 52 deletions
diff --git a/test/acceptance/acceptance_test.rb b/test/acceptance/acceptance_test.rb index 19f6dea..b77e56d 100644 --- a/test/acceptance/acceptance_test.rb +++ b/test/acceptance/acceptance_test.rb @@ -1,69 +1,71 @@ # coding: utf-8 -require 'highline/import' +require "highline/import" -class HighLine::AcceptanceTest - @@answers ||= {} +class HighLine + class AcceptanceTest + @answers ||= {} - def self.check(&block) - caller_file = File.basename(caller[0].split(":")[-3]) + class << self + attr_reader :answers + end - test = new - yield test - test.caller_file = caller_file - test.check - end + def self.check + caller_file = File.basename(caller(1..1).first.split(":")[-3]) - def self.answers - @@answers - end + test = new + yield test + test.caller_file = caller_file + test.check + end - def self.answers_for_report - answers.map do |file, answer| - "#{file}: #{answer}" - end.join("\n") - 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 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 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 + # 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 + # 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 + 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 + # 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 + # Gather the user feedback about the test + print question + answer = STDIN.gets.chomp + answer = "y" if answer.empty? + HighLine::AcceptanceTest.answers[caller_file] = answer - puts + puts + end end end |