From c674cacface666d218e426b678e2a104471f0028 Mon Sep 17 00:00:00 2001 From: tiagofsilva Date: Sat, 5 Oct 2019 04:12:14 -0300 Subject: [PATCH 1/2] Fixes typo in module description --- lib/testrocket.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/testrocket.rb b/lib/testrocket.rb index 7518be0..f4e5167 100644 --- a/lib/testrocket.rb +++ b/lib/testrocket.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true ## -# TestRocket Module to refine lambdas an use them for lightweight tests +# TestRocket Module to refine procs and use them for lightweight tests # module TestRocket VERSION = '1.0.0' From 1382c2018f7d7dcde2614742a09118a20761c73e Mon Sep 17 00:00:00 2001 From: tiagofsilva Date: Sat, 5 Oct 2019 04:14:55 -0300 Subject: [PATCH 2/2] Makes some readability improvements in main module and adds private method to refactor conditional --- lib/testrocket.rb | 60 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/lib/testrocket.rb b/lib/testrocket.rb index f4e5167..0cc470f 100644 --- a/lib/testrocket.rb +++ b/lib/testrocket.rb @@ -12,26 +12,60 @@ module TestRocket # Include TestRocket methods WITHOUT implementation selected Proc.send :include, TestRocket + Kernel.define_method :production_env? do + ENV['RACK_ENV'] == 'production' || + ((defined?(Rails) && Rails.env.production?)) || + ENV['RAILS_ENV'] == 'production' + end + # If we're in a production environment, the tests shall do nothing. - if ENV['RACK_ENV'] == 'production' || - (defined?(Rails) && Rails.env.production?) || - ENV['RAILS_ENV'] == 'production' + if production_env? def _test(a, b); end def _show(r); end def _pend; end def _desc; end else - def _test(a, b); send((call rescue()) ? a : b) end - def _show(r); (TestRocket.out || STDERR) << r + "\n"; r end - def _pass; ' OK' end - def _fail; " FAIL @ #{source_location * ':'}" end - def _pend; "PENDING '#{call}' @ #{source_location * ':'}" end - def _desc; " FIRE '#{call}'!" end + def _test(a, b) + res = (call rescue()) ? a : b + send(res) + end + + def _show(r) + (TestRocket.out || STDERR) << r + "\n" + r + end + + def _pass + " OK" + end + + def _fail + " FAIL @ #{source_location * ':'}" + end + + def _pend + "PENDING '#{call}' @ #{source_location * ':'}" + end + + def _desc + " FIRE '#{call}'!" + end end - def +@; _show _test :_pass, :_fail end - def -@; _show _test :_fail, :_pass end - def ~; _show _pend end - def !; _show _desc end + def +@ + _show(_test(:_pass, :_fail)) + end + + def -@ + _show(_test(:_fail, :_pass)) + end + + def ~ + _show(_pend) + end + + def ! + _show(_desc) + end end end \ No newline at end of file