Permalink
Browse files

Implement table diffing.

Add new function clucumber-steps:table-equal, which implements the table diffing wire protocol
methods. As of cucumber 0.8.3, diffs are not presented very nicely yet, but at least the foundation
is there (-:
  • Loading branch information...
1 parent 3545f68 commit 52075835b50aa16eda6499d9189e4886e0da0daa @antifuchs antifuchs committed Jul 12, 2010
Showing with 67 additions and 6 deletions.
  1. +49 −0 features/table_diffing.feature
  2. +2 −1 lib/clucumber/packages.lisp
  3. +16 −5 lib/clucumber/server.lisp
@@ -0,0 +1,49 @@
+Feature: Table diffing
+
+ As a user of clucumber, I want to compare tables against each other
+ so that I can more easily tell which aspect of my data are causing
+ failures.
+
+Scenario: Simple table diff - table given, compared.
+
+ Given a standard Cucumber project directory structure
+ Given the standard clucumber setup
+ Given a file named "features/table-diffing.feature" with:
+ """
+ Feature: Table step args
+
+ Scenario: A working table step
+ Given I have a step that wants these args:
+ | foo |
+ | bar |
+ | baz |
+
+ Scenario: A failing table step
+ Given I have a step that wants these args:
+ | bork |
+ | bar |
+ | bork |
+ """
+ Given a file named "features/step_definitions/table-diffing-steps.lisp" with:
+ """
+ (Given* #?{^I have a step that wants these args:$} (table)
+ (unless (table-equal '(("foo") ("bar") ("baz")) table)
+ (fail "Tables are not equal!")))
+ """
+ When I run "cucumber -f progress"
+ Then it should fail with exactly:
+ """
+ .F
+
+ (::) failed steps (::)
+
+ Tables are not equal! (Cucumber::WireSupport::WireException)
+ features/table-diffing.feature:10:in `Given I have a step that wants these args:'
+
+ Failing Scenarios:
+ cucumber features/table-diffing.feature:9 # Scenario: A failing table step
+
+ 2 scenarios (1 failed, 1 passed)
+ 2 steps (1 failed, 1 passed)
+
+ """
@@ -6,7 +6,8 @@
#:Given* #:When* #:Then*
#:Before #:After
#:pending #:fail
- #:var)
+ #:var
+ #:table-equal)
(:use #:cl #:cl-interpol))
(cl:defpackage #:clucumber-user
@@ -31,15 +31,17 @@
:key (lambda (path)
(enough-namestring path base-pathname))))))))
-(defun serve-cucumber-requests (socket &aux (stream (socket-stream socket)))
+(defvar *stream*)
+
+(defun serve-cucumber-requests (socket &aux (*stream* (socket-stream socket)))
(handler-case
(loop
- (let* ((line (read-line stream))
+ (let* ((line (read-line *stream*))
(message (read-json line nil))
(reply (call-wire-protocol-method message)))
- (st-json:write-json reply stream)
- (terpri stream)
- (finish-output stream)))
+ (st-json:write-json reply *stream*)
+ (terpri *stream*)
+ (finish-output *stream*)))
(end-of-file nil nil)))
@@ -240,3 +242,12 @@
(defun reset-state ()
(clrhash *variables*))
+
+;;; Table diffing:
+
+(defun clucumber-steps:table-equal (expected actual)
+ (st-json:write-json (list "diff" (list expected actual)) *stream*)
+ (terpri *stream*)
+ (finish-output *stream*)
+ (let ((reply-line (read-line *stream*)))
+ (string= "diff_ok" (first (read-json reply-line nil)))))

0 comments on commit 5207583

Please sign in to comment.