strut 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ require "strut/annotation"
2
+
3
+ module Strut
4
+ SCENARIO_PASS = "pass"
5
+ SCENARIO_FAIL = "fail"
6
+ SCENARIO_ERROR = "error"
7
+
8
+ class ScenarioResult
9
+ attr_accessor :name, :time
10
+ attr_reader :result, :message
11
+
12
+ def initialize
13
+ @annotations = Hash.new { |h, k| h[k] = [] }
14
+ @time = 0.0
15
+ end
16
+
17
+ def add_ok_for_line(line)
18
+ add_annotation_for_line(line, ANNOTATION_OK)
19
+ end
20
+
21
+ def add_fail_for_line(line, message)
22
+ add_annotation_for_line(line, ANNOTATION_FAIL, message)
23
+ end
24
+
25
+ def add_exception_for_line(line, message)
26
+ add_annotation_for_line(line, ANNOTATION_EXCEPTION, message)
27
+ end
28
+
29
+ def add_annotation_for_line(line, type, message = "")
30
+ @annotations[line] << Annotation.new(type, message)
31
+ end
32
+
33
+ def annotations_for_line(line)
34
+ @annotations[line]
35
+ end
36
+
37
+ def result
38
+ all_annotations = @annotations.values.flatten
39
+ return SCENARIO_ERROR if all_annotations.any? { |a| a.type == ANNOTATION_EXCEPTION }
40
+ return SCENARIO_FAIL if all_annotations.any? { |a| a.type == ANNOTATION_FAIL }
41
+ return SCENARIO_PASS
42
+ end
43
+
44
+ def message
45
+ all_annotations = @annotations.values.flatten
46
+
47
+ exception = all_annotations.detect { |a| a.type == ANNOTATION_EXCEPTION }
48
+ return exception.message unless exception.nil?
49
+
50
+ failure = all_annotations.detect { |a| a.type == ANNOTATION_FAIL }
51
+ return failure.message unless failure.nil?
52
+
53
+ ok = all_annotations.detect { |a| a.type == ANNOTATION_OK }
54
+ return ok.message unless ok.nil?
55
+
56
+ ""
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,61 @@
1
+ require "rubygems"
2
+ require "rubyslim/ruby_slim"
3
+
4
+ module Strut
5
+ class SlimClient
6
+ def initialize(host, port, max_attempts)
7
+ @host = host
8
+ @port = port
9
+ @max_attempts = max_attempts
10
+ end
11
+
12
+ def responses_for_commands(commands)
13
+ encoded_commands = encode_commands(commands)
14
+ socket = prepare_socket
15
+ read_and_ignore_version(socket)
16
+ write_commands(socket, encoded_commands)
17
+ response = read_response(socket)
18
+ decode_response(response)
19
+ end
20
+
21
+ def encode_commands(commands)
22
+ flattened_commands = commands.map { |c| c.to_a }
23
+ serialised_commands = ListSerializer.serialize(flattened_commands)
24
+ length = ListSerializer.length_string(serialised_commands.length)
25
+ "#{length}#{serialised_commands}"
26
+ end
27
+
28
+ def prepare_socket
29
+ socket = nil
30
+ attempts = 0
31
+ while socket.nil? and attempts < @max_attempts do
32
+ begin
33
+ socket = TCPSocket.open(@host, @port)
34
+ rescue
35
+ attempts += 1
36
+ sleep(2)
37
+ end
38
+ end
39
+ throw "Could not connect to Slim server." if socket.nil?
40
+ socket
41
+ end
42
+
43
+ def read_and_ignore_version(socket)
44
+ socket.gets
45
+ end
46
+
47
+ def write_commands(socket, commands)
48
+ socket.puts(commands)
49
+ end
50
+
51
+ def read_response(socket)
52
+ length = socket.read(6).to_i # <length>
53
+ socket.read(1) # :
54
+ socket.read(length) # <command>
55
+ end
56
+
57
+ def decode_response(response)
58
+ ListDeserializer.deserialize(response)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,89 @@
1
+ module Strut
2
+ CommandMetadata = Struct.new(:scenario_number, :line, :expected_value)
3
+
4
+ class SlimCommand
5
+ attr_reader :id
6
+ attr_reader :metadata
7
+
8
+ def initialize(id, metadata)
9
+ @id = id
10
+ @metadata = metadata
11
+ end
12
+
13
+ def to_a
14
+ [@id, command]
15
+ end
16
+
17
+ def to_s
18
+ sprintf("[%2d]", @id)
19
+ end
20
+ end
21
+
22
+ class ImportCommand < SlimCommand
23
+ attr_reader :namespace
24
+
25
+ def initialize(id, metadata, namespace)
26
+ super(id, metadata)
27
+ @namespace = namespace
28
+ end
29
+
30
+ def command
31
+ "import"
32
+ end
33
+
34
+ def to_a
35
+ super + [@namespace]
36
+ end
37
+
38
+ def to_s
39
+ "#{super} import #{@namespace}"
40
+ end
41
+ end
42
+
43
+ class MakeCommand < SlimCommand
44
+ attr_reader :instance, :class_name
45
+
46
+ def initialize(id, metadata, instance, class_name)
47
+ super(id, metadata)
48
+ @instance = instance
49
+ @class_name = class_name
50
+ end
51
+
52
+ def command
53
+ "make"
54
+ end
55
+
56
+ def to_a
57
+ super + [@instance, @class_name]
58
+ end
59
+
60
+ def to_s
61
+ "#{super} #{@instance} = new #{@class_name}"
62
+ end
63
+ end
64
+
65
+ class CallCommand < SlimCommand
66
+ attr_reader :instance, :property, :value
67
+
68
+ def initialize(id, metadata, instance, property, value)
69
+ super(id, metadata)
70
+ @instance = instance
71
+ @property = property
72
+ @value = value
73
+ end
74
+
75
+ def command
76
+ "call"
77
+ end
78
+
79
+ def to_a
80
+ ary = super + [@instance, @property]
81
+ ary << @value unless @value.nil?
82
+ ary
83
+ end
84
+
85
+ def to_s
86
+ "#{super} #{@instance}.#{@property}(#{@value})"
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,29 @@
1
+ require "strut/slim_command"
2
+
3
+ module Strut
4
+ class SlimCommandFactory
5
+ def initialize
6
+ @command_id = 0
7
+ end
8
+
9
+ def next_command_id
10
+ @command_id += 1
11
+ @command_id.to_s
12
+ end
13
+
14
+ def make_import_command(metadata, namespace)
15
+ id = next_command_id
16
+ ImportCommand.new(id, metadata, namespace)
17
+ end
18
+
19
+ def make_make_command(metadata, instance, class_name)
20
+ id = next_command_id
21
+ MakeCommand.new(id, metadata, instance, class_name)
22
+ end
23
+
24
+ def make_call_command(metadata, instance, property, value = nil)
25
+ id = next_command_id
26
+ CallCommand.new(id, metadata, instance, property, value)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Strut
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'strut/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "strut"
8
+ spec.version = Strut::VERSION
9
+ spec.authors = ["Dan Cutting"]
10
+ spec.email = ["dan@cutting.io"]
11
+
12
+ spec.summary = %q{Acceptance testing with Swagger}
13
+ spec.homepage = "https://github.com/dcutting/strut"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = ["strut"]
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "coveralls"
25
+ spec.add_development_dependency "equivalent-xml"
26
+
27
+ spec.add_dependency "term-ansicolor", "~> 1.3"
28
+ spec.add_dependency "rubyslim", "~> 0.1"
29
+ spec.add_dependency "psych", "2.0.5"
30
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strut
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dan Cutting
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: equivalent-xml
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
+ - !ruby/object:Gem::Dependency
84
+ name: term-ansicolor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubyslim
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.1'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: psych
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 2.0.5
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 2.0.5
125
+ description:
126
+ email:
127
+ - dan@cutting.io
128
+ executables:
129
+ - strut
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".simplecov"
136
+ - ".travis.yml"
137
+ - CODE_OF_CONDUCT.md
138
+ - Gemfile
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - bin/console
143
+ - bin/setup
144
+ - exe/strut
145
+ - lib/strut.rb
146
+ - lib/strut/annotation.rb
147
+ - lib/strut/config.rb
148
+ - lib/strut/document.rb
149
+ - lib/strut/document_builder.rb
150
+ - lib/strut/extensions.rb
151
+ - lib/strut/interaction_factory.rb
152
+ - lib/strut/parser.rb
153
+ - lib/strut/report.rb
154
+ - lib/strut/report_builder.rb
155
+ - lib/strut/report_junit_formatter.rb
156
+ - lib/strut/report_pretty_formatter.rb
157
+ - lib/strut/scenario_builder.rb
158
+ - lib/strut/scenario_result.rb
159
+ - lib/strut/slim_client.rb
160
+ - lib/strut/slim_command.rb
161
+ - lib/strut/slim_command_factory.rb
162
+ - lib/strut/version.rb
163
+ - strut.gemspec
164
+ homepage: https://github.com/dcutting/strut
165
+ licenses:
166
+ - MIT
167
+ metadata: {}
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubyforge_project:
184
+ rubygems_version: 2.4.5.1
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: Acceptance testing with Swagger
188
+ test_files: []