lucid 0.3.0 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,38 +0,0 @@
1
- require 'yaml'
2
- require 'erb'
3
-
4
- module Lucid
5
- module WireSupport
6
- class Configuration
7
- attr_reader :host, :port, :unix
8
-
9
- def self.from_file(wire_file)
10
- settings = YAML.load(ERB.new(File.read(wire_file)).result)
11
- new(settings)
12
- end
13
-
14
- def initialize(args)
15
- @host = args['host']
16
- @port = args['port']
17
- @unix = args['unix'] if RUBY_PLATFORM !~ /mingw|mswin/
18
- @timeouts = DEFAULT_TIMEOUTS.merge(args['timeout'] || {})
19
- end
20
-
21
- def timeout(message = nil)
22
- return @timeouts[message.to_s] || 3
23
- end
24
-
25
- def to_s
26
- return @unix if @unix
27
- "#{@host}:#{@port}"
28
- end
29
-
30
- DEFAULT_TIMEOUTS = {
31
- 'connect' => 11,
32
- 'invoke' => 120,
33
- 'begin_scenario' => 120,
34
- 'end_scenario' => 120
35
- }
36
- end
37
- end
38
- end
@@ -1,61 +0,0 @@
1
- require 'timeout'
2
- require 'lucid/wire_support/wire_protocol'
3
-
4
- module Lucid
5
- module WireSupport
6
- class Connection
7
- class ConnectionError < StandardError; end
8
-
9
- include WireProtocol
10
-
11
- def initialize(config)
12
- @config = config
13
- end
14
-
15
- def call_remote(request_handler, message, params)
16
- packet = WirePacket.new(message, params)
17
-
18
- begin
19
- send_data_to_socket(packet.to_json)
20
- response = fetch_data_from_socket(@config.timeout(message))
21
- response.handle_with(request_handler)
22
- rescue Timeout::Error => e
23
- backtrace = e.backtrace ; backtrace.shift # because Timeout puts some wierd stuff in there
24
- raise Timeout::Error, "Timed out calling wire server with message '#{message}'", backtrace
25
- end
26
- end
27
-
28
- def exception(params)
29
- WireException.new(params, @config)
30
- end
31
-
32
- private
33
-
34
- def send_data_to_socket(data)
35
- Timeout.timeout(@config.timeout('connect')) { socket.puts(data) }
36
- end
37
-
38
- def fetch_data_from_socket(timeout)
39
- raw_response =
40
- if timeout == :never
41
- socket.gets
42
- else
43
- Timeout.timeout(timeout) { socket.gets }
44
- end
45
- raise exception({'message' => "Remote Socket with #{@config.host}:#{@config.port} closed."}) if raw_response.nil?
46
- WirePacket.parse(raw_response)
47
- end
48
-
49
- def socket
50
- return @socket if @socket
51
- if @config.unix
52
- @socket = UNIXSocket.new(@config.unix)
53
- else
54
- @socket = TCPSocket.new(@config.host, @config.port)
55
- end
56
- rescue Errno::ECONNREFUSED => exception
57
- raise(ConnectionError, "Unable to contact the wire server at #{@config}. Is it up?")
58
- end
59
- end
60
- end
61
- end
@@ -1,32 +0,0 @@
1
- module Lucid
2
- module WireSupport
3
- class RequestHandler
4
- def initialize(connection)
5
- @connection = connection
6
- @message = underscore(self.class.name.split('::').last)
7
- end
8
-
9
- def execute(request_params = nil)
10
- @connection.call_remote(self, @message, request_params)
11
- end
12
-
13
- def handle_fail(params)
14
- raise @connection.exception(params)
15
- end
16
-
17
- def handle_success(params)
18
- end
19
-
20
- private
21
-
22
- # Props to Rails
23
- def underscore(camel_cased_word)
24
- camel_cased_word.to_s.gsub(/::/, '/').
25
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
26
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
27
- tr("-", "_").
28
- downcase
29
- end
30
- end
31
- end
32
- end
@@ -1,32 +0,0 @@
1
- module Lucid
2
- module WireSupport
3
- # Proxy for an exception that occured at the remote end of the wire
4
- class WireException < StandardError
5
- module CanSetName
6
- attr_writer :exception_name
7
- def to_s
8
- @exception_name
9
- end
10
- end
11
-
12
- def initialize(args, config)
13
- super args['message']
14
- if args['exception']
15
- self.class.extend(CanSetName)
16
- self.class.exception_name = "#{args['exception']} from #{config}"
17
- end
18
- if args['backtrace']
19
- @backtrace = if args['backtrace'].is_a?(String)
20
- args['backtrace'].split("\n") # TODO: change cuke4nuke to pass an array instead of a big string
21
- else
22
- args['backtrace']
23
- end
24
- end
25
- end
26
-
27
- def backtrace
28
- @backtrace || super
29
- end
30
- end
31
- end
32
- end
@@ -1,54 +0,0 @@
1
- require 'multi_json'
2
- require 'socket'
3
- require 'lucid/wire_support/connection'
4
- require 'lucid/wire_support/configuration'
5
- require 'lucid/wire_support/wire_packet'
6
- require 'lucid/wire_support/wire_exception'
7
- require 'lucid/wire_support/wire_step_definition'
8
-
9
- module Lucid
10
- module WireSupport
11
-
12
- # The wire-protocol (lanugage independent) implementation of the programming
13
- # language API.
14
- class WireLanguage
15
- include Interface::InterfaceMethods
16
-
17
- def initialize(runtime)
18
- @connections = []
19
- end
20
-
21
- def alias_adverbs(adverbs)
22
- end
23
-
24
- def load_code_file(wire_file)
25
- config = Configuration.from_file(wire_file)
26
- @connections << Connection.new(config)
27
- end
28
-
29
- def matcher_text(code_keyword, step_name, multiline_arg_class, matcher_type)
30
- matchers = @connections.map do |remote|
31
- remote.matcher_text(code_keyword, step_name, multiline_arg_class.to_s)
32
- end
33
- matchers.flatten.join("\n")
34
- end
35
-
36
- def step_matches(step_name, formatted_step_name)
37
- @connections.map{ |c| c.step_matches(step_name, formatted_step_name)}.flatten
38
- end
39
-
40
- protected
41
-
42
- def begin_scenario(scenario)
43
- @connections.each { |c| c.begin_scenario(scenario) }
44
- @current_scenario = scenario
45
- end
46
-
47
- def end_scenario
48
- scenario = @current_scenario
49
- @connections.each { |c| c.end_scenario(scenario) }
50
- @current_scenario = nil
51
- end
52
- end
53
- end
54
- end
@@ -1,34 +0,0 @@
1
- require 'multi_json'
2
-
3
- module Lucid
4
- module WireSupport
5
- # Represents the packet of data sent over the wire as JSON data, containing
6
- # a message and a hash of arguments
7
- class WirePacket
8
- class << self
9
- def parse(raw)
10
- attributes = MultiJson.load(raw.strip)
11
- message = attributes[0]
12
- params = attributes[1]
13
- new(message, params)
14
- end
15
- end
16
-
17
- attr_reader :message, :params
18
-
19
- def initialize(message, params = nil)
20
- @message, @params = message, params
21
- end
22
-
23
- def to_json
24
- packet = [@message]
25
- packet << @params if @params
26
- MultiJson.dump(packet)
27
- end
28
-
29
- def handle_with(handler)
30
- handler.send("handle_#{@message}", @params)
31
- end
32
- end
33
- end
34
- end
@@ -1,43 +0,0 @@
1
- require 'lucid/wire_support/wire_protocol/requests'
2
-
3
- module Lucid
4
- module WireSupport
5
- module WireProtocol
6
- def step_matches(name_to_match, name_to_report)
7
- handler = Requests::StepMatches.new(self)
8
- handler.execute(name_to_match, name_to_report)
9
- end
10
-
11
- def matcher_text(step_keyword, step_name, multiline_arg_class_name)
12
- handler = Requests::SnippetText.new(self)
13
- handler.execute(step_keyword, step_name, multiline_arg_class_name)
14
- end
15
-
16
- def invoke(step_definition_id, args)
17
- handler = Requests::Invoke.new(self)
18
- handler.execute(step_definition_id, args)
19
- end
20
-
21
- def diff_failed
22
- handler = Requests::DiffFailed.new(self)
23
- handler.execute
24
- end
25
-
26
- def diff_ok
27
- handler = Requests::DiffOk.new(self)
28
- handler.execute
29
- end
30
-
31
- def begin_scenario(scenario)
32
- handler = Requests::BeginScenario.new(self)
33
- handler.execute(scenario)
34
- end
35
-
36
- def end_scenario(scenario)
37
- handler = Requests::EndScenario.new(self)
38
- handler.execute(scenario)
39
- end
40
-
41
- end
42
- end
43
- end
@@ -1,125 +0,0 @@
1
- require 'lucid/wire_support/request_handler'
2
- require 'gherkin/formatter/argument'
3
-
4
- module Lucid
5
- module WireSupport
6
- module WireProtocol
7
- module Requests
8
- class StepMatches < RequestHandler
9
- def execute(name_to_match, name_to_report)
10
- @name_to_match, @name_to_report = name_to_match, name_to_report
11
- request_params = {
12
- :name_to_match => name_to_match
13
- }
14
- super(request_params)
15
- end
16
-
17
- def handle_success(params)
18
- params.map do |raw_step_match|
19
- create_step_match(raw_step_match)
20
- end
21
- end
22
-
23
- alias :handle_step_matches :handle_success
24
-
25
- private
26
-
27
- def create_step_match(raw_step_match)
28
- step_definition = WireStepDefinition.new(@connection, raw_step_match)
29
- step_args = raw_step_match['args'].map do |raw_arg|
30
- Gherkin::Formatter::Argument.new(raw_arg['pos'], raw_arg['val'])
31
- end
32
- step_match(step_definition, step_args)
33
- end
34
-
35
- def step_match(step_definition, step_args)
36
- StepMatch.new(step_definition, @name_to_match, @name_to_report, step_args)
37
- end
38
- end
39
-
40
- class SnippetText < RequestHandler
41
- def execute(step_keyword, step_name, multiline_arg_class_name)
42
- request_params = {
43
- :step_keyword => step_keyword,
44
- :step_name => step_name,
45
- :multiline_arg_class => multiline_arg_class_name
46
- }
47
- super(request_params)
48
- end
49
-
50
- def handle_success(matcher_text)
51
- matcher_text
52
- end
53
-
54
- alias :handle_matcher_text :handle_success
55
- end
56
-
57
- class Invoke < RequestHandler
58
- def execute(step_definition_id, args)
59
- request_params = {
60
- :id => step_definition_id,
61
- :args => args
62
- }
63
- super(request_params)
64
- end
65
-
66
- def handle_pending(message)
67
- raise Pending, message || "TODO"
68
- end
69
-
70
- def handle_diff!(tables)
71
- table1 = AST::Table.new(tables[0])
72
- table2 = AST::Table.new(tables[1])
73
- table1.diff!(table2)
74
- end
75
-
76
- def handle_diff(tables)
77
- begin
78
- handle_diff!(tables)
79
- rescue Lucid::AST::Table::Different
80
- @connection.diff_failed
81
- end
82
- @connection.diff_ok
83
- end
84
-
85
- alias :handle_step_failed :handle_fail
86
- end
87
-
88
- class DiffFailed < RequestHandler
89
- alias :handle_step_failed :handle_fail
90
- end
91
-
92
- class DiffOk < RequestHandler
93
- alias :handle_step_failed :handle_fail
94
- end
95
-
96
- module Tags
97
- def clean_tag_names(scenario)
98
- scenario.source_tags.map { |tag| tag.name.gsub(/^@/, '') }.sort
99
- end
100
-
101
- def request_params(scenario)
102
- return nil unless scenario.source_tags.any?
103
- { "tags" => clean_tag_names(scenario) }
104
- end
105
- end
106
-
107
- class BeginScenario < RequestHandler
108
- include Tags
109
-
110
- def execute(scenario)
111
- super(request_params(scenario))
112
- end
113
- end
114
-
115
- class EndScenario < RequestHandler
116
- include Tags
117
-
118
- def execute(scenario)
119
- super(request_params(scenario))
120
- end
121
- end
122
- end
123
- end
124
- end
125
- end
@@ -1,26 +0,0 @@
1
- module Lucid
2
- module WireSupport
3
- class WireStepDefinition
4
- attr_reader :regexp_source, :file_colon_line
5
-
6
- def initialize(connection, data)
7
- @connection = connection
8
- @id = data['id']
9
- @regexp_source = data['regexp'] || "Unknown"
10
- @file_colon_line = data['source'] || "Unknown"
11
- end
12
-
13
- def invoke(args)
14
- prepared_args = args.map{ |arg| prepare(arg) }
15
- @connection.invoke(@id, prepared_args)
16
- end
17
-
18
- private
19
-
20
- def prepare(arg)
21
- return arg unless arg.is_a?(Lucid::AST::Table)
22
- arg.raw
23
- end
24
- end
25
- end
26
- end