Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 48 additions & 14 deletions lib/testrocket.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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