Skip to content

Instantly share code, notes, and snippets.

@buren
Created October 19, 2015 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buren/7541a6002d4f6cd99c8e to your computer and use it in GitHub Desktop.
Save buren/7541a6002d4f6cd99c8e to your computer and use it in GitHub Desktop.
rspec-like specs, using ruby procs
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
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