cornichon 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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rvmrc +60 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +209 -0
- data/Rakefile +13 -0
- data/bin/cornichon +5 -0
- data/bin/setup +8 -0
- data/cornichon.gemspec +28 -0
- data/lib/cornichon.rb +11 -0
- data/lib/cornichon/config.rb +23 -0
- data/lib/cornichon/parser.rb +103 -0
- data/lib/cornichon/version.rb +3 -0
- data/lib/cornichon/writer.rb +56 -0
- metadata +118 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f0296d0b8d9c07b3e06e1997e38c229617931e72
|
|
4
|
+
data.tar.gz: 77d948f2f9ec78b1fa2f9cae5e899b02e59b2b21
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 93ed8757dda8e3b4b626d5ac4af3c6dd77083fb1fdc4ec655a7c5404a4138721ba92135b5f5d9e3bfe413acc81994f240d365caccceb24dc3f52a2d80cfe4b84
|
|
7
|
+
data.tar.gz: df3c0444bb1601c2b2d043529e9b6ef23e1e58ed8678f1f1082b994c7d04660e2a774fe12606ae2c89235e261773176212ae4d2c31028e15e7effd3b60507a2d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
|
4
|
+
# development environment upon cd'ing into the directory
|
|
5
|
+
|
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
|
8
|
+
# echo "rvm use 2.0.0" > .rvmrc
|
|
9
|
+
environment_id="ruby-2.3.1"
|
|
10
|
+
|
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
|
12
|
+
# rvmrc_rvm_version="1.29.1 (master)" # 1.10.1 seems like a safe start
|
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
|
15
|
+
# return 1
|
|
16
|
+
# }
|
|
17
|
+
|
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
|
24
|
+
then
|
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
|
26
|
+
for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
|
|
27
|
+
do
|
|
28
|
+
if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
|
|
29
|
+
then \. "${__hook}" || true
|
|
30
|
+
fi
|
|
31
|
+
done
|
|
32
|
+
unset __hook
|
|
33
|
+
if (( ${rvm_use_flag:=1} >= 1 )) # display automatically
|
|
34
|
+
then
|
|
35
|
+
if [[ $- == *i* ]] # check for interactive shells
|
|
36
|
+
then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)\n" # show the user the ruby and gemset they are using in green
|
|
37
|
+
else printf "%b" "Using: $GEM_HOME\n" # don't use colors in non-interactive shells
|
|
38
|
+
fi
|
|
39
|
+
fi
|
|
40
|
+
else
|
|
41
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
|
42
|
+
rvm --create use "$environment_id" || {
|
|
43
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
|
44
|
+
return 1
|
|
45
|
+
}
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# If you use bundler, this might be useful to you:
|
|
49
|
+
# if [[ -s Gemfile ]] && {
|
|
50
|
+
# ! builtin command -v bundle >/dev/null ||
|
|
51
|
+
# builtin command -v bundle | GREP_OPTIONS="" \command \grep $rvm_path/bin/bundle >/dev/null
|
|
52
|
+
# }
|
|
53
|
+
# then
|
|
54
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
|
55
|
+
# gem install bundler
|
|
56
|
+
# fi
|
|
57
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
|
58
|
+
# then
|
|
59
|
+
# bundle install | GREP_OPTIONS="" \command \grep -vE '^Using|Your bundle is complete'
|
|
60
|
+
# fi
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Thom Gray
|
|
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,209 @@
|
|
|
1
|
+
# Cornichon
|
|
2
|
+
|
|
3
|
+
A cornichon is a fancy gherkin ([WIKI](https://en.wikipedia.org/wiki/Pickled_cucumber#Cornichon))
|
|
4
|
+
|
|
5
|
+
Cornichon allows you to write pseudo-Gherkin features that will transpile to valid Gherkin. In the process, you can programatically insert content into those features before running your cucumber tests. Now, you can write your acceptance tests to be more configurable, flexible, reusable, dynamic and greatly increase your test coverage!
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'cornichon'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install cornichon
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
Add the following files to your project
|
|
26
|
+
```
|
|
27
|
+
your_project/
|
|
28
|
+
features/
|
|
29
|
+
cornichon/
|
|
30
|
+
templates/
|
|
31
|
+
quick_start.cornichon
|
|
32
|
+
presenters/
|
|
33
|
+
quick_start.rb
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```feature
|
|
37
|
+
# features/cornichon/templates/quick_start.cornichon
|
|
38
|
+
|
|
39
|
+
Feature: A very quick start
|
|
40
|
+
|
|
41
|
+
Scenario: You're never gonna keep me down
|
|
42
|
+
Given I've been knocked down {{several}} times
|
|
43
|
+
Then I get up again
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```rb
|
|
47
|
+
# features/cornichon/presenters/quick_start.rb
|
|
48
|
+
|
|
49
|
+
def several
|
|
50
|
+
# return a random number between 2 .. 100
|
|
51
|
+
2 + rand(99)
|
|
52
|
+
end
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Then simply run
|
|
56
|
+
```sh
|
|
57
|
+
bundle exec cornichon
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
And voilà! you should have a brand new feature file in `features/cornichon/features`.
|
|
61
|
+
Now run your cucumber tests!
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
### Simple values
|
|
66
|
+
|
|
67
|
+
use `{{double braces}}` to insert a method value
|
|
68
|
+
|
|
69
|
+
Template:
|
|
70
|
+
```feature
|
|
71
|
+
# features/cornichon/templates/joke.cornichon
|
|
72
|
+
|
|
73
|
+
Scenario: A classic pub joke
|
|
74
|
+
Given A {{person}} walks into a bar
|
|
75
|
+
Then expect consequences
|
|
76
|
+
```
|
|
77
|
+
Presenter:
|
|
78
|
+
```rb
|
|
79
|
+
# features/cornichon/presenters/joke.rb
|
|
80
|
+
|
|
81
|
+
def person
|
|
82
|
+
['Englishman', 'Irishman', 'Scotsman', 'Welshman'].sample
|
|
83
|
+
end
|
|
84
|
+
```
|
|
85
|
+
Sample Output:
|
|
86
|
+
```feature
|
|
87
|
+
# features/cornichon/features/joke.feature
|
|
88
|
+
|
|
89
|
+
Scenario: A classic pub joke
|
|
90
|
+
Given A Scotsman walks into a bar
|
|
91
|
+
Then expect consequences
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Nested values
|
|
95
|
+
|
|
96
|
+
use `{{dot.separated.keys}}` to specify values within a nested hash
|
|
97
|
+
|
|
98
|
+
### Tables
|
|
99
|
+
|
|
100
|
+
use `[[double square brackets]]` to insert a table from an array of hashes (or a single hash for a single row table)
|
|
101
|
+
|
|
102
|
+
Template:
|
|
103
|
+
```feature
|
|
104
|
+
# features/cornichon/templates/nursery_rhyme.cornichon
|
|
105
|
+
|
|
106
|
+
Scenario Outline: A classic nursery rhyme
|
|
107
|
+
Given I was born on a "<day>"
|
|
108
|
+
Then I should "<expectation>"
|
|
109
|
+
Examples:
|
|
110
|
+
[[mondays_child]]
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
Presenter:
|
|
114
|
+
```rb
|
|
115
|
+
# features/cornichon/presenters/nursery_rhyme.rb
|
|
116
|
+
|
|
117
|
+
def mondays_child
|
|
118
|
+
[
|
|
119
|
+
{
|
|
120
|
+
'day' => 'Monday'
|
|
121
|
+
'expectation' => 'be fair of face'
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
'day' => 'Tuesday'
|
|
125
|
+
'expectation' => 'be full of grace'
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
'day' => 'Wednesday'
|
|
129
|
+
'expectation' => 'be full of woe'
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
'day' => 'Thursday'
|
|
133
|
+
'expectation' => 'have far to go'
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
'day' => 'Friday'
|
|
137
|
+
'expectation' => 'be loving and giving'
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
'day' => 'Saturday'
|
|
141
|
+
'expectation' => 'work hard for a living'
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
'day' => 'Sunday'
|
|
145
|
+
'expectation' => 'be bonnie and blithe and good and gay'
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
end
|
|
149
|
+
```
|
|
150
|
+
Sample Output:
|
|
151
|
+
```feature
|
|
152
|
+
# features/cornichon/features/nursery_rhyme.feature
|
|
153
|
+
|
|
154
|
+
Scenario Outline: A classic nursery rhyme
|
|
155
|
+
Given I was born on a "<day>"
|
|
156
|
+
Then I should "<expectation>"
|
|
157
|
+
Examples:
|
|
158
|
+
| day | expectation |
|
|
159
|
+
| Monday | be fair of face |
|
|
160
|
+
| Tuesday | be full of grace |
|
|
161
|
+
| Wednesday | be full of woe |
|
|
162
|
+
| Thursday | have far to go |
|
|
163
|
+
| Friday | be loving and giving |
|
|
164
|
+
| Saturday | work hard for a living |
|
|
165
|
+
| Sunday | be bonnie and blithe and good and gay |
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### The + sign
|
|
169
|
+
|
|
170
|
+
use `{{+a plus sign}}` to refer to the last instance of a key (rather than calling the method again)
|
|
171
|
+
You may need to use this if your methods do not return the same value on every call
|
|
172
|
+
|
|
173
|
+
Template:
|
|
174
|
+
```feature
|
|
175
|
+
# features/cornichon/templates/reply.cornichon
|
|
176
|
+
|
|
177
|
+
Scenario: Being polite
|
|
178
|
+
Given my name is {{name}}
|
|
179
|
+
When someone asks me my name
|
|
180
|
+
Then I would say 'My name is {{+name}}'
|
|
181
|
+
```
|
|
182
|
+
Presenter:
|
|
183
|
+
```rb
|
|
184
|
+
# features/cornichon/presenters/reply.rb
|
|
185
|
+
|
|
186
|
+
def name
|
|
187
|
+
['Sarah', 'Thomas', 'Michael', 'Jane', 'Fred', 'Kirsty'].sample
|
|
188
|
+
end
|
|
189
|
+
```
|
|
190
|
+
Sample Output:
|
|
191
|
+
```feature
|
|
192
|
+
# features/cornichon/features/joke.feature
|
|
193
|
+
|
|
194
|
+
Scenario: Being polite
|
|
195
|
+
Given my name is Jane
|
|
196
|
+
When someone asks me my name
|
|
197
|
+
Then I would say 'My name is Jane'
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Development
|
|
201
|
+
|
|
202
|
+
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.
|
|
203
|
+
|
|
204
|
+
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).
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
209
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
2
|
+
require "rspec/core/rake_task"
|
|
3
|
+
|
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
5
|
+
|
|
6
|
+
task :default => :spec
|
|
7
|
+
|
|
8
|
+
task :demo do
|
|
9
|
+
require_relative "lib/cornichon"
|
|
10
|
+
require_relative "lib/cornichon/writer"
|
|
11
|
+
Cornichon.configure(:features_path => 'features')
|
|
12
|
+
Cornichon::Writer.write!(:verbose => true)
|
|
13
|
+
end
|
data/bin/cornichon
ADDED
data/bin/setup
ADDED
data/cornichon.gemspec
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "cornichon/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "cornichon"
|
|
8
|
+
spec.version = Cornichon::VERSION
|
|
9
|
+
spec.authors = ["thomgray"]
|
|
10
|
+
spec.email = ["thomdikdave@hotmail.com"]
|
|
11
|
+
spec.executables << 'cornichon'
|
|
12
|
+
|
|
13
|
+
spec.summary = %q{A fancy gherkin}
|
|
14
|
+
spec.description = %q{A gherkin transpiler that allows you to write cucumber (gherkin) features programatically, thereby greatly improving your test coverage!}
|
|
15
|
+
spec.homepage = "https://github.com/thomgray/cornichon"
|
|
16
|
+
spec.license = "MIT"
|
|
17
|
+
|
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
spec.require_paths = ["lib"]
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
27
|
+
spec.add_development_dependency "cucumber"
|
|
28
|
+
end
|
data/lib/cornichon.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Cornichon
|
|
2
|
+
class Config
|
|
3
|
+
class << self
|
|
4
|
+
def configure(opts)
|
|
5
|
+
@relative_feature_path = opts[:features_path] if opts[:features_path]
|
|
6
|
+
@relative_template_path = opts[:templates_path] if opts[:templates_path]
|
|
7
|
+
@relative_presenter_path = opts[:presenters_path] if opts[:presenters_path]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def relative_feature_path
|
|
11
|
+
@relative_feature_path ||= 'features/cornichon/features'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def relative_template_path
|
|
15
|
+
@relative_template_path ||= 'features/cornichon/templates'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def relative_presenter_path
|
|
19
|
+
@relative_presenter_path ||= 'features/cornichon/presenters'
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
module Cornichon
|
|
2
|
+
class Parser
|
|
3
|
+
class << self
|
|
4
|
+
def parse(template)
|
|
5
|
+
template.gsub(/{{(.*?)}}|^(.*)\[\[(.*?)\]\]/) { |match|
|
|
6
|
+
replacement = nil
|
|
7
|
+
if $1
|
|
8
|
+
replacement = handle_string $1.strip
|
|
9
|
+
elsif $3
|
|
10
|
+
replacement = get_array(call($3), $2.length)
|
|
11
|
+
replacement.prepend($2) if replacement
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
if replacement
|
|
15
|
+
replacement
|
|
16
|
+
else
|
|
17
|
+
match
|
|
18
|
+
end
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def handle_string(raw)
|
|
25
|
+
retained = false
|
|
26
|
+
if raw.start_with? '+'
|
|
27
|
+
raw.slice!('+').lstrip!
|
|
28
|
+
retained = true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
value = call(raw, retained)
|
|
32
|
+
|
|
33
|
+
get_string value
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def inject_path(hash, path)
|
|
37
|
+
return hash if path.empty?
|
|
38
|
+
begin
|
|
39
|
+
path.inject(hash, :[])
|
|
40
|
+
rescue
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def retain_cache
|
|
46
|
+
@retain_cache ||= Hash.new
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def call(method, retained = false)
|
|
50
|
+
value = nil
|
|
51
|
+
|
|
52
|
+
key_path = method.split('.')
|
|
53
|
+
first = key_path.first
|
|
54
|
+
remainder = key_path.drop 1
|
|
55
|
+
|
|
56
|
+
if retained
|
|
57
|
+
value = retain_cache[first]
|
|
58
|
+
return inject_path(value, remainder) if value
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
begin
|
|
62
|
+
value = send first
|
|
63
|
+
rescue
|
|
64
|
+
return nil
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
if value
|
|
68
|
+
retain_cache[first] = value
|
|
69
|
+
value = inject_path(value, remainder)
|
|
70
|
+
end
|
|
71
|
+
value
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def get_string(str)
|
|
75
|
+
str.to_s if str
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def get_array(array, lpad = 0)
|
|
79
|
+
return nil unless array
|
|
80
|
+
array = [array] if array.is_a?(Hash)
|
|
81
|
+
return nil unless array.is_a?(Array)
|
|
82
|
+
|
|
83
|
+
all_keys = array.reduce([]) { |acc, obj|
|
|
84
|
+
acc | obj.keys
|
|
85
|
+
}
|
|
86
|
+
columns = all_keys.map { |key|
|
|
87
|
+
max_width = key.length
|
|
88
|
+
rows = [key] + array.map { |example|
|
|
89
|
+
cell = example.fetch(key, "")
|
|
90
|
+
max_width = cell.length if cell.length > max_width
|
|
91
|
+
cell
|
|
92
|
+
}
|
|
93
|
+
rows.map! { |cell| cell.ljust(max_width) }
|
|
94
|
+
}
|
|
95
|
+
(0...columns.first.length).map { |i|
|
|
96
|
+
first = '| '
|
|
97
|
+
first.prepend(' ' * lpad) if i > 0
|
|
98
|
+
first << columns.map { |c| c[i] }.join(' | ') << ' |'
|
|
99
|
+
}.join("\n")
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require "cornichon/config"
|
|
2
|
+
require "cornichon/parser"
|
|
3
|
+
require "fileutils"
|
|
4
|
+
|
|
5
|
+
module Cornichon
|
|
6
|
+
class Writer
|
|
7
|
+
class << self
|
|
8
|
+
def write!(opts = {})
|
|
9
|
+
$verbose = opts[:verbose]
|
|
10
|
+
if $verbose
|
|
11
|
+
puts "SETUP: templates at #{Config.relative_template_path}"
|
|
12
|
+
puts "SETUP: presenters at #{Config.relative_presenter_path}"
|
|
13
|
+
puts "SETUP: features written to #{Config.relative_feature_path}\n"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
require_presenter_methods
|
|
17
|
+
create_feature_dir
|
|
18
|
+
|
|
19
|
+
templates.each { |template|
|
|
20
|
+
template_name = File.basename(template, ".cornichon")
|
|
21
|
+
feature_path = File.join(Dir.pwd, Config.relative_feature_path, "#{template_name}.feature")
|
|
22
|
+
raw_feature = parse_template(template)
|
|
23
|
+
IO.write(feature_path, raw_feature)
|
|
24
|
+
puts "written #{feature_path}" if $verbose
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def templates
|
|
29
|
+
@templates ||= Proc.new {
|
|
30
|
+
full_path = File.join(Dir.pwd, Config.relative_template_path)
|
|
31
|
+
Dir.glob("#{full_path}/*.cornichon")
|
|
32
|
+
}.call
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def parse_template(template_file)
|
|
36
|
+
raw_template = IO.read(template_file)
|
|
37
|
+
Parser.parse(raw_template)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def require_presenter_methods
|
|
43
|
+
full_path = File.join(Dir.pwd, Config.relative_presenter_path)
|
|
44
|
+
Dir.glob("#{full_path}/*.rb").each { |file|
|
|
45
|
+
puts "SETUP: requiring #{file}" if $verbose
|
|
46
|
+
require "#{file}"
|
|
47
|
+
}
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def create_feature_dir
|
|
51
|
+
dir_path = File.join(Dir.pwd, Config.relative_feature_path)
|
|
52
|
+
FileUtils.mkdir_p dir_path unless Dir.exist? dir_path
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cornichon
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- thomgray
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-08-13 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.15'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.15'
|
|
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: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: cucumber
|
|
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
|
+
description: A gherkin transpiler that allows you to write cucumber (gherkin) features
|
|
70
|
+
programatically, thereby greatly improving your test coverage!
|
|
71
|
+
email:
|
|
72
|
+
- thomdikdave@hotmail.com
|
|
73
|
+
executables:
|
|
74
|
+
- cornichon
|
|
75
|
+
extensions: []
|
|
76
|
+
extra_rdoc_files: []
|
|
77
|
+
files:
|
|
78
|
+
- ".gitignore"
|
|
79
|
+
- ".rspec"
|
|
80
|
+
- ".rvmrc"
|
|
81
|
+
- ".travis.yml"
|
|
82
|
+
- Gemfile
|
|
83
|
+
- LICENSE.txt
|
|
84
|
+
- README.md
|
|
85
|
+
- Rakefile
|
|
86
|
+
- bin/cornichon
|
|
87
|
+
- bin/setup
|
|
88
|
+
- cornichon.gemspec
|
|
89
|
+
- lib/cornichon.rb
|
|
90
|
+
- lib/cornichon/config.rb
|
|
91
|
+
- lib/cornichon/parser.rb
|
|
92
|
+
- lib/cornichon/version.rb
|
|
93
|
+
- lib/cornichon/writer.rb
|
|
94
|
+
homepage: https://github.com/thomgray/cornichon
|
|
95
|
+
licenses:
|
|
96
|
+
- MIT
|
|
97
|
+
metadata: {}
|
|
98
|
+
post_install_message:
|
|
99
|
+
rdoc_options: []
|
|
100
|
+
require_paths:
|
|
101
|
+
- lib
|
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
|
+
requirements:
|
|
104
|
+
- - ">="
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
version: '0'
|
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - ">="
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '0'
|
|
112
|
+
requirements: []
|
|
113
|
+
rubyforge_project:
|
|
114
|
+
rubygems_version: 2.6.10
|
|
115
|
+
signing_key:
|
|
116
|
+
specification_version: 4
|
|
117
|
+
summary: A fancy gherkin
|
|
118
|
+
test_files: []
|