summaryrefslogtreecommitdiff
path: root/lib/spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/spec.rb')
-rw-r--r--lib/spec.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/spec.rb b/lib/spec.rb
new file mode 100644
index 0000000..d9c7d96
--- /dev/null
+++ b/lib/spec.rb
@@ -0,0 +1,45 @@
+class Spec
+ class << self
+ @@contexts = []
+
+ def context(description, &block)
+ @@contexts.push({ description: description, block: block })
+ end
+
+ def expect(value)
+ Result.new(value)
+ end
+
+ def eq(value)
+ Proc.new do |actual|
+ if actual != value
+ raise AssertionError.new("Expected #{value.to_s}, got #{actual.to_s}")
+ end
+ end
+ end
+
+ def call
+ @@contexts.each do |context|
+ puts name
+ puts " #{context[:description]}"
+ context[:block].call
+ end
+ end
+ end
+
+ class Result
+ def initialize(value)
+ @value = value
+ end
+
+ attr_reader :value
+
+ def to(matcher)
+ matcher.call(value)
+ puts " Passed!"
+ end
+ end
+
+ class AssertionError < RuntimeError
+ end
+end