Skip to content

Commit

Permalink
Send end_scenario message to programming languages
Browse files Browse the repository at this point in the history
In the future, the programming languages should do this themselves
by adding their own filters, but this is the most direct way to fix
the regression #813.

Closes #813
  • Loading branch information
mattwynne committed Mar 18, 2015
1 parent 1596f55 commit 49eeaa1
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 8 deletions.
36 changes: 36 additions & 0 deletions features/docs/wire_protocol/invoke_message.feature
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,39 @@ Feature: Invoke message
1 step (1 passed)
"""

Scenario: Invoke a scenario outline step
Given a file named "features/wired_in_an_outline.feature" with:
"""
Feature:
Scenario Outline:
Given we're all <arg>
Examples:
| arg |
| wired |
"""
And 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":[]}] | ["success"] |
| ["end_scenario"] | ["success"] |
When I run `cucumber -f progress features/wired_in_an_outline.feature`
Then the stderr should not contain anything
And it should pass with:
"""
.
1 scenario (1 passed)
1 step (1 passed)
"""
And the wire server should have received the following messages:
| step_matches |
| begin_scenario |
| invoke |
| end_scenario |



19 changes: 18 additions & 1 deletion features/lib/step_definitions/wire_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,26 @@
set_env(variable, value)
end

Then(/^the wire server should have received the following messages:$/) do |expected_messages|
expect(messages_received).to eq expected_messages.raw.flatten
end

module WireHelper
attr_reader :messages_received

def start_wire_server
@wire_pid = fork { @server.run }
@messages_received = []
reader, writer = IO.pipe
@wire_pid = fork {
reader.close
@server.run(writer)
}
writer.close
Thread.new do
while message = reader.gets
@messages_received << message.strip
end
end
at_exit { stop_wire_server }
end

Expand Down
17 changes: 10 additions & 7 deletions features/lib/support/fake_wire_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ def initialize(port, protocol_table)
@delays = {}
end

def run
def run(io)
@server = TCPServer.open(@port)
loop { handle_connections }
loop { handle_connections(io) }
end

def delay_response(message, delay)
Expand All @@ -18,13 +18,14 @@ def delay_response(message, delay)

private

def handle_connections
Thread.start(@server.accept) { |socket| open_session_on socket }
def handle_connections(io)
Thread.start(@server.accept) { |socket| open_session_on socket, io }
end

def open_session_on(socket)
def open_session_on(socket, io)
begin
SocketSession.new(socket, @protocol_table, @delays).start
on_message = -> (message) { io.puts message }
SocketSession.new(socket, @protocol_table, @delays, on_message).start
rescue Exception => e
raise e
ensure
Expand All @@ -33,10 +34,11 @@ def open_session_on(socket)
end

class SocketSession
def initialize(socket, protocol, delays)
def initialize(socket, protocol, delays, on_message)
@socket = socket
@protocol = protocol
@delays = delays
@on_message = on_message
end

def start
Expand All @@ -50,6 +52,7 @@ def start
def handle(data)
if protocol_entry = response_to(data.strip)
sleep delay(data)
@on_message.call(MultiJson.load(protocol_entry['request'])[0])
send_response(protocol_entry['response'])
else
serialized_exception = { :message => "Not understood: #{data}", :backtrace => [] }
Expand Down
1 change: 1 addition & 0 deletions lib/cucumber/filters/prepare_world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_case
init_scenario = Cucumber::Hooks.around_hook(@original_test_case.source) do |continue|
@runtime.begin_scenario(scenario)
continue.call
@runtime.end_scenario(scenario)
end
around_hooks = [init_scenario] + @original_test_case.around_hooks

Expand Down
4 changes: 4 additions & 0 deletions lib/cucumber/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def begin_scenario(scenario)
@support_code.fire_hook(:begin_scenario, scenario)
end

def end_scenario(scenario)
@support_code.fire_hook(:end_scenario)
end

def unknown_programming_language?
@support_code.unknown_programming_language?
end
Expand Down

0 comments on commit 49eeaa1

Please sign in to comment.