gherkin_format 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ff0287a7fd69cc632acd63eaa3e88cb873307b6d
4
+ data.tar.gz: f2858e507b780084ff5d5e67b7dcd4b5acc1dc4b
5
+ SHA512:
6
+ metadata.gz: 35e7f2cc6d207de8c3bf1833ba9ce7cbc8622087bbd918f81f5b823b25348ef36c6adf93472513ef8c1020b8756303e34ae3ca7307aed50c38d742db46fae417
7
+ data.tar.gz: 08b4d12bf60bb7495821ddc25769f858cf957e774a7d31735d1ddf9510d15c065151dd3207bc8fb53c284fc8e7db028b8fcc92c4a344bed8c92813731e108e8b
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Funkwerk AG
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.
22
+
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # gherkin_format
2
+ Format Gherkin Files
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require 'rake/testtask'
2
+
3
+ task default: :build
4
+
5
+ desc 'Builds the Gem.'
6
+ task build: :test do
7
+ sh 'gem build gherkin_format.gemspec'
8
+ end
9
+
10
+ task test: :rubocop
11
+ Rake::TestTask.new do |t|
12
+ t.libs << 'test'
13
+ end
14
+
15
+ task test: :cli_test
16
+ task :cli_test do
17
+ gherkin_format(%w(foo.feature))
18
+ end
19
+
20
+ def gherkin_format(args)
21
+ sh "ruby -ilib lib/* bin/gherkin_format #{args.join ' '}"
22
+ end
23
+
24
+ desc 'Publishes the Gem'
25
+ task :push do
26
+ sh 'gem push gherkin_format-1.0.0-gem'
27
+ end
28
+
29
+ desc 'Checks ruby style'
30
+ task :rubocop do
31
+ sh 'rubocop'
32
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gherkin_format'
3
+ require 'optparse'
4
+
5
+ options = {}
6
+ OptionParser.new do |opts|
7
+ opts.banner = 'Usage: gherkin_format [files]'
8
+ opts.on('-v', '--[no-]verbose', 'Run verbosely') do |verbose|
9
+ options[:verbose] = verbose
10
+ end
11
+ opts.on('-r', '--[no-]replace', 'Replaces input files') do |replace|
12
+ options[:replace] = replace
13
+ end
14
+ end.parse!
15
+
16
+ formatter = GherkinFormat.new
17
+ ARGV.each do |file|
18
+ formatter.format file, options
19
+ end
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |specification|
2
+ specification.name = 'gherkin_format'
3
+ specification.version = '0.0.1'
4
+ specification.date = '2015-05-19'
5
+ specification.summary = 'Gherkin Format'
6
+ specification.description = 'Format Gherkin Files'
7
+ specification.authors = ['Stefan Rohe']
8
+ specification.homepage = 'http://github.com/funkwerk/gherkin_format/'
9
+ specification.files = `git ls-files`.split("\n")
10
+ specification.executables = specification.files.grep(%r{^bin/}) { |file| File.basename(file) }
11
+ specification.add_runtime_dependency 'gherkin', ['>= 2.12.2']
12
+ end
@@ -0,0 +1,28 @@
1
+ require 'gherkin/formatter/pretty_formatter'
2
+ require 'gherkin/parser/parser'
3
+ require 'stringio'
4
+
5
+ # format gherkin files
6
+ class GherkinFormat
7
+ def format_string(input, file = 'generated.feature')
8
+ io = StringIO.new
9
+ formatter = Gherkin::Formatter::PrettyFormatter.new(io, true, false)
10
+ parser = Gherkin::Parser::Parser.new(formatter, true)
11
+ parser.parse(input, file, 0)
12
+ io.string.split("\n").map(&:rstrip).join("\n") + "\n"
13
+ end
14
+
15
+ def format(file, options = {})
16
+ input = File.read file
17
+ output = format_string input, file
18
+ return if input == output
19
+
20
+ if options.key? :replace
21
+ File.write("#{file}_orig", input)
22
+ File.write("#{file}", output)
23
+ end
24
+
25
+ puts "File #{file} is not formatted well."
26
+ fail "File #{file} is not formatted well."
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ require 'minitest/autorun'
2
+ require 'gherkin_format'
3
+
4
+ # gherkin format test
5
+ class GherkinFormatTest < Minitest::Unit::TestCase
6
+ def setup
7
+ @format = GherkinFormat.new
8
+ end
9
+
10
+ def test_formats_string
11
+ # setup
12
+ feature = %(Feature: Foo
13
+ Scenario: Bar)
14
+ expected = %(Feature: Foo
15
+
16
+ Scenario: Bar
17
+ )
18
+
19
+ # exercise
20
+ actual = @format.format_string(feature)
21
+
22
+ # verify
23
+ assert_equal expected, actual
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gherkin_format
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stefan Rohe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gherkin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.12.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.12.2
27
+ description: Format Gherkin Files
28
+ email:
29
+ executables:
30
+ - gherkin_format
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - bin/gherkin_format
38
+ - gherkin_format.gemspec
39
+ - lib/gherkin_format.rb
40
+ - test/test_gherkin_format.rb
41
+ homepage: http://github.com/funkwerk/gherkin_format/
42
+ licenses: []
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.2.3
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Gherkin Format
64
+ test_files: []