contracts-lite 0.14.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/CHANGELOG.markdown +80 -0
- data/Gemfile +16 -0
- data/LICENSE +23 -0
- data/README.md +102 -0
- data/TODO.markdown +6 -0
- data/TUTORIAL.md +747 -0
- data/benchmarks/bench.rb +67 -0
- data/benchmarks/hash.rb +69 -0
- data/benchmarks/invariants.rb +91 -0
- data/benchmarks/io.rb +62 -0
- data/benchmarks/wrap_test.rb +57 -0
- data/contracts.gemspec +13 -0
- data/lib/contracts.rb +231 -0
- data/lib/contracts/builtin_contracts.rb +541 -0
- data/lib/contracts/call_with.rb +97 -0
- data/lib/contracts/core.rb +52 -0
- data/lib/contracts/decorators.rb +47 -0
- data/lib/contracts/engine.rb +26 -0
- data/lib/contracts/engine/base.rb +136 -0
- data/lib/contracts/engine/eigenclass.rb +50 -0
- data/lib/contracts/engine/target.rb +70 -0
- data/lib/contracts/error_formatter.rb +121 -0
- data/lib/contracts/errors.rb +71 -0
- data/lib/contracts/formatters.rb +134 -0
- data/lib/contracts/invariants.rb +68 -0
- data/lib/contracts/method_handler.rb +195 -0
- data/lib/contracts/method_reference.rb +100 -0
- data/lib/contracts/support.rb +59 -0
- data/lib/contracts/validators.rb +139 -0
- data/lib/contracts/version.rb +3 -0
- data/script/rubocop +7 -0
- data/spec/builtin_contracts_spec.rb +461 -0
- data/spec/contracts_spec.rb +748 -0
- data/spec/error_formatter_spec.rb +68 -0
- data/spec/fixtures/fixtures.rb +710 -0
- data/spec/invariants_spec.rb +17 -0
- data/spec/module_spec.rb +18 -0
- data/spec/override_validators_spec.rb +162 -0
- data/spec/ruby_version_specific/contracts_spec_1.9.rb +24 -0
- data/spec/ruby_version_specific/contracts_spec_2.0.rb +55 -0
- data/spec/ruby_version_specific/contracts_spec_2.1.rb +63 -0
- data/spec/spec_helper.rb +102 -0
- data/spec/support.rb +10 -0
- data/spec/support_spec.rb +21 -0
- data/spec/validators_spec.rb +47 -0
- metadata +94 -0
data/spec/support.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Contracts
|
2
|
+
RSpec.describe Support do
|
3
|
+
describe "eigenclass?" do
|
4
|
+
it "is falsey for non-singleton classes" do
|
5
|
+
expect(Contracts::Support.eigenclass? String).to be_falsey
|
6
|
+
end
|
7
|
+
|
8
|
+
it "is truthy for singleton classes" do
|
9
|
+
singleton_class = String.instance_exec { class << self; self; end }
|
10
|
+
expect(Contracts::Support.eigenclass? singleton_class).to be_truthy
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "eigenclass_of" do
|
15
|
+
it "returns the eigenclass of a given object" do
|
16
|
+
singleton_class = String.instance_exec { class << self; self; end }
|
17
|
+
expect(Contracts::Support.eigenclass_of String).to eq singleton_class
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Contract validators" do
|
4
|
+
subject(:o) { GenericExample.new }
|
5
|
+
|
6
|
+
describe "Range" do
|
7
|
+
it "passes when value is in range" do
|
8
|
+
expect do
|
9
|
+
o.method_with_range_contract(5)
|
10
|
+
end.not_to raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it "fails when value is not in range" do
|
14
|
+
expect do
|
15
|
+
o.method_with_range_contract(300)
|
16
|
+
end.to raise_error(ContractError, /Expected: 1\.\.10/)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "fails when value is incorrect" do
|
20
|
+
expect do
|
21
|
+
o.method_with_range_contract("hello world")
|
22
|
+
end.to raise_error(ContractError, /Expected: 1\.\.10.*Actual: "hello world"/m)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "Regexp" do
|
27
|
+
it "should pass for a matching string" do
|
28
|
+
expect { o.should_contain_foo("containing foo") }.to_not raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should fail for a non-matching string" do
|
32
|
+
expect { o.should_contain_foo("that's not F00") }.to raise_error(ContractError)
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "within a hash" do
|
36
|
+
it "should pass for a matching string" do
|
37
|
+
expect { o.hash_containing_foo(:host => "foo.example.org") }.to_not raise_error
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "within an array" do
|
42
|
+
it "should pass for a matching string" do
|
43
|
+
expect { o.array_containing_foo(["foo"]) }.to_not raise_error
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: contracts-lite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.14.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aditya Bhargava
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This library provides contracts for Ruby. Contracts let you clearly express
|
14
|
+
how your code behaves, and free you from writing tons of boilerplate, defensive
|
15
|
+
code.
|
16
|
+
email: bluemangroupie@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
22
|
+
- ".rspec"
|
23
|
+
- ".rubocop.yml"
|
24
|
+
- ".travis.yml"
|
25
|
+
- CHANGELOG.markdown
|
26
|
+
- Gemfile
|
27
|
+
- LICENSE
|
28
|
+
- README.md
|
29
|
+
- TODO.markdown
|
30
|
+
- TUTORIAL.md
|
31
|
+
- benchmarks/bench.rb
|
32
|
+
- benchmarks/hash.rb
|
33
|
+
- benchmarks/invariants.rb
|
34
|
+
- benchmarks/io.rb
|
35
|
+
- benchmarks/wrap_test.rb
|
36
|
+
- contracts.gemspec
|
37
|
+
- lib/contracts.rb
|
38
|
+
- lib/contracts/builtin_contracts.rb
|
39
|
+
- lib/contracts/call_with.rb
|
40
|
+
- lib/contracts/core.rb
|
41
|
+
- lib/contracts/decorators.rb
|
42
|
+
- lib/contracts/engine.rb
|
43
|
+
- lib/contracts/engine/base.rb
|
44
|
+
- lib/contracts/engine/eigenclass.rb
|
45
|
+
- lib/contracts/engine/target.rb
|
46
|
+
- lib/contracts/error_formatter.rb
|
47
|
+
- lib/contracts/errors.rb
|
48
|
+
- lib/contracts/formatters.rb
|
49
|
+
- lib/contracts/invariants.rb
|
50
|
+
- lib/contracts/method_handler.rb
|
51
|
+
- lib/contracts/method_reference.rb
|
52
|
+
- lib/contracts/support.rb
|
53
|
+
- lib/contracts/validators.rb
|
54
|
+
- lib/contracts/version.rb
|
55
|
+
- script/rubocop
|
56
|
+
- spec/builtin_contracts_spec.rb
|
57
|
+
- spec/contracts_spec.rb
|
58
|
+
- spec/error_formatter_spec.rb
|
59
|
+
- spec/fixtures/fixtures.rb
|
60
|
+
- spec/invariants_spec.rb
|
61
|
+
- spec/module_spec.rb
|
62
|
+
- spec/override_validators_spec.rb
|
63
|
+
- spec/ruby_version_specific/contracts_spec_1.9.rb
|
64
|
+
- spec/ruby_version_specific/contracts_spec_2.0.rb
|
65
|
+
- spec/ruby_version_specific/contracts_spec_2.1.rb
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
- spec/support.rb
|
68
|
+
- spec/support_spec.rb
|
69
|
+
- spec/validators_spec.rb
|
70
|
+
homepage: http://github.com/ddd-ruby/contracts.ruby
|
71
|
+
licenses:
|
72
|
+
- BSD-2-Clause
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.5.1
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Contracts for Ruby. (fork)
|
94
|
+
test_files: []
|