Skip to content

Commit

Permalink
suppress output for verbose tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tcob committed Apr 15, 2018
1 parent 3ade6bf commit 1f0e655
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 20 deletions.
18 changes: 11 additions & 7 deletions lib/orgbots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
require_relative 'tasks/schedule'
require_relative 'config'

# Run through the setup checklist before proceeding
Config.new.checklist
puts TaskManager.new.shuffle_file

# Clear the screen and show a welcome message
system 'clear'
Reporter.new.welcome
# Query.new.authed_ratelimit

# Prompt the user to select which mode to run Orgbots in
Config.new.mode_config
# # Run through the setup checklist before proceeding
# Config.new.checklist

# # Clear the screen and show a welcome message
# system 'clear'
# Reporter.new.welcome

# # Prompt the user to select which mode to run Orgbots in
# Config.new.mode_config
2 changes: 1 addition & 1 deletion lib/tasks/random_commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(r, t)

def commit
content = genword
randombranch = BranchBot.new(@repo, @token).list_branches.sample
randombranch = BranchBot.new(@repo, @token).rand_branch
file = pick_file(randombranch)
file = genword.to_s + txt_ext if maybe
CommitBot.new(@repo, randombranch, @token).commit(file, content, genword)
Expand Down
12 changes: 4 additions & 8 deletions lib/tasks/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ def initialize
@t = ENV['TOKEN']
end

def rand_file_content
def shuffle_rand_file
@message = 'shufflin'
@branch = BranchBot.new(@r, @t).list_branches.sample
@file = FileBot.new(@r, @t).list_files(@branch).collect { |f| f[:path] }.sample
FileBot.new(@r, @t).get_contents(@file, @branch)[:content]
end

# Find a branch, find a file on that branch
def shuffle_file
@message = 'shufflin'
RandCommit.new(@r, @t).shuffle_file(@branch, @file, rand_file_content, @message)
@content = FileBot.new(@r, @t).get_contents(@file, @branch)[:content]
RandCommit.new(@r, @t).shuffle_file(@branch, @file, @content, @message)
end
end
5 changes: 5 additions & 0 deletions lib/utils/brancher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class BranchBot
def initialize(r, t)
@c = Octokit::Client.new(access_token: t)
@repo = r
@token = t
end

def list_branches
Expand All @@ -26,4 +27,8 @@ def delete_branch(branch)
@c.delete_ref(@repo, 'heads/' + branch) if list_branches.include?(branch)
puts "Deleting #{branch} from #{@repo}"
end

def rand_branch
BranchBot.new(@repo, @token).list_branches.sample.to_s
end
end
2 changes: 1 addition & 1 deletion lib/utils/reacter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def issue_react(issue_id, reaction)
end

def randemoji(multiple)
moji = Octokit.emojis.to_a.sample(multiple)
moji = @c.emojis.to_a.sample(multiple)
str = ''
moji.each { |a| str += ":#{a[0]}: " }
str
Expand Down
22 changes: 22 additions & 0 deletions test/suppress_output.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Temporarily redirects STDOUT and STDERR to /dev/null
# but does print exceptions should there occur any.
# Call as:
# suppress_output { puts 'never printed' }
#
def suppress_output
begin
original_stderr = $stderr.clone
original_stdout = $stdout.clone
$stderr.reopen(File.new('/dev/null', 'w'))
$stdout.reopen(File.new('/dev/null', 'w'))
retval = yield
rescue Exception => e
$stdout.reopen(original_stdout)
$stderr.reopen(original_stderr)
raise e
ensure
$stdout.reopen(original_stdout)
$stderr.reopen(original_stderr)
end
retval
end
5 changes: 3 additions & 2 deletions test/test_pull_requests.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'test/unit'
require 'dotenv/load'
require_relative 'suppress_output'
require_relative '../lib/utils/pullrequest'

Dotenv.load('orgbot.env')
Expand All @@ -8,14 +9,14 @@ class TestPullRequest < Test::Unit::TestCase
def test_open_prs
pr = PRBot.new(ENV['REPO'], ENV['TOKEN'])
assert_nothing_raised do
pr.open_prs
suppress_output { pr.open_prs }
end
end

def test_all_pr_comments
pr = PRBot.new(ENV['REPO'], ENV['TOKEN'])
assert_nothing_raised do
pr.all_pr_comments
suppress_output { pr.all_pr_comments }
end
end
end
3 changes: 2 additions & 1 deletion test/test_reporter.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require 'test/unit'
require_relative 'suppress_output'
require_relative '../lib/utils/reporter'

class TestReporter < Test::Unit::TestCase
def test_welcome
rep = Reporter.new
assert_nothing_raised do
rep.welcome
suppress_output { rep.welcome }
end
end
end

0 comments on commit 1f0e655

Please sign in to comment.