kappamaki 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 960f9aaf3f5c2e884699282e0cda5b44b4026b0f
4
- data.tar.gz: c35b41b43bf956587aba8e0099a064083c925db5
3
+ metadata.gz: 10ed7a3b93d835a5c218b8ef5580105f2f9fbe66
4
+ data.tar.gz: 5999f91ecf1e906886a602191f10e59d8604cf76
5
5
  SHA512:
6
- metadata.gz: 5344d48ba377716604389d71312859a8a7391fc82989aa85f658a60edc960874199bf09e645b78f9424f668e92af3c05396368714feceb75192b13b51e43b6b6
7
- data.tar.gz: 23dcd71028f962236686ee2042ee5cbeb4b97f742120654026ba3b7163d24d5bdc563b9cab3e6279766c351cc7868c3b076c052441d344a7006b14202694afe1
6
+ metadata.gz: 6c80afb2dc07f5aded681535d1f355682517016a6a0730f9a9bc79401cc3a7283a6135d55db7ea9c1b545df2c30b8fcda01f248ee315da7b73146bb3f347c1bf
7
+ data.tar.gz: 4174272fab1d6528bf87efb8fd970d309a5f893ed8f7b4a5b289b60164dfe305edad6ef3ef78975b4a83fe32b3080bc67880b8420e3e91a3f7299d559bcfb969
data/README.md CHANGED
@@ -10,29 +10,92 @@ which adds naturalness and freshness to a meal.
10
10
 
11
11
  Kappamaki provides a number of helper methods that can be used directly
12
12
  in your Cucumber step definitions.
13
- It allows for Cucumber steps that look like this:
13
+
14
+ ### from_sentence
15
+
16
+ Parses a list of values from a sentence.
17
+
18
+ ```cucumber
19
+ Given the restaurant offers cucumber rolls, philadelphia rolls, and avocado rolls
20
+ ```
21
+
22
+ Your step definition would look like this:
23
+
24
+ ```ruby
25
+ Given /^the restaurant offers (.+)$/ do |menu_list|
26
+
27
+ # menu_list is this string:
28
+ 'cucumber rolls, philadelphia rolls, and avocado rolls'
29
+
30
+ # Let's parse this into an array
31
+ menu = Kappamaki.from_sentence menu_list
32
+
33
+ # The result, menu, is this array:
34
+ ['cucumber rolls', 'philadelphia rolls', 'avocado rolls']
35
+
36
+ # Now we can set up our menu here...
37
+ end
38
+ ```
39
+
40
+
41
+ ### attributes_from_sentence
42
+
43
+ Parses key-value pairs from natural sentences.
14
44
 
15
45
  ```cucumber
16
- Given I have a dinner with starter: "miso soup" and entree: "sushi"
46
+ When I order a dinner with starter: "miso soup" and entree: "cucumber rolls"
17
47
  ```
18
48
 
19
49
  Your step definition would look like this:
20
50
 
21
51
  ```ruby
22
- Given /^I have a dinner with (.+)$/ do |dinner_attributes|
52
+ When /^I order a dinner with (.+)$/ do |order_items|
23
53
 
24
- # dinner_attributes is this string:
25
- 'starter: "miso soup" and entree: "sushi"'
54
+ # order_items is this string:
55
+ 'starter: "miso soup" and entree: "cucumber rolls"'
26
56
 
27
57
  # Let's parse that string using Kappamaki
28
- dinner_data = Kappamaki.attributes_from_sentence(dinner_attributes)
58
+ order_data = Kappamaki.attributes_from_sentence(order_items)
29
59
 
30
- # The result, dinner_data, is this hash:
60
+ # The result, order_data, is this hash:
31
61
  { starter: "miso soup",
32
- entree: "sushi" }
62
+ entree: "cucumber rolls" }
63
+
64
+ # now we can set up our order...
65
+ create :order, order_data
66
+ end
67
+ ```
68
+
69
+
70
+ ### symbolize_keys_deep
71
+
72
+ Converts the keys of a hash into symbols.
73
+
74
+ ```cucumber
75
+ Then I am served these items
76
+ | name | count |
77
+ | miso soup | 1 |
78
+ | cucumber roll | 8 |
79
+ ```
80
+
81
+ Your step definition would look like this:
82
+
83
+ ```ruby
84
+ Then ^I am served these items do |entrees|
85
+ entrees.hashes.each do |entree|
86
+
87
+ # entree is this hash:
88
+ { 'name' => 'miso soup', 'count' => '1' }
89
+
90
+ # Let's convert the keys to symbols.
91
+ Kappamaki.symbolize_keys_deep! entree
92
+
93
+ # Now entree is this hash:
94
+ { name: 'miso soup', count: '1' }
33
95
 
34
- # now we can set up our system using this data
35
- create :dinner, dinner_data
96
+ # Now we can use this hash in places that expect hashes with symbols
97
+ expect(order).to include entree
98
+ end
36
99
  end
37
100
  ```
38
101
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'kappamaki'
7
- spec.version = '0.0.2'
7
+ spec.version = '0.0.3'
8
8
  spec.authors = ['Kevin Goslar']
9
9
  spec.email = ['kevin.goslar@originate.com']
10
10
  spec.summary = 'Tools for natural, high-level, sophisticated Cucumber steps'
@@ -20,9 +20,8 @@ Gem::Specification.new do |spec|
20
20
  spec.test_files = spec.files.grep('spec')
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_development_dependency 'bundler', '~> 0'
24
- spec.add_development_dependency 'rake', '~> 0'
25
- spec.add_development_dependency 'rspec', '~> 0'
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'rspec'
26
25
 
27
26
  spec.required_ruby_version = '>= 1.9.3'
28
27
  end
@@ -21,4 +21,14 @@ module Kappamaki
21
21
  .map{|s| s.gsub '"', ''}
22
22
  end
23
23
 
24
+
25
+ # Converts all keys in the given hash to symbols
26
+ def self.symbolize_keys_deep!(h)
27
+ h.keys.each do |k|
28
+ ks = k.to_sym
29
+ h[ks] = h.delete k
30
+ symbolize_keys_deep! h[ks] if h[ks].kind_of? Hash
31
+ end
32
+ end
33
+
24
34
  end
@@ -35,5 +35,21 @@ describe Kappamaki do
35
35
  end
36
36
  end
37
37
  end
38
+
39
+
40
+ describe 'symbolize_keys_deep!' do
41
+
42
+ it 'converts string keys to symbols' do
43
+ actual = { 'one' => 'two', 'alpha' => 'beta' }
44
+ Kappamaki.symbolize_keys_deep! actual
45
+ expect(actual).to eq({ one: 'two', alpha: 'beta' })
46
+ end
47
+
48
+ it 'converts nested keys' do
49
+ actual = { 'one' => { 'alpha' => 'beta' }}
50
+ Kappamaki.symbolize_keys_deep! actual
51
+ expect(actual).to eq({ one: { alpha: 'beta' }})
52
+ end
53
+ end
38
54
  end
39
55
 
metadata CHANGED
@@ -1,55 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kappamaki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Goslar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-23 00:00:00.000000000 Z
11
+ date: 2014-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - "~>"
31
+ - - ">="
46
32
  - !ruby/object:Gem::Version
47
33
  version: '0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - "~>"
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
41
  description: |2