lucid 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/.gitignore +30 -10
  2. data/.rspec +1 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +15 -0
  6. data/Gemfile +4 -2
  7. data/HISTORY.md +22 -0
  8. data/{LICENSE.txt → LICENSE} +6 -3
  9. data/README.md +22 -8
  10. data/Rakefile +2 -1
  11. data/bin/lucid +10 -10
  12. data/bin/lucid-gen +4 -0
  13. data/lib/autotest/discover.rb +11 -0
  14. data/lib/autotest/lucid.rb +6 -0
  15. data/lib/autotest/lucid_mixin.rb +135 -0
  16. data/lib/autotest/lucid_rails.rb +6 -0
  17. data/lib/autotest/lucid_rails_rspec.rb +6 -0
  18. data/lib/autotest/lucid_rails_rspec2.rb +6 -0
  19. data/lib/autotest/lucid_rspec.rb +6 -0
  20. data/lib/autotest/lucid_rspec2.rb +6 -0
  21. data/lib/lucid.rb +32 -1
  22. data/lib/lucid/ast.rb +20 -0
  23. data/lib/lucid/ast/background.rb +116 -0
  24. data/lib/lucid/ast/comment.rb +24 -0
  25. data/lib/lucid/ast/doc_string.rb +44 -0
  26. data/lib/lucid/ast/empty_background.rb +33 -0
  27. data/lib/lucid/ast/examples.rb +49 -0
  28. data/lib/lucid/ast/feature.rb +99 -0
  29. data/lib/lucid/ast/has_steps.rb +74 -0
  30. data/lib/lucid/ast/location.rb +41 -0
  31. data/lib/lucid/ast/multiline_argument.rb +31 -0
  32. data/lib/lucid/ast/names.rb +13 -0
  33. data/lib/lucid/ast/outline_table.rb +194 -0
  34. data/lib/lucid/ast/scenario.rb +103 -0
  35. data/lib/lucid/ast/scenario_outline.rb +144 -0
  36. data/lib/lucid/ast/specs.rb +38 -0
  37. data/lib/lucid/ast/step.rb +122 -0
  38. data/lib/lucid/ast/step_collection.rb +92 -0
  39. data/lib/lucid/ast/step_invocation.rb +196 -0
  40. data/lib/lucid/ast/table.rb +730 -0
  41. data/lib/lucid/ast/tags.rb +28 -0
  42. data/lib/lucid/ast/tdl_walker.rb +195 -0
  43. data/lib/lucid/cli/app.rb +78 -0
  44. data/lib/lucid/cli/configuration.rb +261 -0
  45. data/lib/lucid/cli/options.rb +463 -0
  46. data/lib/lucid/cli/profile.rb +101 -0
  47. data/lib/lucid/configuration.rb +53 -0
  48. data/lib/lucid/core_ext/disable_autorunners.rb +15 -0
  49. data/lib/lucid/core_ext/instance_exec.rb +70 -0
  50. data/lib/lucid/core_ext/proc.rb +36 -0
  51. data/lib/lucid/core_ext/string.rb +9 -0
  52. data/lib/lucid/errors.rb +40 -0
  53. data/lib/lucid/factory.rb +43 -0
  54. data/lib/lucid/formatter/ansicolor.rb +168 -0
  55. data/lib/lucid/formatter/console.rb +218 -0
  56. data/lib/lucid/formatter/debug.rb +33 -0
  57. data/lib/lucid/formatter/duration.rb +11 -0
  58. data/lib/lucid/formatter/gherkin_formatter_adapter.rb +94 -0
  59. data/lib/lucid/formatter/gpretty.rb +24 -0
  60. data/lib/lucid/formatter/html.rb +610 -0
  61. data/lib/lucid/formatter/interceptor.rb +66 -0
  62. data/lib/lucid/formatter/io.rb +31 -0
  63. data/lib/lucid/formatter/jquery-min.js +154 -0
  64. data/lib/lucid/formatter/json.rb +19 -0
  65. data/lib/lucid/formatter/json_pretty.rb +10 -0
  66. data/lib/lucid/formatter/junit.rb +177 -0
  67. data/lib/lucid/formatter/lucid.css +283 -0
  68. data/lib/lucid/formatter/lucid.sass +244 -0
  69. data/lib/lucid/formatter/ordered_xml_markup.rb +24 -0
  70. data/lib/lucid/formatter/progress.rb +95 -0
  71. data/lib/lucid/formatter/rerun.rb +91 -0
  72. data/lib/lucid/formatter/standard.rb +235 -0
  73. data/lib/lucid/formatter/stepdefs.rb +14 -0
  74. data/lib/lucid/formatter/steps.rb +49 -0
  75. data/lib/lucid/formatter/summary.rb +35 -0
  76. data/lib/lucid/formatter/unicode.rb +53 -0
  77. data/lib/lucid/formatter/usage.rb +132 -0
  78. data/lib/lucid/generator.rb +21 -0
  79. data/lib/lucid/generators/project.rb +70 -0
  80. data/lib/lucid/generators/project/Gemfile.tt +6 -0
  81. data/lib/lucid/generators/project/browser-symbiont.rb +24 -0
  82. data/lib/lucid/generators/project/driver-symbiont.rb +4 -0
  83. data/lib/lucid/generators/project/errors.rb +26 -0
  84. data/lib/lucid/generators/project/events-symbiont.rb +36 -0
  85. data/lib/lucid/generators/project/lucid-symbiont.yml +6 -0
  86. data/lib/lucid/interface.rb +8 -0
  87. data/lib/lucid/interface_methods.rb +125 -0
  88. data/lib/lucid/interface_rb/matcher.rb +108 -0
  89. data/lib/lucid/interface_rb/rb_hook.rb +18 -0
  90. data/lib/lucid/interface_rb/rb_language.rb +190 -0
  91. data/lib/lucid/interface_rb/rb_lucid.rb +119 -0
  92. data/lib/lucid/interface_rb/rb_step_definition.rb +122 -0
  93. data/lib/lucid/interface_rb/rb_transform.rb +57 -0
  94. data/lib/lucid/interface_rb/rb_world.rb +136 -0
  95. data/lib/lucid/interface_rb/regexp_argument_matcher.rb +21 -0
  96. data/lib/lucid/load_path.rb +13 -0
  97. data/lib/lucid/parser.rb +2 -126
  98. data/lib/lucid/platform.rb +27 -0
  99. data/lib/lucid/rspec/allow_doubles.rb +20 -0
  100. data/lib/lucid/rspec/disallow_options.rb +27 -0
  101. data/lib/lucid/runtime.rb +200 -0
  102. data/lib/lucid/runtime/facade.rb +60 -0
  103. data/lib/lucid/runtime/interface_io.rb +60 -0
  104. data/lib/lucid/runtime/orchestrator.rb +218 -0
  105. data/lib/lucid/runtime/results.rb +64 -0
  106. data/lib/lucid/runtime/specs_loader.rb +79 -0
  107. data/lib/lucid/spec_file.rb +112 -0
  108. data/lib/lucid/step_definition_light.rb +20 -0
  109. data/lib/lucid/step_definitions.rb +13 -0
  110. data/lib/lucid/step_match.rb +99 -0
  111. data/lib/lucid/tdl_builder.rb +282 -0
  112. data/lib/lucid/term/ansicolor.rb +118 -0
  113. data/lib/lucid/unit.rb +11 -0
  114. data/lib/lucid/wire_support/configuration.rb +38 -0
  115. data/lib/lucid/wire_support/connection.rb +61 -0
  116. data/lib/lucid/wire_support/request_handler.rb +32 -0
  117. data/lib/lucid/wire_support/wire_exception.rb +32 -0
  118. data/lib/lucid/wire_support/wire_language.rb +54 -0
  119. data/lib/lucid/wire_support/wire_packet.rb +34 -0
  120. data/lib/lucid/wire_support/wire_protocol.rb +43 -0
  121. data/lib/lucid/wire_support/wire_protocol/requests.rb +125 -0
  122. data/lib/lucid/wire_support/wire_step_definition.rb +26 -0
  123. data/lucid.gemspec +25 -14
  124. metadata +220 -12
  125. data/lib/lucid/app.rb +0 -103
  126. data/lib/lucid/options.rb +0 -168
  127. data/lib/lucid/version.rb +0 -3
  128. data/lucid.yml +0 -8
data/lib/lucid/unit.rb ADDED
@@ -0,0 +1,11 @@
1
+ module Lucid
2
+ class Unit
3
+ def initialize(step_collection)
4
+ @step_collection = step_collection
5
+ end
6
+
7
+ def step_count
8
+ @step_collection.length
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,38 @@
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
@@ -0,0 +1,61 @@
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
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,54 @@
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
@@ -0,0 +1,34 @@
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
+ packet.to_json
27
+ end
28
+
29
+ def handle_with(handler)
30
+ handler.send("handle_#{@message}", @params)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,43 @@
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
@@ -0,0 +1,125 @@
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
@@ -0,0 +1,26 @@
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