json-spec 0.1.0
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 +7 -0
- data/.gitignore +3 -0
- data/.gitmodules +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +960 -0
- data/Rakefile +10 -0
- data/api_documentation.md +611 -0
- data/cachivache/.gitignore +1 -0
- data/cachivache/Gemfile +4 -0
- data/cachivache/README.md +247 -0
- data/cachivache/Rakefile +19 -0
- data/cachivache/Vagrantfile +70 -0
- data/cachivache/cachivache.rb +59 -0
- data/cachivache/lib/let-behaviour.rb +27 -0
- data/cachivache/lib/rake-helper.rb +131 -0
- data/cachivache/lib/sh-file-context.rb +39 -0
- data/cachivache/lib/sh-if-context.rb +31 -0
- data/cachivache/stuff/.gitkeep +0 -0
- data/cachivache/stuff/ruby-json-spec.rb +22 -0
- data/examples/example-1-simple.rb +66 -0
- data/examples/example-2-default-expectations.rb +63 -0
- data/examples/example-3-each-field.rb +104 -0
- data/examples/example-4-to-be-as-defined-in.rb +117 -0
- data/examples/example-5-custom-expectations.rb +153 -0
- data/examples/example-6-custom-messages.rb +36 -0
- data/examples/example-7-full-example.rb +231 -0
- data/examples/fixtures.rb +77 -0
- data/examples/validation-printer.rb +47 -0
- data/json-spec.gemspec +29 -0
- data/lib/cabeza-de-termo/json-spec/errors/error.rb +6 -0
- data/lib/cabeza-de-termo/json-spec/errors/expectation-not-found-error.rb +8 -0
- data/lib/cabeza-de-termo/json-spec/errors/modifier-not-found-error.rb +8 -0
- data/lib/cabeza-de-termo/json-spec/errors/unkown-json-type-error.rb +8 -0
- data/lib/cabeza-de-termo/json-spec/errors/validation-error.rb +8 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/default-expectations/default-expectation-builder.rb +29 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/default-expectations/default-expectations-mapping.rb +54 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/block-expectation-definition.rb +16 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/class-expectation-definition.rb +15 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectation-definition.rb +19 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb +136 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expecting-all-of-expectation-definition.rb +23 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expecting-any-of-expectation-definition.rb +23 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expecting-expectation-definition.rb +17 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/negating-expectation-definition.rb +16 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-library-definition-builder.rb +35 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/modifier-builders/class-modifier-definition.rb +15 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/modifier-builders/composing-modifiers-definition.rb +28 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/modifier-builders/modifier-definition.rb +13 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/modifier-builders/modifiers-definition-builder.rb +73 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb +150 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/initializers/default-library-initializer.rb +265 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/initializers/library-initializer.rb +9 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/messages/expectation-messages-mapping.rb +27 -0
- data/lib/cabeza-de-termo/json-spec/expectations/abstract-expectation.rb +39 -0
- data/lib/cabeza-de-termo/json-spec/expectations/all-expectations-composite.rb +33 -0
- data/lib/cabeza-de-termo/json-spec/expectations/any-expectation-composite.rb +33 -0
- data/lib/cabeza-de-termo/json-spec/expectations/block-expectation.rb +28 -0
- data/lib/cabeza-de-termo/json-spec/expectations/expectation.rb +51 -0
- data/lib/cabeza-de-termo/json-spec/expectations/is-email-expectation.rb +16 -0
- data/lib/cabeza-de-termo/json-spec/expectations/is-scalar-expectation.rb +17 -0
- data/lib/cabeza-de-termo/json-spec/expectations/is-url-expectation.rb +21 -0
- data/lib/cabeza-de-termo/json-spec/expectations/negated-expectation.rb +31 -0
- data/lib/cabeza-de-termo/json-spec/expectations/runner/abstract-expectations-runner.rb +27 -0
- data/lib/cabeza-de-termo/json-spec/expectations/runner/can-be-absent-expectations-runner.rb +50 -0
- data/lib/cabeza-de-termo/json-spec/expectations/runner/can-be-null-expectations-runner.rb +48 -0
- data/lib/cabeza-de-termo/json-spec/expectations/runner/expectations-runner.rb +43 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-any-of.rb +62 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-anything.rb +16 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-each-field.rb +58 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-each.rb +58 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-expression.rb +314 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-field-name.rb +16 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-field.rb +76 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-list.rb +40 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-object.rb +82 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-scalar.rb +20 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-spec.rb +174 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/abstract-instantiator.rb +9 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/all-expectations-composite-instantiator.rb +12 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/any-expectation-composite-instantiator.rb +12 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/block-expectation-instantiator.rb +16 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/composite-instantiator.rb +45 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/modifier-composite-instantiator.rb +12 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/negated-expectation-instantiator.rb +20 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/patial-application-instantiator.rb +26 -0
- data/lib/cabeza-de-termo/json-spec/json-spec.rb +2 -0
- data/lib/cabeza-de-termo/json-spec/message-formatters/block-message-formatter.rb +15 -0
- data/lib/cabeza-de-termo/json-spec/message-formatters/erb-message-formatter.rb +60 -0
- data/lib/cabeza-de-termo/json-spec/message-formatters/message-formatter.rb +9 -0
- data/lib/cabeza-de-termo/json-spec/metaprogramming/message-send.rb +37 -0
- data/lib/cabeza-de-termo/json-spec/metaprogramming/message.rb +37 -0
- data/lib/cabeza-de-termo/json-spec/metaprogramming/object-method.rb +14 -0
- data/lib/cabeza-de-termo/json-spec/modifiers/can-be-absent-modifier.rb +13 -0
- data/lib/cabeza-de-termo/json-spec/modifiers/can-be-null-modifier.rb +13 -0
- data/lib/cabeza-de-termo/json-spec/modifiers/expression-modifier.rb +9 -0
- data/lib/cabeza-de-termo/json-spec/modifiers/modifier-composite.rb +27 -0
- data/lib/cabeza-de-termo/json-spec/signals/signal.rb +6 -0
- data/lib/cabeza-de-termo/json-spec/signals/skip-branch-signal.rb +8 -0
- data/lib/cabeza-de-termo/json-spec/utilities/bind.rb +20 -0
- data/lib/cabeza-de-termo/json-spec/utilities/range.rb +70 -0
- data/lib/cabeza-de-termo/json-spec/value-holders/accessors-chain.rb +27 -0
- data/lib/cabeza-de-termo/json-spec/value-holders/missing-value.rb +21 -0
- data/lib/cabeza-de-termo/json-spec/value-holders/value-holder.rb +135 -0
- data/lib/cabeza-de-termo/json-spec/version.rb +5 -0
- data/lib/cabeza-de-termo/json-spec/walkers/expression-walker.rb +66 -0
- data/lib/cabeza-de-termo/json-spec/walkers/json-expectations-runner.rb +214 -0
- data/lib/cabeza-de-termo/json-spec/walkers/json-expression-explainer.rb +183 -0
- data/lib/cabeza-de-termo/json-spec/walkers/reporter/expectation-report.rb +63 -0
- data/lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb +111 -0
- data/lib/cabeza-de-termo/json-spec/walkers/validator/json-validator-error.rb +29 -0
- data/lib/cabeza-de-termo/json-spec/walkers/validator/json-validator.rb +133 -0
- data/lib/cabeza-de-termo/json-spec/walkers/value-holders-stack-behaviour.rb +57 -0
- metadata +242 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class ShFileContext
|
|
2
|
+
def self.with(args, &block)
|
|
3
|
+
new(args).evaluate_with block
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def initialize(args)
|
|
7
|
+
@filename = args[:file]
|
|
8
|
+
@text = ''
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def text
|
|
12
|
+
@text
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def evaluate_with(block)
|
|
16
|
+
instance_eval(&block)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def <<(string)
|
|
20
|
+
text << "\n" unless @text.empty?
|
|
21
|
+
text << string
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# replace pattern: "user: ''", with: "user: 'admin'"
|
|
25
|
+
def replace(params)
|
|
26
|
+
pattern = params[:pattern]
|
|
27
|
+
replacement = params[:with]
|
|
28
|
+
self << %Q{sudo sed -i 's|#{pattern}|#{replacement}|g' #{@filename}}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# append '[mongo]'
|
|
32
|
+
def append(text)
|
|
33
|
+
self << %Q{echo "#{text}" | sudo tee -a #{@filename}}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def append_new_line
|
|
37
|
+
append "\n"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
class ShIfContext
|
|
2
|
+
def self.with(args, &block)
|
|
3
|
+
new(args).evaluate_with block
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def initialize(args)
|
|
7
|
+
@guard = args[:guard]
|
|
8
|
+
@text = ''
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def text
|
|
12
|
+
@text
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def evaluate_with(block)
|
|
16
|
+
self << "if #{@guard}; then"
|
|
17
|
+
|
|
18
|
+
instance_eval(&block)
|
|
19
|
+
|
|
20
|
+
self << "fi"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def sh(string)
|
|
24
|
+
self << string
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def <<(string)
|
|
28
|
+
text << "\n" unless @text.empty?
|
|
29
|
+
text << string
|
|
30
|
+
end
|
|
31
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
dependencies = [
|
|
2
|
+
:git,
|
|
3
|
+
:ruby
|
|
4
|
+
]
|
|
5
|
+
|
|
6
|
+
namespace :'stuff' do
|
|
7
|
+
desc 'Install ruby-json-spec'
|
|
8
|
+
task :'ruby-json-spec' => dependencies do
|
|
9
|
+
sh %Q{
|
|
10
|
+
cd #{RubyJsonSpec.project_folder}
|
|
11
|
+
|
|
12
|
+
bundle install
|
|
13
|
+
rake test
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class RubyJsonSpec
|
|
19
|
+
include LetBehaviour
|
|
20
|
+
|
|
21
|
+
let(:project_folder) { Cachivache.src_folder }
|
|
22
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require 'cabeza-de-termo/json-spec/json-spec'
|
|
2
|
+
require_relative 'fixtures'
|
|
3
|
+
|
|
4
|
+
# To run this example do
|
|
5
|
+
# ruby -I lib examples/example-1-simple.rb
|
|
6
|
+
#
|
|
7
|
+
class Example_1_Simple
|
|
8
|
+
def self.run()
|
|
9
|
+
self.new.run
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def run()
|
|
13
|
+
valid_licenses =
|
|
14
|
+
['Apache-2.0', 'BSD-2-Clause', 'BSD-3-Clause',
|
|
15
|
+
'BSD-4-Clause' ,'GPL-2.0', 'GPL-2.0+', 'GPL-3.0',
|
|
16
|
+
'GPL-3.0+', 'LGPL-2.1', 'LGPL-2.1+', 'LGPL-3.0',
|
|
17
|
+
'LGPL-3.0+', 'MIT']
|
|
18
|
+
|
|
19
|
+
json_spec = CabezaDeTermo::JsonSpec::JsonSpec.new do
|
|
20
|
+
expect_an(:object) do
|
|
21
|
+
expect('name') .to_be_defined .not_blank
|
|
22
|
+
expect('type') .to_be_defined .not_blank
|
|
23
|
+
expect('description') .to_be_defined .not_blank
|
|
24
|
+
expect('keywords') .to_be_a(:list) .can_be_absent .not_empty do
|
|
25
|
+
each do
|
|
26
|
+
expect_a(:scalar) .not_blank
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
expect('homepage') .to_be_url
|
|
30
|
+
expect('license') .to_be_defined .to_be_in(valid_licenses)
|
|
31
|
+
expect('authors') .to_be_a(:list) .to_be_defined .not_empty do
|
|
32
|
+
each do
|
|
33
|
+
expect_an(:object) do
|
|
34
|
+
expect('name') .to_be_defined .not_blank
|
|
35
|
+
expect('email') .to_be_defined .to_be_email
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
expect('require') .to_be_an(:object) .can_be_absent
|
|
40
|
+
expect('require-dev') .to_be_an(:object) .can_be_absent
|
|
41
|
+
expect('autoload') .to_be_an(:object) .to_be_defined do
|
|
42
|
+
expect('psr-0') .to_be_an(:object) .can_be_absent
|
|
43
|
+
expect('psr-4') .to_be_an(:object) .can_be_absent
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
validator = json_spec.validate_string(Fixtures.named :simple)
|
|
49
|
+
|
|
50
|
+
puts "- Failed expectations: #{validator.errors_count}\n"
|
|
51
|
+
validator.errors.each do |error|
|
|
52
|
+
puts "\tField: '#{error.accessors_chain}'\t message: \"#{error.message}\"\n"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
puts "\n"
|
|
56
|
+
|
|
57
|
+
puts "- Unexpected fields: #{validator.unexpected_fields_count}\n"
|
|
58
|
+
validator.unexpected_fields.each do |error|
|
|
59
|
+
puts "\tField: '#{error.accessors_chain}'\t message: \"#{error.message}\"\n"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
puts "\n"
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
Example_1_Simple.run
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'cabeza-de-termo/json-spec/json-spec'
|
|
2
|
+
require_relative 'fixtures'
|
|
3
|
+
require_relative 'validation-printer'
|
|
4
|
+
|
|
5
|
+
# To run this example do
|
|
6
|
+
# ruby -I lib examples/example-2-default-expectations.rb
|
|
7
|
+
#
|
|
8
|
+
class Example_2_DefaultExpectations
|
|
9
|
+
def self.run()
|
|
10
|
+
self.new.run
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def run()
|
|
14
|
+
CabezaDeTermo::JsonSpec::ExpectationsLibrary.define do
|
|
15
|
+
default_expectations do
|
|
16
|
+
for_every_field do
|
|
17
|
+
to_be_defined
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
valid_licenses =
|
|
23
|
+
['Apache-2.0', 'BSD-2-Clause', 'BSD-3-Clause',
|
|
24
|
+
'BSD-4-Clause' ,'GPL-2.0', 'GPL-2.0+', 'GPL-3.0',
|
|
25
|
+
'GPL-3.0+', 'LGPL-2.1', 'LGPL-2.1+', 'LGPL-3.0',
|
|
26
|
+
'LGPL-3.0+', 'MIT']
|
|
27
|
+
|
|
28
|
+
json_spec = CabezaDeTermo::JsonSpec::JsonSpec.new do
|
|
29
|
+
expect_an(:object) do
|
|
30
|
+
expect('name') .not_blank
|
|
31
|
+
expect('type') .not_blank
|
|
32
|
+
expect('description') .not_blank
|
|
33
|
+
expect('keywords') .to_be_a(:list) .can_be_absent .not_empty do
|
|
34
|
+
each do
|
|
35
|
+
expect(:scalar) .not_blank
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
expect('homepage') .to_be_url
|
|
39
|
+
expect('license') .to_be_in(valid_licenses)
|
|
40
|
+
expect('authors') .to_be_a(:list) .not_empty do
|
|
41
|
+
each do
|
|
42
|
+
expect_an(:object) do
|
|
43
|
+
expect('name') .not_blank
|
|
44
|
+
expect('email') .to_be_email
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
expect('require') .to_be_an(:object) .can_be_absent
|
|
49
|
+
expect('require-dev') .to_be_an(:object) .can_be_absent
|
|
50
|
+
expect('autoload') .to_be_an(:object) do
|
|
51
|
+
expect('psr-0') .to_be_an(:object) .can_be_absent
|
|
52
|
+
expect('psr-4') .to_be_an(:object) .can_be_absent
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
validator = json_spec.validate_string(Fixtures.named :simple)
|
|
58
|
+
|
|
59
|
+
ValidationPrinter.new.print_report_of validator
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
Example_2_DefaultExpectations.run
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require 'cabeza-de-termo/json-spec/json-spec'
|
|
2
|
+
require_relative 'fixtures'
|
|
3
|
+
require_relative 'validation-printer'
|
|
4
|
+
|
|
5
|
+
# To run this example do
|
|
6
|
+
# ruby -I lib examples/example-3-each-field.rb
|
|
7
|
+
#
|
|
8
|
+
class Example_3_EachField
|
|
9
|
+
def self.run()
|
|
10
|
+
self.new.run
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def run()
|
|
14
|
+
valid_licenses =
|
|
15
|
+
['Apache-2.0', 'BSD-2-Clause', 'BSD-3-Clause',
|
|
16
|
+
'BSD-4-Clause' ,'GPL-2.0', 'GPL-2.0+', 'GPL-3.0',
|
|
17
|
+
'GPL-3.0+', 'LGPL-2.1', 'LGPL-2.1+', 'LGPL-3.0',
|
|
18
|
+
'LGPL-3.0+', 'MIT']
|
|
19
|
+
|
|
20
|
+
CabezaDeTermo::JsonSpec::ExpectationsLibrary.define do
|
|
21
|
+
default_expectations do
|
|
22
|
+
for_every_field do
|
|
23
|
+
to_be_defined
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
json_spec = CabezaDeTermo::JsonSpec::JsonSpec.new do
|
|
29
|
+
expect_an(:object) do
|
|
30
|
+
expect('name') .not_blank
|
|
31
|
+
expect('type') .not_blank
|
|
32
|
+
expect('description') .not_blank
|
|
33
|
+
|
|
34
|
+
expect('keywords') .to_be_a(:list) .can_be_absent .not_empty do
|
|
35
|
+
each do
|
|
36
|
+
expect_a(:scalar) .not_blank
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
expect('homepage') .to_be_url
|
|
41
|
+
expect('license') .to_be_in(valid_licenses)
|
|
42
|
+
|
|
43
|
+
expect('authors') .to_be_a(:list) .not_empty do
|
|
44
|
+
each do
|
|
45
|
+
expect_an(:object) do
|
|
46
|
+
expect('name') .not_blank
|
|
47
|
+
expect('email') .to_be_email
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
expect('require') .to_be_an(:object) .can_be_absent do
|
|
53
|
+
each_field do
|
|
54
|
+
expect_name .not_blank
|
|
55
|
+
expect_a(:scalar) .not_blank
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
expect('require-dev') .to_be_an(:object) .can_be_absent do
|
|
60
|
+
each_field do
|
|
61
|
+
expect_name.not_blank
|
|
62
|
+
expect_a(:scalar) .not_blank
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
expect('autoload') .to_be_an(:object) do
|
|
67
|
+
expect('psr-0') .to_be_an(:object) .can_be_absent do
|
|
68
|
+
each_field do
|
|
69
|
+
expect_name
|
|
70
|
+
|
|
71
|
+
expect_a(:list) .not_empty do
|
|
72
|
+
each do
|
|
73
|
+
expect_a(:scalar) .not_blank
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
expect('psr-4') .to_be_an(:object) .can_be_absent do
|
|
80
|
+
each_field do
|
|
81
|
+
expect_name
|
|
82
|
+
|
|
83
|
+
expect_a(:list) .not_empty do
|
|
84
|
+
each do
|
|
85
|
+
expect_a(:scalar) .not_blank
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
expect('classmap') .to_be_a(:list) .can_be_absent
|
|
92
|
+
|
|
93
|
+
expect('files') .to_be_a(:list) .can_be_absent
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
validator = json_spec.validate_string(Fixtures::named :simple)
|
|
99
|
+
|
|
100
|
+
ValidationPrinter.new.print_report_of validator
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
Example_3_EachField::run
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
require 'cabeza-de-termo/json-spec/json-spec'
|
|
2
|
+
require_relative 'fixtures'
|
|
3
|
+
require_relative 'validation-printer'
|
|
4
|
+
|
|
5
|
+
# To run self example do
|
|
6
|
+
# ruby -I lib examples/example-4-to-be-as-defined-in.rb
|
|
7
|
+
#
|
|
8
|
+
class Example_4_ToBeAsDefinedIn
|
|
9
|
+
def self.run()
|
|
10
|
+
self.new.run
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def run()
|
|
14
|
+
CabezaDeTermo::JsonSpec::ExpectationsLibrary.define do
|
|
15
|
+
default_expectations do
|
|
16
|
+
for_every_field do
|
|
17
|
+
to_be_defined
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
validator = ComposerJson.new.spec.validate_string(Fixtures.named :simple)
|
|
23
|
+
|
|
24
|
+
ValidationPrinter.new.print_report_of validator
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class ComposerJson
|
|
29
|
+
def spec()
|
|
30
|
+
CabezaDeTermo::JsonSpec::JsonSpec.new do |json_spec|
|
|
31
|
+
json_spec.expect_an(:object) do |object|
|
|
32
|
+
object.expect('name') .not_blank
|
|
33
|
+
object.expect('type') .not_blank
|
|
34
|
+
object.expect('description') .not_blank
|
|
35
|
+
object.expect('keywords') .to_be_as_defined_in(self, :keywords_spec)
|
|
36
|
+
object.expect('homepage').to_be_url
|
|
37
|
+
object.expect('license') .to_be_in(self.valid_licenses)
|
|
38
|
+
object.expect('authors') .to_be_as_defined_in(self, :authors_spec)
|
|
39
|
+
object.expect('require') .to_be_as_defined_in(self, :require_spec)
|
|
40
|
+
object.expect('require-dev') .to_be_as_defined_in(self, :require_spec)
|
|
41
|
+
object.expect('autoload') .to_be_as_defined_in(self, :autoload_spec)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def keywords_spec(json_spec)
|
|
47
|
+
json_spec .to_be_a(:list) .can_be_absent .not_empty do
|
|
48
|
+
each do
|
|
49
|
+
expect_a(:scalar) .not_blank
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def authors_spec(json_spec)
|
|
55
|
+
json_spec .to_be_a(:list) .not_empty do |list|
|
|
56
|
+
list.each do |each|
|
|
57
|
+
each.to_be_as_defined_in(self, :author_spec)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def author_spec(json_spec)
|
|
63
|
+
json_spec .expect_an(:object) do
|
|
64
|
+
expect('name') .not_blank
|
|
65
|
+
expect('email') .to_be_email
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def require_spec(json)
|
|
70
|
+
json .to_be_an(:object) .can_be_absent do
|
|
71
|
+
each_field do
|
|
72
|
+
expect_name .not_blank
|
|
73
|
+
expect_a(:scalar) .not_blank
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def autoload_spec(json)
|
|
79
|
+
json .to_be_an(:object) do |object|
|
|
80
|
+
object.expect('psr-0') .to_be_as_defined_in(self, :psr_spec)
|
|
81
|
+
object.expect('psr-4') .to_be_as_defined_in(self, :psr_spec)
|
|
82
|
+
object.expect('classmap') .to_be_as_defined_in(self, :classmaps_spec)
|
|
83
|
+
object.expect('files') .to_be_as_defined_in(self, :files_spec)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def psr_spec(json_spec)
|
|
88
|
+
json_spec .to_be_an(:object) .can_be_absent do
|
|
89
|
+
each_field do
|
|
90
|
+
expect_name
|
|
91
|
+
|
|
92
|
+
expect_a(:list) .not_empty do
|
|
93
|
+
each do
|
|
94
|
+
expect_a(:scalar) .not_blank
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def classmaps_spec(json_spec)
|
|
102
|
+
json_spec .to_be_a(:list) .can_be_absent .not_empty
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def files_spec(json_spec)
|
|
106
|
+
json_spec .to_be_a(:list) .can_be_absent .not_empty
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def valid_licenses()
|
|
110
|
+
['Apache-2.0', 'BSD-2-Clause', 'BSD-3-Clause',
|
|
111
|
+
'BSD-4-Clause' ,'GPL-2.0', 'GPL-2.0+', 'GPL-3.0',
|
|
112
|
+
'GPL-3.0+', 'LGPL-2.1', 'LGPL-2.1+', 'LGPL-3.0',
|
|
113
|
+
'LGPL-3.0+', 'MIT']
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
Example_4_ToBeAsDefinedIn::run
|