cucumber-wire 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +18 -0
  4. data/Gemfile +20 -0
  5. data/README.md +1 -0
  6. data/Rakefile +13 -0
  7. data/cucumber-wire.gemspec +28 -0
  8. data/features/erb_configuration.feature +54 -0
  9. data/features/handle_unexpected_response.feature +29 -0
  10. data/features/invoke_message.feature +212 -0
  11. data/features/readme.md +26 -0
  12. data/features/snippets_message.feature +47 -0
  13. data/features/step_definitions/aruba_steps.rb +1 -0
  14. data/features/step_definitions/wire_steps.rb +58 -0
  15. data/features/step_matches_message.feature +79 -0
  16. data/features/support/fake_wire_server.rb +80 -0
  17. data/features/table_diffing.feature +124 -0
  18. data/features/tags.feature +86 -0
  19. data/features/timeouts.feature +63 -0
  20. data/lib/cucumber/wire.rb +5 -0
  21. data/lib/cucumber/wire/add_hooks_filter.rb +25 -0
  22. data/lib/cucumber/wire/configuration.rb +38 -0
  23. data/lib/cucumber/wire/connection.rb +63 -0
  24. data/lib/cucumber/wire/connections.rb +50 -0
  25. data/lib/cucumber/wire/data_packet.rb +34 -0
  26. data/lib/cucumber/wire/exception.rb +32 -0
  27. data/lib/cucumber/wire/plugin.rb +32 -0
  28. data/lib/cucumber/wire/protocol.rb +43 -0
  29. data/lib/cucumber/wire/protocol/requests.rb +128 -0
  30. data/lib/cucumber/wire/request_handler.rb +32 -0
  31. data/lib/cucumber/wire/snippet.rb +35 -0
  32. data/lib/cucumber/wire/step_definition.rb +21 -0
  33. data/lib/cucumber/wire/version +1 -0
  34. data/spec/cucumber/wire/configuration_spec.rb +63 -0
  35. data/spec/cucumber/wire/connection_spec.rb +64 -0
  36. data/spec/cucumber/wire/connections_spec.rb +23 -0
  37. data/spec/cucumber/wire/data_packet_spec.rb +43 -0
  38. data/spec/cucumber/wire/exception_spec.rb +50 -0
  39. metadata +157 -0
@@ -0,0 +1,32 @@
1
+ module Cucumber
2
+ module Wire
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,35 @@
1
+ module Cucumber
2
+ module Wire
3
+ module Snippet
4
+ class Generator
5
+ def initialize(connections)
6
+ # This array is shared mutable state with the wire language.
7
+ @connections = connections
8
+ end
9
+
10
+ def call(code_keyword, step_name, multiline_arg, snippet_type)
11
+ @connections.snippets(code_keyword, step_name, MultilineArgClassName.new(multiline_arg).to_s).join("\n")
12
+ end
13
+
14
+ class MultilineArgClassName
15
+ def initialize(arg)
16
+ arg.describe_to(self)
17
+ @result = ""
18
+ end
19
+
20
+ def data_table(*)
21
+ @result = "Cucumber::MultilineArgument::DataTable"
22
+ end
23
+
24
+ def doc_string(*)
25
+ @result = "Cucumber::MultilineArgument::DocString"
26
+ end
27
+
28
+ def to_s
29
+ @result
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ require 'cucumber/core/ast/location'
2
+
3
+ module Cucumber
4
+ module Wire
5
+ class StepDefinition
6
+ attr_reader :regexp_source, :location
7
+
8
+ def initialize(connection, data)
9
+ @connection = connection
10
+ @id = data['id']
11
+ @regexp_source = data['regexp'] || "Unknown"
12
+ @location = Core::Ast::Location.from_file_colon_line(data['source'] || "unknown:0")
13
+ end
14
+
15
+ def invoke(args)
16
+ @connection.invoke(@id, args)
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,63 @@
1
+ require 'cucumber/wire/configuration'
2
+ require 'tempfile'
3
+
4
+ module Cucumber
5
+ module Wire
6
+ describe Configuration do
7
+ let(:wire_file) { Tempfile.new('wire') }
8
+ let(:config) { Configuration.from_file(wire_file.path) }
9
+
10
+ def write_wire_file(contents)
11
+ wire_file << contents
12
+ wire_file.close
13
+ end
14
+
15
+ it "reads the hostname / port from the file" do
16
+ write_wire_file %q{
17
+ host: localhost
18
+ port: 54321
19
+ }
20
+
21
+ expect(config.host).to eq 'localhost'
22
+ expect(config.port).to eq 54321
23
+ end
24
+
25
+ it "reads the timeout for a specific message" do
26
+ write_wire_file %q{
27
+ host: localhost
28
+ port: 54321
29
+ timeout:
30
+ invoke: 99
31
+ }
32
+
33
+ expect(config.timeout('invoke')).to eq 99
34
+ end
35
+
36
+ it "reads the timeout for a connect message" do
37
+ write_wire_file %q{
38
+ host: localhost
39
+ port: 54321
40
+ timeout:
41
+ connect: 99
42
+ }
43
+
44
+ expect(config.timeout('connect')).to eq 99
45
+ end
46
+
47
+ describe "a wire file with no timeouts specified" do
48
+ before(:each) do
49
+ write_wire_file %q{
50
+ host: localhost
51
+ port: 54321
52
+ }
53
+ end
54
+
55
+ %w(invoke begin_scenario end_scenario).each do |message|
56
+ it "sets the default timeout for '#{message}' to 120 seconds" do
57
+ expect(config.timeout(message)).to eq 120
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,64 @@
1
+ require 'cucumber/wire/connection'
2
+ require 'cucumber/wire/configuration'
3
+
4
+ module Cucumber
5
+ module Wire
6
+ describe Connection do
7
+ class TestConnection < Connection
8
+ attr_accessor :socket
9
+ end
10
+
11
+ class TestConfiguration
12
+ attr_reader :custom_timeout
13
+
14
+ def initialize
15
+ @custom_timeout = {}
16
+ end
17
+
18
+ def timeout(message = nil)
19
+ return :default_timeout if message.nil?
20
+ @custom_timeout[message] || Configuration::DEFAULT_TIMEOUTS.fetch(message)
21
+ end
22
+
23
+ def host
24
+ 'localhost'
25
+ end
26
+
27
+ def port
28
+ '3902'
29
+ end
30
+ end
31
+
32
+ before(:each) do
33
+ @config = TestConfiguration.new
34
+ @connection = TestConnection.new(@config)
35
+ @connection.socket = @socket = double('socket').as_null_object
36
+ @response = %q{["response"]}
37
+ end
38
+
39
+ it "re-raises a timeout error" do
40
+ allow(Timeout).to receive(:timeout).and_raise(Timeout::Error.new(''))
41
+ expect(-> { @connection.call_remote(nil, :foo, []) }).to raise_error(Timeout::Error)
42
+ end
43
+
44
+ it "ignores timeout errors when configured to do so" do
45
+ @config.custom_timeout[:foo] = :never
46
+
47
+ allow(@socket).to receive(:gets) { @response }
48
+
49
+ handler = double(:handle_response => :response)
50
+
51
+ expect(@connection.call_remote(handler, :foo, [])).to eq :response
52
+ end
53
+
54
+ it "raises an exception on remote connection closed" do
55
+ @config.custom_timeout[:foo] = :never
56
+
57
+ allow(@socket).to receive(:gets)
58
+ expect(-> {
59
+ @connection.call_remote(nil, :foo, [])
60
+ }).to raise_error(Wire::Exception, 'Remote Socket with localhost:3902 closed.')
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,23 @@
1
+ require 'cucumber/wire/connections'
2
+ require 'cucumber/wire/configuration'
3
+
4
+ module Cucumber
5
+ module Wire
6
+ describe Connections do
7
+ describe "#step_matches" do
8
+ it "returns the matches from each of the RemoteSteps" do
9
+ connection1 = double(step_matches: [:a, :b])
10
+ connection2 = double(step_matches: [:c])
11
+
12
+ connections = Connections.new([connection1, connection2], double)
13
+ expect(connections.step_matches('')).to eq [:a, :b, :c]
14
+ end
15
+
16
+ it "copes with no connections" do
17
+ connections = Connections.new([], double)
18
+ expect(connections.step_matches('')).to eq []
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ require 'cucumber/wire/data_packet'
2
+
3
+ module Cucumber
4
+ module Wire
5
+ describe DataPacket do
6
+ describe "#to_json" do
7
+ it "converts params to a JSON hash" do
8
+ packet = DataPacket.new('test_message', :foo => :bar)
9
+
10
+ expect(packet.to_json).to eq "[\"test_message\",{\"foo\":\"bar\"}]"
11
+ end
12
+
13
+ it "does not pass blank params" do
14
+ packet = DataPacket.new('test_message')
15
+
16
+ expect(packet.to_json).to eq "[\"test_message\"]"
17
+ end
18
+ end
19
+
20
+ describe ".parse" do
21
+ it "understands a raw packet containing null parameters" do
22
+ packet = DataPacket.parse("[\"test_message\",null]")
23
+
24
+ expect(packet.message).to eq 'test_message'
25
+ expect(packet.params).to be_nil
26
+ end
27
+
28
+ it "understands a raw packet containing no parameters" do
29
+ packet = DataPacket.parse("[\"test_message\"]")
30
+
31
+ expect(packet.message).to eq 'test_message'
32
+ expect(packet.params).to be_nil
33
+ end
34
+
35
+ it "understands a raw packet containging parameters data" do
36
+ packet = DataPacket.parse("[\"test_message\",{\"foo\":\"bar\"}]")
37
+
38
+ expect(packet.params['foo']).to eq 'bar'
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,50 @@
1
+ require 'cucumber/wire/exception'
2
+ require 'cucumber/wire/configuration'
3
+
4
+ module Cucumber
5
+ module Wire
6
+ describe Exception do
7
+ before(:each) do
8
+ @config = Configuration.new('host' => 'localhost', 'port' => 54321)
9
+ end
10
+
11
+ def exception
12
+ Wire::Exception.new(@data, @config)
13
+ end
14
+
15
+ describe "with just a message" do
16
+ before(:each) do
17
+ @data = {'message' => 'foo'}
18
+ end
19
+
20
+ it "#to_s as expecteds" do
21
+ expect(exception.to_s).to eq "foo"
22
+ end
23
+ end
24
+
25
+ describe "with a message and an exception" do
26
+ before(:each) do
27
+ @data = {'message' => 'foo', 'exception' => 'Bar'}
28
+ end
29
+
30
+ it "#to_s as expecteds" do
31
+ expect(exception.to_s).to eq "foo"
32
+ end
33
+
34
+ it "#class.to_s returns the name of the exception" do
35
+ expect(exception.class.to_s).to eq 'Bar from localhost:54321'
36
+ end
37
+ end
38
+
39
+ describe "with a custom backtrace" do
40
+ before(:each) do
41
+ @data = {'message' => 'foo', 'backtrace' => ['foo', 'bar', 'baz']}
42
+ end
43
+
44
+ it "#backrace returns the custom backtrace" do
45
+ expect(exception.backtrace).to eq ['foo', 'bar', 'baz']
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber-wire
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matt Wynne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cucumber
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.5
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aruba
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Wire protocol for Cucumber
84
+ email: cukes@googlegroups.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".rspec"
90
+ - ".travis.yml"
91
+ - Gemfile
92
+ - README.md
93
+ - Rakefile
94
+ - cucumber-wire.gemspec
95
+ - features/erb_configuration.feature
96
+ - features/handle_unexpected_response.feature
97
+ - features/invoke_message.feature
98
+ - features/readme.md
99
+ - features/snippets_message.feature
100
+ - features/step_definitions/aruba_steps.rb
101
+ - features/step_definitions/wire_steps.rb
102
+ - features/step_matches_message.feature
103
+ - features/support/fake_wire_server.rb
104
+ - features/table_diffing.feature
105
+ - features/tags.feature
106
+ - features/timeouts.feature
107
+ - lib/cucumber/wire.rb
108
+ - lib/cucumber/wire/add_hooks_filter.rb
109
+ - lib/cucumber/wire/configuration.rb
110
+ - lib/cucumber/wire/connection.rb
111
+ - lib/cucumber/wire/connections.rb
112
+ - lib/cucumber/wire/data_packet.rb
113
+ - lib/cucumber/wire/exception.rb
114
+ - lib/cucumber/wire/plugin.rb
115
+ - lib/cucumber/wire/protocol.rb
116
+ - lib/cucumber/wire/protocol/requests.rb
117
+ - lib/cucumber/wire/request_handler.rb
118
+ - lib/cucumber/wire/snippet.rb
119
+ - lib/cucumber/wire/step_definition.rb
120
+ - lib/cucumber/wire/version
121
+ - spec/cucumber/wire/configuration_spec.rb
122
+ - spec/cucumber/wire/connection_spec.rb
123
+ - spec/cucumber/wire/connections_spec.rb
124
+ - spec/cucumber/wire/data_packet_spec.rb
125
+ - spec/cucumber/wire/exception_spec.rb
126
+ homepage: http://cucumber.io
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options:
132
+ - "--charset=UTF-8"
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: 1.9.3
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.2.2
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: cucumber-wire-0.0.1
151
+ test_files:
152
+ - spec/cucumber/wire/configuration_spec.rb
153
+ - spec/cucumber/wire/connection_spec.rb
154
+ - spec/cucumber/wire/connections_spec.rb
155
+ - spec/cucumber/wire/data_packet_spec.rb
156
+ - spec/cucumber/wire/exception_spec.rb
157
+ has_rdoc: