gherkin_generator 1.0.1 → 1.0.3

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gherkin_generator.rb +64 -0
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c020f8419f2062b0da0e876a6b69326ab11ac54
4
- data.tar.gz: cd473780412a8f7a9d759b241a7c50f126745b11
3
+ metadata.gz: b1252b9c59effa14e97e71eb82a6d1a3d6abcd66
4
+ data.tar.gz: 6154bddbccc55a7b65b9266532f8e8c53e9fa4b6
5
5
  SHA512:
6
- metadata.gz: ef111a3d2e581e07d63aba1fff8ed6a2e9a9d586c1c4db541db21643781d3b8ffdc0073cba55451d51941a140172bdf4ff325e7283825d5763992d6f4f3dc89d
7
- data.tar.gz: fc65c3569844284640e97dea090cdfb5e281231ba8e240176032958b8d664d703fc47c0202aa8149ae11b444b67574ad7644adb45cdb84a6cd44e348acfc6b51
6
+ metadata.gz: a2a650dbdb55be2e173a8de6ab08e3407f306ca0b80508c4007b12149bdc1bb9ae7717f3e76333f65fa0e5d0f85b14f61ef3217877bda4169c3eee68e4c51fc9
7
+ data.tar.gz: a4eb5bd8531bafe74fbcd10c10b623166d196b32dc6f9130f6aa5b13f9e37ec0c2ccd38acb26b92549db56aa82abda57746fc5b6f1684e8ca84de5cf57ce5ab2
@@ -0,0 +1,64 @@
1
+ class GherkinGenerator
2
+ attr_accessor :description
3
+
4
+ def initialize(feature_name)
5
+ @feature_name = feature_name
6
+ @scenarios = []
7
+ @tag = ''
8
+ end
9
+
10
+ def add_scenario(scenario)
11
+ examples_keyword = 'Examples '
12
+ scenario_parts = scenario.split examples_keyword
13
+ if scenario_parts[1] && !@ex_yield.nil?
14
+ examples = @ex_yield.call(scenario_parts[1])
15
+ end
16
+ result = Scenario.new(scenario_parts[0], examples)
17
+ @scenarios << result
18
+ result
19
+ end
20
+
21
+ def example_handler(&block)
22
+ @ex_yield = block
23
+ end
24
+
25
+ def to_gherkin
26
+ feature = 'Feature: ' + @feature_name
27
+ desc = @description.nil? ? '' : "\n\t" + @description.sub("\n", "\n\t")
28
+ scenarios = ''
29
+
30
+ @scenarios.each do |item|
31
+ scenarios << item.format_string
32
+ end
33
+
34
+ feature + desc + scenarios + "\n"
35
+ end
36
+
37
+ class Scenario
38
+ def initialize(scenario, examples)
39
+ @scenario = scenario
40
+ @tag = []
41
+ @examples = if examples.nil?
42
+ ''
43
+ else
44
+ "\n\tExamples:\n\t\t" + examples.strip.gsub("\n", "\n\t\t")
45
+ end
46
+ end
47
+
48
+ def add_tag(tag)
49
+ @tag << '@' + tag
50
+ end
51
+
52
+ def format_string
53
+ keywords = %w(Given And When Then)
54
+ steps = @scenario.split(':')[1].strip
55
+ keywords.map do |word|
56
+ steps = steps.split(" #{word}").join("\n\t\t#{word}")
57
+ end
58
+ scenario = @scenario.split(':')[0]
59
+ tag = @tag.empty? ? '' : (@tag.join(' ') + "\n\t")
60
+ type = @examples.empty? ? 'Scenario' : 'Scenario Outline'
61
+ "\n\n\t" + tag + type + ': ' + scenario + "\n\t\t" + steps + @examples
62
+ end
63
+ end
64
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gherkin_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Carey
@@ -15,7 +15,8 @@ email: opensource+gherkin-formatter@dorightdigital.com
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
- files: []
18
+ files:
19
+ - lib/gherkin_generator.rb
19
20
  homepage:
20
21
  licenses:
21
22
  - MIT
@@ -36,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
36
37
  version: '0'
37
38
  requirements: []
38
39
  rubyforge_project:
39
- rubygems_version: 2.0.5
40
+ rubygems_version: 2.0.3
40
41
  signing_key:
41
42
  specification_version: 4
42
43
  summary: Gherkin Generator