brine-dsl 0.5.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.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +123 -0
  7. data/Guardfile +12 -0
  8. data/LICENSE +21 -0
  9. data/README.md +137 -0
  10. data/Rakefile +32 -0
  11. data/brine-dsl.gemspec +32 -0
  12. data/config/cucumber.yml +2 -0
  13. data/docs/build.gradle +19 -0
  14. data/docs/cookbook.html +567 -0
  15. data/docs/gradle/wrapper/gradle-wrapper.jar +0 -0
  16. data/docs/gradle/wrapper/gradle-wrapper.properties +6 -0
  17. data/docs/gradlew +172 -0
  18. data/docs/gradlew.bat +84 -0
  19. data/docs/guide.html +1149 -0
  20. data/docs/index.html +472 -0
  21. data/docs/specs.html +1672 -0
  22. data/docs/src/cookbook.adoc +87 -0
  23. data/docs/src/guide.adoc +427 -0
  24. data/docs/src/index.adoc +16 -0
  25. data/docs/src/spec.erb +121 -0
  26. data/docs/src/specs.adoc +24 -0
  27. data/features/argument_transforms/boolean.feature +37 -0
  28. data/features/argument_transforms/datetime.feature +45 -0
  29. data/features/argument_transforms/integer.feature +41 -0
  30. data/features/argument_transforms/list.feature +46 -0
  31. data/features/argument_transforms/object.feature +66 -0
  32. data/features/argument_transforms/quoted.feature +41 -0
  33. data/features/argument_transforms/regex.feature +40 -0
  34. data/features/argument_transforms/template.feature +46 -0
  35. data/features/argument_transforms/whitespace.feature +51 -0
  36. data/features/assertions/is_a_valid.feature +184 -0
  37. data/features/assertions/is_equal_to.feature +60 -0
  38. data/features/assertions/is_including.feature +29 -0
  39. data/features/assertions/is_matching.feature +35 -0
  40. data/features/deprecations/replaced_with.feature +35 -0
  41. data/features/request_construction/basic.feature +29 -0
  42. data/features/request_construction/body.feature +26 -0
  43. data/features/request_construction/clearing.feature +46 -0
  44. data/features/request_construction/headers.feature +94 -0
  45. data/features/request_construction/params.feature +60 -0
  46. data/features/resource_cleanup/cleanup.feature +86 -0
  47. data/features/selectors/all.feature +55 -0
  48. data/features/selectors/any.feature +48 -0
  49. data/features/step_definitions/test_steps.rb +5 -0
  50. data/features/support/env.rb +10 -0
  51. data/lib/brine/cleaner_upper.rb +62 -0
  52. data/lib/brine/coercer.rb +18 -0
  53. data/lib/brine/hooks.rb +4 -0
  54. data/lib/brine/mustache_binder.rb +25 -0
  55. data/lib/brine/requester.rb +125 -0
  56. data/lib/brine/rest_steps.rb +138 -0
  57. data/lib/brine/selector.rb +66 -0
  58. data/lib/brine/step_definitions/assertions.rb +37 -0
  59. data/lib/brine/step_definitions/assignment.rb +13 -0
  60. data/lib/brine/step_definitions/cleanup.rb +4 -0
  61. data/lib/brine/step_definitions/request_construction.rb +19 -0
  62. data/lib/brine/step_definitions/selection.rb +37 -0
  63. data/lib/brine/test_steps.rb +138 -0
  64. data/lib/brine/transforms.rb +81 -0
  65. data/lib/brine/type_checks.rb +35 -0
  66. data/lib/brine/util.rb +35 -0
  67. data/lib/brine.rb +39 -0
  68. data/tutorial/missing.feature +5 -0
  69. data/tutorial/post_matching.feature +12 -0
  70. data/tutorial/post_status.feature +10 -0
  71. data/tutorial/support/env.rb +2 -0
  72. metadata +306 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2a3988772e5439b101fa2d3d9ab87034c04bb8a9
4
+ data.tar.gz: c1491585ad2734877fb636a0f0880b02960e9172
5
+ SHA512:
6
+ metadata.gz: 72aa061fc15c4f629f74fc2ce37aa8c2818570591647dd33e8a7b0dde906f3daf735a2b22845210bb90636a3c04c2961e89b19b2cb463f198b8bd806779f8755
7
+ data.tar.gz: 8888baf7504c251f3011660bdb96eebb66f2f3abe3ae206b6418cc7d0f9d8048bcf1a2fd2ccdf84a22c9c016b2be6c01500419deffca8ab4341976f271f1a421
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/
2
+ tmp
3
+ .gradle
4
+ *~
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3
4
+ - 2.4
5
+ deploy:
6
+ provider: rubygems
7
+ gem: brine-dsl
8
+ api_key:
9
+ secure: QrX84AYqIs2Mz/5SaziW528tWzhx6pBZg93rwGWk8FyCjTZd2yILm+1O2BE/52JQclk/9lbJqzjJYsEirCC+5CmvddojiQCpX/ABeIbBq/DhNjomKf0L+tVglcZMbC/n3Xl6Xaa2kWv00mXxn71Ndj+uqCBq7oPXEZ6Z9Bf2x+Fz4+Mb0yN7tylCsQJ7WUR+EuMccXJ/eRIeVLlBqDtu7Ki534kKwOKWarkGvmvJMaXDRUSVm4dYkLDE+byoZTqu2LhcRcchCQauatDjMIv+NEhoVF9nvJPaFfSBnV64i+RwVIDemNgtSAGfZxmw6Jlf8ZWnlNDCvkXqN4dypqrlIiIZpeJpAZg0zj48sV6PNNNqr5xPgepTbNw8ShUHIQr9E8m9ePnyf1kg6FtkbnP0HYuabNw3XMIa7ZTzeCfKH6hwHFpBfNntZO9Ph6mhBsx3VkBq1RzjM3JKGOQqILsq3EZJdwRL5r+WWp8J6FtHWMfsHxQ5Fj4bAZPBYHKyamLEl14l/grnl+PussGT09DYkDInnmihprHw/5Pl/lOJk7OtmrNB2OrRlDt9spsua4P+sZdiQwqnG/p2UXQSeShQoYbm4pgqrbfKUF3Bye3uYhujXfCu2/vEN9ddv2UBKCCZA/iqZohmZbGZadeayBLLVvB/CTFzEI5z9ya0f8TDTzo=
10
+ on:
11
+ tags: true
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org' do
2
+ gemspec
3
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,123 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ brine-dsl (0.5.0)
5
+ cucumber (~> 2.4)
6
+ faraday
7
+ faraday_middleware
8
+ jsonpath
9
+ mustache
10
+ oauth2
11
+ rspec
12
+
13
+ GEM
14
+ remote: http://rubygems.org/
15
+ specs:
16
+ aruba (0.14.2)
17
+ childprocess (~> 0.5.6)
18
+ contracts (~> 0.9)
19
+ cucumber (>= 1.3.19)
20
+ ffi (~> 1.9.10)
21
+ rspec-expectations (>= 2.99)
22
+ thor (~> 0.19)
23
+ asciidoctor (1.5.6.1)
24
+ builder (3.2.3)
25
+ childprocess (0.5.9)
26
+ ffi (~> 1.0, >= 1.0.11)
27
+ coderay (1.1.2)
28
+ contracts (0.16.0)
29
+ cucumber (2.99.0)
30
+ builder (>= 2.1.2)
31
+ cucumber-core (~> 1.5.0)
32
+ cucumber-wire (~> 0.0.1)
33
+ diff-lcs (>= 1.1.3)
34
+ gherkin (~> 4.0)
35
+ multi_json (>= 1.7.5, < 2.0)
36
+ multi_test (>= 0.1.2)
37
+ cucumber-core (1.5.0)
38
+ gherkin (~> 4.0)
39
+ cucumber-wire (0.0.1)
40
+ diff-lcs (1.3)
41
+ faraday (0.12.2)
42
+ multipart-post (>= 1.2, < 3)
43
+ faraday_middleware (0.12.2)
44
+ faraday (>= 0.7.4, < 1.0)
45
+ ffi (1.9.18)
46
+ formatador (0.2.5)
47
+ gherkin (4.1.3)
48
+ guard (2.14.1)
49
+ formatador (>= 0.2.4)
50
+ listen (>= 2.7, < 4.0)
51
+ lumberjack (~> 1.0)
52
+ nenv (~> 0.1)
53
+ notiffany (~> 0.0)
54
+ pry (>= 0.9.12)
55
+ shellany (~> 0.0)
56
+ thor (>= 0.18.1)
57
+ guard-compat (1.2.1)
58
+ guard-cucumber (2.1.2)
59
+ cucumber (~> 2.0)
60
+ guard-compat (~> 1.0)
61
+ nenv (~> 0.1)
62
+ jsonpath (0.8.10)
63
+ multi_json
64
+ jwt (1.5.6)
65
+ listen (3.1.5)
66
+ rb-fsevent (~> 0.9, >= 0.9.4)
67
+ rb-inotify (~> 0.9, >= 0.9.7)
68
+ ruby_dep (~> 1.2)
69
+ lumberjack (1.0.12)
70
+ method_source (0.9.0)
71
+ multi_json (1.12.2)
72
+ multi_test (0.1.2)
73
+ multi_xml (0.6.0)
74
+ multipart-post (2.0.0)
75
+ mustache (1.0.5)
76
+ nenv (0.3.0)
77
+ notiffany (0.1.1)
78
+ nenv (~> 0.1)
79
+ shellany (~> 0.0)
80
+ oauth2 (1.4.0)
81
+ faraday (>= 0.8, < 0.13)
82
+ jwt (~> 1.0)
83
+ multi_json (~> 1.3)
84
+ multi_xml (~> 0.5)
85
+ rack (>= 1.2, < 3)
86
+ pry (0.11.3)
87
+ coderay (~> 1.1.0)
88
+ method_source (~> 0.9.0)
89
+ rack (2.0.3)
90
+ rake (12.3.0)
91
+ rb-fsevent (0.10.2)
92
+ rb-inotify (0.9.10)
93
+ ffi (>= 0.5.0, < 2)
94
+ rspec (3.7.0)
95
+ rspec-core (~> 3.7.0)
96
+ rspec-expectations (~> 3.7.0)
97
+ rspec-mocks (~> 3.7.0)
98
+ rspec-core (3.7.0)
99
+ rspec-support (~> 3.7.0)
100
+ rspec-expectations (3.7.0)
101
+ diff-lcs (>= 1.2.0, < 2.0)
102
+ rspec-support (~> 3.7.0)
103
+ rspec-mocks (3.7.0)
104
+ diff-lcs (>= 1.2.0, < 2.0)
105
+ rspec-support (~> 3.7.0)
106
+ rspec-support (3.7.0)
107
+ ruby_dep (1.5.0)
108
+ shellany (0.0.1)
109
+ thor (0.20.0)
110
+
111
+ PLATFORMS
112
+ ruby
113
+
114
+ DEPENDENCIES
115
+ aruba!
116
+ asciidoctor!
117
+ brine-dsl!
118
+ guard!
119
+ guard-cucumber!
120
+ rake!
121
+
122
+ BUNDLED WITH
123
+ 1.16.0
data/Guardfile ADDED
@@ -0,0 +1,12 @@
1
+ guard 'cucumber',
2
+ all_after_pass: true,
3
+ all_on_start: true,
4
+ cmd_additional_args: '--profile guard',
5
+ keep_failed: true do
6
+
7
+ clearing = true
8
+ watch(%r{^features/.+\.feature$})
9
+ watch(%r{^lib/.+$}) { "features" }
10
+ watch(%r{^features/step_definitions/.+$}) { "features" }
11
+ watch(%r{^features/support/.+$}) { "features" }
12
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Brightcove
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,137 @@
1
+ Brine
2
+ ===
3
+
4
+ > Cucumber DSL for testing REST APIs
5
+
6
+ Motivation
7
+ ---
8
+ REpresentational State Transfer APIs expose their functionality
9
+ through combinations of fairly coarse primitives that generally
10
+ revolve around the use of transferring data in a standard exchange
11
+ format (such as JSON) using HTTP methods and other aspects of the very
12
+ simple HTTP protocol. Tests for such an API can therefore be defined
13
+ using a domain specific language (DSL) built around those higher level
14
+ ideas rather than requiring a general purpose language (the equivalent
15
+ of scripted `curl` commands with some glue code and assertions).
16
+ This project provides such a DSL by using select libraries
17
+ integrated into Cucumber, where Cucumber provides a test-oriented
18
+ framework for DSL creation.
19
+
20
+ Sample Usage
21
+ ---
22
+ The general usage pattern revolves around construction of a request
23
+ and performing assertions against the received response.
24
+
25
+ ```gherkin
26
+ When the request body is assigned:
27
+ """
28
+ {"first_name": "John",
29
+ "last_name": "Smith"}
30
+ """
31
+ And a POST is sent to `/users`
32
+ Then the value of the response status is equal to `200`
33
+ And the value of the response body is including:
34
+ """
35
+ {"first_name": "John",
36
+ "last_name": "Smith"}
37
+ """
38
+ ```
39
+
40
+ Disclaimer
41
+ ---
42
+ Right now this project is new and features are being implemented as
43
+ needed rather than speculatively. Some of the info here may be more
44
+ optimistic than realistic until things are smoothed out or hopes abandoned.
45
+
46
+ Features
47
+ ---
48
+
49
+ ### Variable Binding/Expansion
50
+
51
+ In cases where dynamic data is in the response or is desired for the
52
+ request, then values can be bound to identifiers which can then be
53
+ expanded using [Mustache](mustache.github.io) templates in your
54
+ feature files.
55
+
56
+ ### Type Transforms
57
+
58
+ Different types of data can be expressed directly in the feature files
59
+ or expanded into variables by using the appropriate syntax for that
60
+ type.
61
+
62
+ [Read More](https://github.com/brightcove/brine/wiki/Argument-Transforms)
63
+
64
+ #### Type Coercion
65
+
66
+ Related to transforms, a facility to coerce types is also provided. This allows
67
+ more intelligent comparison of inputs which have been transformed to a
68
+ richer data type with those that have not been transformed (normally strings).
69
+ As an example comparing a date/time value with a string will attempt to parse
70
+ the string to a date/time so that the values can be compared using the proper semantics.
71
+
72
+ ### Resource Cleanup
73
+
74
+ Tests are likely to create resources which should then be cleaned up,
75
+ restoring the pre-test state of the system: steps to facilitate this
76
+ are provided.
77
+
78
+ ### Authentication
79
+
80
+ Presently OAuth2 is supported to issue authenticated requests during a
81
+ test (likely using a feature `Background`).
82
+
83
+ ### Division of Selection and Assertion
84
+
85
+ To allow for a wider range of tests without an exploding code base
86
+ (and keeping the assertions easier to write), Brine internall splits the
87
+ selection of the value(s) to test from the assertion(s) that will be performed against it.
88
+
89
+ [Read Mode](https://github.com/brightcove/brine/wiki/Selection-and-Assertion)
90
+
91
+ ### Request Construction and Response Assertion Step Definitions
92
+
93
+ The previous features combined with the library of provide steps should
94
+ cover all of the functionality needed to exercise and validate all of
95
+ the functionality exposed by your REST API.
96
+
97
+
98
+ Installation
99
+ ---
100
+
101
+ Presently the gem for this project isn't being published anywhere:
102
+ primarily because tracking down a local gem repository seems scary. If
103
+ this project is open sourced then this will probably change but in the
104
+ meantime the project can be used off of GitHub by adding this to your
105
+ `Gemfile` and performing the usual `bundle install` dance:
106
+
107
+ ```ruby
108
+ git 'git@github.com:brightcove/brine.git', :branch => 'master' do
109
+ gem 'brine'
110
+ end
111
+ ```
112
+
113
+ Specific branches and refs can be targetted as
114
+ documented [here](http://bundler.io/git.html). This should likely be
115
+ done in any cases where you're not actively tracking Brine and don't want
116
+ your tests to suddenly break because of changes to it.
117
+
118
+ Brine can then be "mixed in" to your project (which adds assorted
119
+ modules to the `World` and loads all the step definitions and other
120
+ Cucumber magic) by adding the following to your `support/env.rb` or
121
+ other ruby file:
122
+
123
+ ```ruby
124
+ require 'brine'
125
+
126
+ World(brine_mix)
127
+ ```
128
+
129
+ Select pieces can also be loaded (to be documented). With the above,
130
+ feature files should be able to be written and executed without
131
+ requiring any additional ruby code.
132
+
133
+ Questions? Comments?
134
+ ---
135
+ Check out the [wiki](https://github.com/brightcove/brine/wiki) for more information
136
+ and search for related [issues](https://github.com/brightcove/brine/issues)
137
+ or open one for anything not documented or implemented elsewhere.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ require 'cucumber/rake/task'
3
+ Cucumber::Rake::Task.new
4
+
5
+ task default: %w[check]
6
+
7
+ task :check do
8
+ ENV['ROOT_URL'] = 'http://www.example.com'
9
+ if (ENV['WATCH'])
10
+ Kernel.system("bundle exec guard -c")
11
+ else
12
+ Rake::Task['cucumber'].invoke
13
+ end
14
+ end
15
+
16
+ Cucumber::Rake::Task.new(:tutorial) do |t|
17
+ ENV['ROOT_URL'] = 'https://api.myjson.com/'
18
+ t.cucumber_opts = ['tutorial',
19
+ '-r tutorial/support/env.rb']
20
+ end
21
+
22
+ task :help do
23
+ puts """
24
+ Tasks
25
+ ---
26
+ check - run tests
27
+
28
+ Environment Variables
29
+ ---
30
+ WATCH - (guard) automatically rerun tests on file changes
31
+ """
32
+ end
data/brine-dsl.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |s|
3
+ s.name = 'brine-dsl'
4
+ s.version = '0.5.0'
5
+ s.platform = Gem::Platform::RUBY
6
+ s.authors = ["Matt Whipple"]
7
+ s.email = ["mwhipple@brightcove.com"]
8
+ s.license = 'MIT'
9
+ s.homepage = "http://github.com/brightcove/brine"
10
+ s.summary = "Cucumber@REST in Brine"
11
+ s.description = "Cucumber@REST in Brine"
12
+
13
+ s.required_ruby_version = '>= 2.3.0'
14
+
15
+ s.add_runtime_dependency 'cucumber', '~> 2.4'
16
+ s.add_runtime_dependency 'mustache'
17
+ s.add_runtime_dependency 'oauth2'
18
+ s.add_runtime_dependency 'rspec'
19
+ s.add_runtime_dependency 'jsonpath'
20
+ s.add_runtime_dependency 'faraday'
21
+ s.add_runtime_dependency 'faraday_middleware'
22
+
23
+ s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'aruba'
25
+ s.add_development_dependency 'guard'
26
+ s.add_development_dependency 'guard-cucumber'
27
+ s.add_development_dependency 'asciidoctor'
28
+
29
+ s.files = `git ls-files`.split("\n")
30
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
31
+ s.require_paths = ['lib']
32
+ end
@@ -0,0 +1,2 @@
1
+ debug: --format pretty --strict --backtrace
2
+ guard: --format pretty --strict --backtrace
data/docs/build.gradle ADDED
@@ -0,0 +1,19 @@
1
+ plugins {
2
+ id "org.asciidoctor.gradle.asciidoctor" version "1.5.1"
3
+ }
4
+
5
+ dependencies {
6
+ asciidoctor 'com.github.domgold.doctools.asciidoctor:asciidoctor-gherkin-extension:1.0.1'
7
+ }
8
+
9
+ asciidoctor {
10
+ separateOutputDirs = false
11
+ sourceDir 'src'
12
+ outputDir projectDir
13
+ attributes 'toc' : 'right',
14
+ 'source-highlighter' : 'highlightjs',
15
+ 'icons' : 'font',
16
+ 'page-layout': 'docs',
17
+ 'page-description': '{description}',
18
+ 'page-keywords': '{keywords}'
19
+ }