lib/linepipe/step.rb in linepipe-0.1.2 vs lib/linepipe/step.rb in linepipe-0.2.0
- old
+ new
@@ -3,16 +3,39 @@
attr_reader :name
def initialize(name=nil, &block)
@name = name
@block = block
+ @expectations = []
end
def apply(data)
block.call(data)
end
+ def verify_expectations(result)
+ @expectations.each { |exp| exp.verify(result) }
+ end
+
+ def expect(name=nil, &block)
+ @expectations << StepExpectation.new(name, &block)
+ end
+
private
attr_reader :block
+
+ class StepExpectation
+ attr_reader :name, :status
+
+ def initialize(name=nil, &test)
+ @name = name
+ @test = test
+ @status = 'not run'
+ end
+
+ def verify(data)
+ @status = @test.call(data) ? 'pass' : 'fail'
+ end
+ end
end
end