diff --git a/lib/testrocket.rb b/lib/testrocket.rb index 7518be0..0cc470f 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' @@ -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