Skip to content

Commit

Permalink
Add diff! message to wire_protocol to allow clients to more easily sa…
Browse files Browse the repository at this point in the history
…tisfy the 80% use case where you want to diff the table and fail the step if the diff fails.
  • Loading branch information
mattwynne committed Jan 18, 2010
1 parent 58f88c6 commit f47bd23
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
5 changes: 5 additions & 0 deletions History.txt
@@ -1,3 +1,8 @@
== In Git

=== New features
* Add diff! message to wire protocol to allow for immediate diff response to invokes (Matt Wynne)

== 0.6.2 2010-01-18

=== Bugfixes
Expand Down
25 changes: 25 additions & 0 deletions features/wire_protocol_table_diffing.feature
Expand Up @@ -90,3 +90,28 @@ Feature: Wire protocol table diffing
1 step (1 failed)
"""

Scenario: Invoke a step definition which asks for an immediate diff that fails
Given there is a wire server running on port 54321 which understands the following protocol:
| request | response |
| ["step_matches",{"name_to_match":"we're all wired"}] | ["success",[{"id":"1", "args":[]}]] |
| ["begin_scenario"] | ["success"] |
| ["invoke",{"id":"1","args":[]}] | ["diff!",[[["a"]],[["b"]]]] |
| ["end_scenario"] | ["success"] |
When I run cucumber -f progress
And it should fail with
"""
F
(::) failed steps (::)
Tables were not identical (Cucumber::Ast::Table::Different)
features/wired.feature:2:in `Given we're all wired'
Failing Scenarios:
cucumber features/wired.feature:1 # Scenario: Wired
1 scenario (1 failed)
1 step (1 failed)
"""
10 changes: 7 additions & 3 deletions lib/cucumber/wire_support/wire_protocol/requests.rb
Expand Up @@ -64,12 +64,16 @@ def execute(step_definition_id, args)
def handle_pending(message)
raise Pending, message || "TODO"
end

def handle_diff(tables)
def handle_diff!(tables)
table1 = Ast::Table.new(tables[0])
table2 = Ast::Table.new(tables[1])
table1.diff!(table2)
end

def handle_diff(tables)
begin
table1.diff!(table2)
handle_diff!(tables)
rescue Cucumber::Ast::Table::Different
@connection.diff_failed
end
Expand Down

0 comments on commit f47bd23

Please sign in to comment.