spectifly 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.
Files changed (64) hide show
  1. data/.gitignore +17 -0
  2. data/.ruby-version +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +128 -0
  6. data/Rakefile +8 -0
  7. data/lib/entities/association.entity +11 -0
  8. data/lib/entities/entity.entity +16 -0
  9. data/lib/entities/field.entity +35 -0
  10. data/lib/entities/related_entity.entity +28 -0
  11. data/lib/spectifly.rb +7 -0
  12. data/lib/spectifly/base.rb +8 -0
  13. data/lib/spectifly/base/association.rb +18 -0
  14. data/lib/spectifly/base/builder.rb +102 -0
  15. data/lib/spectifly/base/configuration.rb +19 -0
  16. data/lib/spectifly/base/entity_node.rb +55 -0
  17. data/lib/spectifly/base/field.rb +42 -0
  18. data/lib/spectifly/base/types.rb +27 -0
  19. data/lib/spectifly/configuration.rb +17 -0
  20. data/lib/spectifly/entity.rb +106 -0
  21. data/lib/spectifly/json.rb +8 -0
  22. data/lib/spectifly/json/association.rb +19 -0
  23. data/lib/spectifly/json/builder.rb +21 -0
  24. data/lib/spectifly/json/field.rb +28 -0
  25. data/lib/spectifly/json/types.rb +6 -0
  26. data/lib/spectifly/support.rb +32 -0
  27. data/lib/spectifly/tasks.rb +20 -0
  28. data/lib/spectifly/version.rb +3 -0
  29. data/lib/spectifly/xsd.rb +8 -0
  30. data/lib/spectifly/xsd/association.rb +31 -0
  31. data/lib/spectifly/xsd/builder.rb +43 -0
  32. data/lib/spectifly/xsd/field.rb +92 -0
  33. data/lib/spectifly/xsd/types.rb +32 -0
  34. data/lib/tasks/spectifly.rake +6 -0
  35. data/spec/expectations/extended.xsd +15 -0
  36. data/spec/expectations/group.json +37 -0
  37. data/spec/expectations/group.xsd +39 -0
  38. data/spec/expectations/individual.json +57 -0
  39. data/spec/expectations/individual.xsd +47 -0
  40. data/spec/expectations/presented/masterless_group.json +30 -0
  41. data/spec/expectations/presented/masterless_group.xsd +34 -0
  42. data/spec/expectations/presented/positionless_individual.json +44 -0
  43. data/spec/expectations/presented/positionless_individual.xsd +35 -0
  44. data/spec/fixtures/group.entity +23 -0
  45. data/spec/fixtures/individual.entity +33 -0
  46. data/spec/fixtures/invalid/multiple_root.entity +8 -0
  47. data/spec/fixtures/invalid/no_fields.entity +2 -0
  48. data/spec/fixtures/presenters/masterless_group.entity +8 -0
  49. data/spec/fixtures/presenters/positionless_individual.entity +12 -0
  50. data/spec/spec_helper.rb +10 -0
  51. data/spec/spectifly/base/builder_spec.rb +29 -0
  52. data/spec/spectifly/base/entity_node_spec.rb +29 -0
  53. data/spec/spectifly/base/field_spec.rb +100 -0
  54. data/spec/spectifly/configuration_spec.rb +42 -0
  55. data/spec/spectifly/entity_spec.rb +189 -0
  56. data/spec/spectifly/json/builder_spec.rb +42 -0
  57. data/spec/spectifly/json/field_spec.rb +26 -0
  58. data/spec/spectifly/support_spec.rb +53 -0
  59. data/spec/spectifly/xsd/builder_spec.rb +51 -0
  60. data/spec/spectifly/xsd/field_spec.rb +12 -0
  61. data/spec/spectifly/xsd/types_spec.rb +11 -0
  62. data/spec/support/path_helper.rb +28 -0
  63. data/spectifly.gemspec +32 -0
  64. metadata +251 -0
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe Spectifly::Json::Builder do
5
+ describe '#build' do
6
+ it 'returns a hash representation of the entity' do
7
+ entity = Spectifly::Entity.parse(fixture_path('individual'))
8
+ json_path = expectation_path('individual', 'json')
9
+ hash = described_class.new(entity).build
10
+ JSON.pretty_generate(hash).should == File.read(json_path)
11
+ end
12
+
13
+ it 'works with containing relationships' do
14
+ entity = Spectifly::Entity.parse(fixture_path('group'))
15
+ json_path = expectation_path('group', 'json')
16
+ hash = described_class.new(entity).build
17
+ JSON.pretty_generate(hash).should == File.read(json_path)
18
+ end
19
+ end
20
+
21
+ describe '#present_as' do
22
+ it 'filters entity through presenter, and returns self' do
23
+ entity = Spectifly::Entity.parse(fixture_path('individual'))
24
+ presenter_entity = Spectifly::Entity.parse(fixture_path('presenters/positionless_individual'))
25
+ json_path = expectation_path('presented/positionless_individual', 'json')
26
+ builder = described_class.new(entity)
27
+ builder.present_as(presenter_entity).should == builder
28
+ hash = builder.build
29
+ JSON.pretty_generate(hash).should == File.read(json_path)
30
+ end
31
+
32
+ it 'works with overriding relationships' do
33
+ entity = Spectifly::Entity.parse(fixture_path('group'))
34
+ presenter_entity = Spectifly::Entity.parse(fixture_path('presenters/masterless_group'))
35
+ json_path = expectation_path('presented/masterless_group', 'json')
36
+ builder = described_class.new(entity)
37
+ builder.present_as(presenter_entity).should == builder
38
+ hash = builder.build
39
+ JSON.pretty_generate(hash).should == File.read(json_path)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spectifly::Json::Field do
4
+ describe '#to_h' do
5
+ it 'returns hash format of field' do
6
+ expected = {
7
+ :a_field => {
8
+ :type => 'people',
9
+ :multiple => false,
10
+ :required => true,
11
+ :description => "People who don't worry about longevity",
12
+ :example => 'children',
13
+ :validations => ['Must be young', 'Must love eating mud']
14
+ }
15
+ }
16
+
17
+ field = described_class.new('A Field*', {
18
+ 'Description' => "People who don't worry about longevity",
19
+ 'Type' => 'people',
20
+ 'Example' => 'children',
21
+ 'Validations' => ['Must be young', 'Must love eating mud']
22
+ })
23
+ field.to_h.should == expected
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spectifly::Support do
4
+
5
+ describe '.camelize' do
6
+ it 'removes underscores and spaces and capitalizes the first' do
7
+ Spectifly::Support.camelize('foo_bar One two 3').should == 'FooBarOneTwo3'
8
+ end
9
+
10
+ it 'deals with nested classes' do
11
+ Spectifly::Support.camelize('foo_bar/bar_foo').should == 'FooBar::BarFoo'
12
+ end
13
+ end
14
+
15
+ describe '.lower_camelize' do
16
+ it 'camelizes but with lowercase first character' do
17
+ Spectifly::Support.lower_camelize('we Are the_toasty').should == 'weAreTheToasty'
18
+ Spectifly::Support.lower_camelize('PleaseChange me').should == 'pleaseChangeMe'
19
+ end
20
+ end
21
+
22
+ describe '.tokenize' do
23
+ it 'creates snake_case version of string' do
24
+ Spectifly::Support.tokenize('Albus Dumbledore & his_friend').should == 'albus_dumbledore_and_his_friend'
25
+ end
26
+
27
+ it 'uncamelizes' do
28
+ Spectifly::Support.tokenize('thisStrangeJavalikeWord').should == 'this_strange_javalike_word'
29
+ end
30
+
31
+ it 'returns nil if given nil' do
32
+ Spectifly::Support.tokenize(nil).should be_nil
33
+ end
34
+ end
35
+
36
+ describe '.get_module' do
37
+ it 'returns module from constant' do
38
+ Spectifly::Support.get_module(Spectifly::Support).should == 'Spectifly'
39
+ end
40
+
41
+ it 'works with strings' do
42
+ Spectifly::Support.get_module('Spectifly::Support').should == 'Spectifly'
43
+ end
44
+
45
+ it 'works with multiple parent modules' do
46
+ Spectifly::Support.get_module('The::Way::It::Is').should == 'The::Way::It'
47
+ end
48
+
49
+ it 'returns nil if no module' do
50
+ Spectifly::Support.get_module('LonelyConstant').should be_nil
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe Spectifly::Xsd::Builder do
5
+ describe '.from_path' do
6
+ it 'generates builder from entity at given path' do
7
+ path_builder = Spectifly::Xsd::Builder.from_path(fixture_path('individual'))
8
+ xsd_path = expectation_path('individual', 'xsd')
9
+ xsd = path_builder.build
10
+ xsd.should == File.read(xsd_path)
11
+ end
12
+ end
13
+
14
+ describe '#build' do
15
+ it 'returns an xsd representation of the entity' do
16
+ entity = Spectifly::Entity.parse(fixture_path('individual'))
17
+ xsd_path = expectation_path('individual', 'xsd')
18
+ xsd = Spectifly::Xsd::Builder.new(entity).build
19
+ xsd.should == File.read(xsd_path)
20
+ end
21
+
22
+ it 'includes import directives for custom field types' do
23
+ entity = Spectifly::Entity.parse(fixture_path('group'))
24
+ xsd_path = expectation_path('group', 'xsd')
25
+ xsd = Spectifly::Xsd::Builder.new(entity).build
26
+ xsd.should == File.read(xsd_path)
27
+ end
28
+ end
29
+
30
+ describe '#present_as' do
31
+ it 'filters entity through presenter, and returns self' do
32
+ entity = Spectifly::Entity.parse(fixture_path('individual'))
33
+ presenter_entity = Spectifly::Entity.parse(fixture_path('presenters/positionless_individual'))
34
+ xsd_path = expectation_path('presented/positionless_individual', 'xsd')
35
+ builder = Spectifly::Xsd::Builder.new(entity)
36
+ builder.present_as(presenter_entity).should == builder
37
+ xsd = builder.build
38
+ xsd.should == File.read(xsd_path)
39
+ end
40
+
41
+ it 'works with presented relationship-having entities' do
42
+ entity = Spectifly::Entity.parse(fixture_path('group'))
43
+ presenter_entity = Spectifly::Entity.parse(fixture_path('presenters/masterless_group'))
44
+ xsd_path = expectation_path('presented/masterless_group', 'xsd')
45
+ builder = Spectifly::Xsd::Builder.new(entity)
46
+ builder.present_as(presenter_entity).should == builder
47
+ xsd = builder.build
48
+ xsd.should == File.read(xsd_path)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spectifly::Xsd::Field do
4
+ describe '#regex' do
5
+ it 'formats regex to xsd-compatible pattern restriction' do
6
+ field = Spectifly::Xsd::Field.new('some field', {
7
+ 'Validations' => 'Must match regex "^[0-9]{4}"'
8
+ })
9
+ field.regex.should == '[0-9]{4}[\s\S]*'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spectifly::Xsd::Types do
4
+ describe '.build_extended' do
5
+ it 'builds xsd for extended types' do
6
+ expected_path = expectation_path('extended', 'xsd')
7
+ expected = File.read(expected_path)
8
+ Spectifly::Xsd::Types.build_extended.should == expected
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ def spec_path
2
+ File.expand_path('..', File.dirname(__FILE__))
3
+ end
4
+
5
+ def base_fixture_path
6
+ File.join(spec_path, 'fixtures')
7
+ end
8
+
9
+ def base_presenter_path
10
+ File.join(base_fixture_path, 'presenters')
11
+ end
12
+
13
+ def base_expectation_path
14
+ File.join(spec_path, 'expectations')
15
+ end
16
+
17
+ def fixture_path(fixture = nil)
18
+ return base_fixture_path unless fixture
19
+ fixture.gsub!(/\.entity$/, '')
20
+ File.join(base_fixture_path, "#{fixture}.entity")
21
+ end
22
+
23
+ def expectation_path(expectation = nil, format = nil)
24
+ return base_expectation_path unless expectation
25
+ expectation, format_from_expectation = expectation.split('.')
26
+ format ||= format_from_expectation
27
+ File.join(base_expectation_path, "#{expectation}.#{format}")
28
+ end
data/spectifly.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spectifly/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spectifly"
8
+ spec.version = Spectifly::VERSION
9
+ spec.authors = ["Ravi Gadad"]
10
+ spec.email = ["ravi@renewfund.com"]
11
+ spec.description = %q{
12
+ A library for turning business entity specifications into several
13
+ different validatable formats, and creating fixture data for testing.
14
+ }
15
+ spec.summary = %q{Generate schema files from business entity YAML specs.}
16
+ spec.homepage = ""
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files`.split($/)
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "builder"
25
+ spec.add_dependency "json"
26
+ spec.add_dependency "rake"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.3"
29
+ spec.add_development_dependency "rake"
30
+ spec.add_development_dependency "rspec"
31
+ spec.add_development_dependency "simplecov"
32
+ end
metadata ADDED
@@ -0,0 +1,251 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spectifly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ravi Gadad
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: builder
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: simplecov
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: ! "\n A library for turning business entity specifications into several\n
127
+ \ different validatable formats, and creating fixture data for testing.\n "
128
+ email:
129
+ - ravi@renewfund.com
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - .ruby-version
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - lib/entities/association.entity
141
+ - lib/entities/entity.entity
142
+ - lib/entities/field.entity
143
+ - lib/entities/related_entity.entity
144
+ - lib/spectifly.rb
145
+ - lib/spectifly/base.rb
146
+ - lib/spectifly/base/association.rb
147
+ - lib/spectifly/base/builder.rb
148
+ - lib/spectifly/base/configuration.rb
149
+ - lib/spectifly/base/entity_node.rb
150
+ - lib/spectifly/base/field.rb
151
+ - lib/spectifly/base/types.rb
152
+ - lib/spectifly/configuration.rb
153
+ - lib/spectifly/entity.rb
154
+ - lib/spectifly/json.rb
155
+ - lib/spectifly/json/association.rb
156
+ - lib/spectifly/json/builder.rb
157
+ - lib/spectifly/json/field.rb
158
+ - lib/spectifly/json/types.rb
159
+ - lib/spectifly/support.rb
160
+ - lib/spectifly/tasks.rb
161
+ - lib/spectifly/version.rb
162
+ - lib/spectifly/xsd.rb
163
+ - lib/spectifly/xsd/association.rb
164
+ - lib/spectifly/xsd/builder.rb
165
+ - lib/spectifly/xsd/field.rb
166
+ - lib/spectifly/xsd/types.rb
167
+ - lib/tasks/spectifly.rake
168
+ - spec/expectations/extended.xsd
169
+ - spec/expectations/group.json
170
+ - spec/expectations/group.xsd
171
+ - spec/expectations/individual.json
172
+ - spec/expectations/individual.xsd
173
+ - spec/expectations/presented/masterless_group.json
174
+ - spec/expectations/presented/masterless_group.xsd
175
+ - spec/expectations/presented/positionless_individual.json
176
+ - spec/expectations/presented/positionless_individual.xsd
177
+ - spec/fixtures/group.entity
178
+ - spec/fixtures/individual.entity
179
+ - spec/fixtures/invalid/multiple_root.entity
180
+ - spec/fixtures/invalid/no_fields.entity
181
+ - spec/fixtures/presenters/masterless_group.entity
182
+ - spec/fixtures/presenters/positionless_individual.entity
183
+ - spec/spec_helper.rb
184
+ - spec/spectifly/base/builder_spec.rb
185
+ - spec/spectifly/base/entity_node_spec.rb
186
+ - spec/spectifly/base/field_spec.rb
187
+ - spec/spectifly/configuration_spec.rb
188
+ - spec/spectifly/entity_spec.rb
189
+ - spec/spectifly/json/builder_spec.rb
190
+ - spec/spectifly/json/field_spec.rb
191
+ - spec/spectifly/support_spec.rb
192
+ - spec/spectifly/xsd/builder_spec.rb
193
+ - spec/spectifly/xsd/field_spec.rb
194
+ - spec/spectifly/xsd/types_spec.rb
195
+ - spec/support/path_helper.rb
196
+ - spectifly.gemspec
197
+ homepage: ''
198
+ licenses:
199
+ - MIT
200
+ post_install_message:
201
+ rdoc_options: []
202
+ require_paths:
203
+ - lib
204
+ required_ruby_version: !ruby/object:Gem::Requirement
205
+ none: false
206
+ requirements:
207
+ - - ! '>='
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ required_rubygems_version: !ruby/object:Gem::Requirement
211
+ none: false
212
+ requirements:
213
+ - - ! '>='
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ requirements: []
217
+ rubyforge_project:
218
+ rubygems_version: 1.8.23
219
+ signing_key:
220
+ specification_version: 3
221
+ summary: Generate schema files from business entity YAML specs.
222
+ test_files:
223
+ - spec/expectations/extended.xsd
224
+ - spec/expectations/group.json
225
+ - spec/expectations/group.xsd
226
+ - spec/expectations/individual.json
227
+ - spec/expectations/individual.xsd
228
+ - spec/expectations/presented/masterless_group.json
229
+ - spec/expectations/presented/masterless_group.xsd
230
+ - spec/expectations/presented/positionless_individual.json
231
+ - spec/expectations/presented/positionless_individual.xsd
232
+ - spec/fixtures/group.entity
233
+ - spec/fixtures/individual.entity
234
+ - spec/fixtures/invalid/multiple_root.entity
235
+ - spec/fixtures/invalid/no_fields.entity
236
+ - spec/fixtures/presenters/masterless_group.entity
237
+ - spec/fixtures/presenters/positionless_individual.entity
238
+ - spec/spec_helper.rb
239
+ - spec/spectifly/base/builder_spec.rb
240
+ - spec/spectifly/base/entity_node_spec.rb
241
+ - spec/spectifly/base/field_spec.rb
242
+ - spec/spectifly/configuration_spec.rb
243
+ - spec/spectifly/entity_spec.rb
244
+ - spec/spectifly/json/builder_spec.rb
245
+ - spec/spectifly/json/field_spec.rb
246
+ - spec/spectifly/support_spec.rb
247
+ - spec/spectifly/xsd/builder_spec.rb
248
+ - spec/spectifly/xsd/field_spec.rb
249
+ - spec/spectifly/xsd/types_spec.rb
250
+ - spec/support/path_helper.rb
251
+ has_rdoc: