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 +4 -4
- data/README.md +73 -10
- data/kappamaki.gemspec +3 -4
- data/lib/kappamaki.rb +10 -0
- data/spec/kappamaki_spec.rb +16 -0
- metadata +6 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10ed7a3b93d835a5c218b8ef5580105f2f9fbe66
|
4
|
+
data.tar.gz: 5999f91ecf1e906886a602191f10e59d8604cf76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
|
52
|
+
When /^I order a dinner with (.+)$/ do |order_items|
|
23
53
|
|
24
|
-
#
|
25
|
-
'starter: "miso soup" and entree: "
|
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
|
-
|
58
|
+
order_data = Kappamaki.attributes_from_sentence(order_items)
|
29
59
|
|
30
|
-
# The result,
|
60
|
+
# The result, order_data, is this hash:
|
31
61
|
{ starter: "miso soup",
|
32
|
-
entree: "
|
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
|
-
|
35
|
-
|
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
|
|
data/kappamaki.gemspec
CHANGED
@@ -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.
|
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'
|
24
|
-
spec.add_development_dependency '
|
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
|
data/lib/kappamaki.rb
CHANGED
@@ -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
|
data/spec/kappamaki_spec.rb
CHANGED
@@ -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.
|
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-
|
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
|