Created
October 19, 2015 04:24
-
-
Save buren/7541a6002d4f6cd99c8e to your computer and use it in GitHub Desktop.
rspec-like specs, using ruby procs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def describe(label) | |
fails = [] | |
it = ->(it_label, &block) { | |
assert = ->(expected, result) { | |
passed = ->() { print '.' } | |
failed = ->() { | |
print 'F' | |
fails << "#{label} #{it_label}, expected '#{expected}', but was '#{result}'." | |
} | |
expected == result ? passed.() : failed.() | |
} | |
block.(assert) | |
} | |
yield(it) | |
puts | |
if fails.any? | |
puts "\n[FAILED]: \n" | |
puts "#{fails.join("\n")}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'minispec' | |
describe 'minispec' do |it| | |
it.('should pass') do |assert| | |
assert.('describe', 'describe') | |
end | |
it.('should fail') do |assert| | |
assert.('describes', 'describe') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment