strut 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.simplecov +7 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/strut +5 -0
- data/lib/strut.rb +60 -0
- data/lib/strut/annotation.rb +7 -0
- data/lib/strut/config.rb +60 -0
- data/lib/strut/document.rb +14 -0
- data/lib/strut/document_builder.rb +17 -0
- data/lib/strut/extensions.rb +81 -0
- data/lib/strut/interaction_factory.rb +25 -0
- data/lib/strut/parser.rb +57 -0
- data/lib/strut/report.rb +48 -0
- data/lib/strut/report_builder.rb +56 -0
- data/lib/strut/report_junit_formatter.rb +47 -0
- data/lib/strut/report_pretty_formatter.rb +91 -0
- data/lib/strut/scenario_builder.rb +124 -0
- data/lib/strut/scenario_result.rb +59 -0
- data/lib/strut/slim_client.rb +61 -0
- data/lib/strut/slim_command.rb +89 -0
- data/lib/strut/slim_command_factory.rb +29 -0
- data/lib/strut/version.rb +3 -0
- data/strut.gemspec +30 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c1c99d8da5a37d0df59242034dbd19880a55f3d0
|
4
|
+
data.tar.gz: 78be5c9a57ea02b04c689739803a3c235e322352
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e0ec403b21ec73ac3a5a0fc74dfbaa5b04fd67c2170c689c28b101ef4f54cac9e8f2416f5658a380088c8d76ba9a2374b97f3741e17a0650c381141d9a161ac7
|
7
|
+
data.tar.gz: 88f3dfda24b2ce97748dc248e277ab3f0fa24f6efafcd239751426d95d058756d397c7897f20b094b7bddd4e086efd174c3677d6e88187cca1fd55f62619a9ae
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.simplecov
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Dan Cutting
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Strut
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/dcutting/strut.svg?branch=master)](https://travis-ci.org/dcutting/strut)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/dcutting/strut/badge.svg?branch=master&service=github)](https://coveralls.io/github/dcutting/strut?branch=master)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/dcutting/strut/badges/gpa.svg)](https://codeclimate.com/github/dcutting/strut)
|
6
|
+
|
7
|
+
Acceptance testing with [Swagger](http://swagger.io).
|
8
|
+
|
9
|
+
Rather than testing your web service through the API (and therefore requiring your whole stack to be up and running with sample data), Strut uses [Slim](http://www.fitnesse.org/FitNesse.UserGuide.WritingAcceptanceTests.SliM.SlimProtocol) and fixture code. This lets you mock out databases and other external systems, while still covering the major parts of your web service API.
|
10
|
+
|
11
|
+
## Why?
|
12
|
+
|
13
|
+
* Want to specify our web service APIs in Swagger
|
14
|
+
- Because it’s pretty
|
15
|
+
- Because it’s concise
|
16
|
+
- Because it has tools that help you transform it into docs, etc.
|
17
|
+
* Want to write automated acceptance tests for our web service APIs
|
18
|
+
- Because we don’t want to manually test it for releases
|
19
|
+
- Because we want to be confident we don’t break it accidentally
|
20
|
+
* Don’t want to duplicate the API in the Swagger spec and the test suite
|
21
|
+
- Because the Swagger spec will drift out of sync
|
22
|
+
- Because we’ll need to maintain two different ways of saying similar things
|
23
|
+
* Therefore, Strut!
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
Strut is a command-line tool installed via [RubyGems](https://rubygems.org):
|
28
|
+
|
29
|
+
$ gem install strut
|
30
|
+
|
31
|
+
Then run it from any directory containing a .strut.yml configuration file:
|
32
|
+
|
33
|
+
$ strut
|
34
|
+
|
35
|
+
## .strut.yml configuration file
|
36
|
+
|
37
|
+
You need a .strut.yml configuration file in the directory where you run strut (or you can specify a path to one as the only argument to strut). That file should look like this:
|
38
|
+
|
39
|
+
swagger:
|
40
|
+
my_service.yaml
|
41
|
+
runner:
|
42
|
+
Runner.exe -a "..\MyService.Specs\bin\Debug\MyService.Specs.dll.config" -r fitSharp.Slim.Service.Runner,Slim/fitsharp.dll MyService.Specs/bin/Debug/MyService.Specs.dll 9011
|
43
|
+
host:
|
44
|
+
localhost
|
45
|
+
port:
|
46
|
+
9011
|
47
|
+
max_attempts:
|
48
|
+
3
|
49
|
+
namespace:
|
50
|
+
Specs
|
51
|
+
output:
|
52
|
+
pretty
|
53
|
+
|
54
|
+
The `runner` property is a command that runs the Slim server and attaches to your system under test. Strut will automatically run this for you, and kill it when the tests complete. This is an optional parameter. If omitted, Strut will still attempt to connect to the provided host and port, but you will need to manually ensure the Slim server is running.
|
55
|
+
|
56
|
+
You can have "pretty" output (similar to default Cucumber output), or "junit" XML output.
|
57
|
+
|
58
|
+
## Development
|
59
|
+
|
60
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
61
|
+
|
62
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
63
|
+
|
64
|
+
### Windows
|
65
|
+
|
66
|
+
* Install Ruby using [RubyInstaller](http://rubyinstaller.org)
|
67
|
+
* Install [gitbash](https://git-scm.com/download/win)
|
68
|
+
* gem install bundler
|
69
|
+
* git clone git@github.com:dcutting/strut.git
|
70
|
+
* cd strut
|
71
|
+
* bin/setup
|
72
|
+
* bundle exec ruby exe/strut .strut.yml
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dcutting/strut. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
77
|
+
|
78
|
+
## License
|
79
|
+
|
80
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "strut"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/strut
ADDED
data/lib/strut.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "strut/config"
|
2
|
+
require "strut/parser"
|
3
|
+
require "strut/report_builder"
|
4
|
+
require "strut/report_junit_formatter"
|
5
|
+
require "strut/report_pretty_formatter"
|
6
|
+
require "strut/slim_client"
|
7
|
+
require "strut/version"
|
8
|
+
|
9
|
+
module Strut
|
10
|
+
def self.run(args)
|
11
|
+
Strut.new.run(args)
|
12
|
+
end
|
13
|
+
|
14
|
+
class Strut
|
15
|
+
def run(args)
|
16
|
+
config_file = args.shift || ".strut.yml"
|
17
|
+
config = read_config(config_file)
|
18
|
+
|
19
|
+
yaml = File.read(config.swagger)
|
20
|
+
document = Parser.new(config.namespace).parse(yaml)
|
21
|
+
|
22
|
+
responses = get_responses(config, document)
|
23
|
+
exit if responses.nil?
|
24
|
+
|
25
|
+
report = ReportBuilder.new.build(responses, document)
|
26
|
+
formatter = make_formatter(config, yaml)
|
27
|
+
output = formatter.format(report)
|
28
|
+
puts output
|
29
|
+
end
|
30
|
+
|
31
|
+
def read_config(config_file)
|
32
|
+
begin
|
33
|
+
return Config.new(config_file)
|
34
|
+
rescue => e
|
35
|
+
puts e
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_responses(config, document)
|
41
|
+
pid = config.runner ? spawn(config.runner) : nil
|
42
|
+
begin
|
43
|
+
client = SlimClient.new(config.host, config.port, config.max_attempts)
|
44
|
+
return client.responses_for_commands(document.commands)
|
45
|
+
rescue => e
|
46
|
+
puts e
|
47
|
+
ensure
|
48
|
+
Process.kill("KILL", pid) unless pid.nil?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def make_formatter(config, yaml)
|
53
|
+
if config.output == :junit
|
54
|
+
return ReportJUnitFormatter.new
|
55
|
+
else
|
56
|
+
return ReportPrettyFormatter.new(yaml)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/strut/config.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "pathname"
|
2
|
+
require "strut/extensions"
|
3
|
+
|
4
|
+
module Strut
|
5
|
+
class Config
|
6
|
+
attr_reader :swagger, :runner, :host, :port, :max_attempts, :namespace, :output
|
7
|
+
|
8
|
+
def initialize(config_file)
|
9
|
+
path = File.dirname(config_file)
|
10
|
+
read_and_store(config_file, path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def read_and_store(config_file, path)
|
14
|
+
yaml = File.read(config_file)
|
15
|
+
parsed_yaml = Psych::parse_yaml(yaml)
|
16
|
+
store_values(parsed_yaml, path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def store_values(yaml, config_path)
|
20
|
+
@swagger = swagger_path(yaml, config_path)
|
21
|
+
@runner = extract_optional_value(yaml, "runner")
|
22
|
+
@host = extract_value(yaml, "host")
|
23
|
+
@port = extract_int_value(yaml, "port")
|
24
|
+
@max_attempts = extract_int_value(yaml, "max_attempts")
|
25
|
+
@namespace = extract_value(yaml, "namespace")
|
26
|
+
@output = extract_enum_value(yaml, "output", [:junit, :pretty])
|
27
|
+
end
|
28
|
+
|
29
|
+
def swagger_path(yaml, config_path)
|
30
|
+
swagger_path = Pathname.new(extract_value(yaml, "swagger"))
|
31
|
+
unless swagger_path.absolute?
|
32
|
+
swagger_path = Pathname.new(config_path) + swagger_path
|
33
|
+
end
|
34
|
+
swagger_path.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
def extract_optional_value(yaml, name)
|
38
|
+
extract_value(yaml, name, true)
|
39
|
+
end
|
40
|
+
|
41
|
+
def extract_value(yaml, name, optional = false)
|
42
|
+
value = yaml[name]
|
43
|
+
value = value["value"] unless value.nil?
|
44
|
+
throw "No '#{name}' specified." if value.nil? and !optional
|
45
|
+
value
|
46
|
+
end
|
47
|
+
|
48
|
+
def extract_int_value(yaml, name)
|
49
|
+
value = extract_value(yaml, name).to_i
|
50
|
+
throw "'#{name}' must be a number > 0." unless value > 0
|
51
|
+
value
|
52
|
+
end
|
53
|
+
|
54
|
+
def extract_enum_value(yaml, name, enums)
|
55
|
+
value = extract_value(yaml, name).to_sym
|
56
|
+
throw "'#{name}' must be one of #{enums}." unless enums.include?(value)
|
57
|
+
value
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require "psych"
|
2
|
+
require "psych/nodes"
|
3
|
+
require "psych/tree_builder"
|
4
|
+
|
5
|
+
# Adapted from:
|
6
|
+
# http://stackoverflow.com/questions/29462856/loading-yaml-with-line-number-for-each-key
|
7
|
+
|
8
|
+
module Psych
|
9
|
+
def self.parse_yaml(yaml)
|
10
|
+
handler = LineNumberHandler.new
|
11
|
+
parser = Psych::Parser.new(handler)
|
12
|
+
handler.parser = parser
|
13
|
+
parser.parse(yaml)
|
14
|
+
handler.root.to_ruby.first
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Psych's first step is to parse the Yaml into an AST of Node objects
|
19
|
+
# so we open the Node class and add a way to track the line.
|
20
|
+
class Psych::Nodes::Node
|
21
|
+
attr_accessor :line
|
22
|
+
end
|
23
|
+
|
24
|
+
# We need to provide a handler that will add the line to the node
|
25
|
+
# as it is parsed. TreeBuilder is the "usual" handler, that
|
26
|
+
# creates the AST.
|
27
|
+
class LineNumberHandler < Psych::TreeBuilder
|
28
|
+
|
29
|
+
# The handler needs access to the parser in order to call mark
|
30
|
+
attr_accessor :parser
|
31
|
+
|
32
|
+
# We are only interested in scalars, so here we override
|
33
|
+
# the method so that it calls mark and adds the line info
|
34
|
+
# to the node.
|
35
|
+
def scalar value, anchor, tag, plain, quoted, style
|
36
|
+
mark = parser.mark
|
37
|
+
s = super
|
38
|
+
s.line = mark.line
|
39
|
+
s
|
40
|
+
end
|
41
|
+
|
42
|
+
def start_mapping anchor, tag, implicit, style
|
43
|
+
mark = parser.mark
|
44
|
+
s = super
|
45
|
+
s.line = mark.line
|
46
|
+
s
|
47
|
+
end
|
48
|
+
|
49
|
+
def start_sequence anchor, tag, implicit, style
|
50
|
+
mark = parser.mark
|
51
|
+
s = super
|
52
|
+
s.line = mark.line
|
53
|
+
s
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# The next step is to convert the AST to a Ruby object.
|
58
|
+
# Psych does this using the visitor pattern with the ToRuby
|
59
|
+
# visitor. Here we patch ToRuby rather than inherit from it
|
60
|
+
# as it makes the last step a little easier.
|
61
|
+
class Psych::Visitors::ToRuby
|
62
|
+
|
63
|
+
# This is the method for creating hashes. There may be problems
|
64
|
+
# with Yaml mappings that have tags.
|
65
|
+
def revive_hash hash, o
|
66
|
+
o.children.each_slice(2) { |k,v|
|
67
|
+
key = accept(k)
|
68
|
+
val = accept(v)
|
69
|
+
|
70
|
+
val = { "value" => val, "line" => v.line} # line is 0 based, so + 1
|
71
|
+
|
72
|
+
# Code dealing with << (for merging hashes) omitted.
|
73
|
+
# If you need this you will probably need to copy it
|
74
|
+
# in here. See the method:
|
75
|
+
# https://github.com/tenderlove/psych/blob/v2.0.13/lib/psych/visitors/to_ruby.rb#L333-L365
|
76
|
+
|
77
|
+
hash[key] = val
|
78
|
+
}
|
79
|
+
hash
|
80
|
+
end
|
81
|
+
end
|