domain 0.0.1 → 1.0.0.rc1
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.
- data/README.md +75 -2
- data/domain.noespec +1 -1
- data/lib/domain.rb +7 -2
- data/lib/domain/api.rb +48 -0
- data/lib/domain/factory.rb +52 -0
- data/lib/domain/factory/reuse.rb +53 -0
- data/lib/domain/factory/sbyc.rb +9 -0
- data/lib/domain/factory/scalar.rb +30 -0
- data/lib/domain/factory/union.rb +11 -0
- data/lib/domain/support.rb +3 -0
- data/lib/domain/support/equalizer.rb +74 -0
- data/lib/domain/support/fake_domain.rb +38 -0
- data/lib/domain/support/impl_domain.rb +17 -0
- data/lib/domain/version.rb +2 -2
- data/spec/factory/reuse_domain/test_new.rb +26 -0
- data/spec/factory/reuse_domain/test_predicate.rb +10 -0
- data/spec/factory/reuse_domain/test_recoat.rb +22 -0
- data/spec/factory/reuse_domain/test_reuse.rb +20 -0
- data/spec/factory/reuse_domain/test_values.rb +11 -0
- data/spec/factory/sbyc_domain/test_new.rb +22 -0
- data/spec/factory/sbyc_domain/test_predicate.rb +10 -0
- data/spec/factory/sbyc_domain/test_sub_domains.rb +14 -0
- data/spec/factory/sbyc_domain/test_super_domain.rb +10 -0
- data/spec/factory/sbyc_domain/test_super_domain_of.rb +18 -0
- data/spec/factory/sbyc_domain/test_triple_equal.rb +23 -0
- data/spec/factory/scalar_domain/test_component_reader.rb +16 -0
- data/spec/factory/scalar_domain/test_hash.rb +14 -0
- data/spec/factory/scalar_domain/test_to_hash.rb +14 -0
- data/spec/factory/scalar_domain/test_values.rb +11 -0
- data/spec/factory/test_sbyc.rb +16 -0
- data/spec/factory/test_scalar.rb +14 -0
- data/spec/factory/test_union.rb +17 -0
- data/spec/factory/union_domain/test_new.rb +17 -0
- data/spec/factory/union_domain/test_predicate.rb +18 -0
- data/spec/factory/union_domain/test_sub_domains.rb +10 -0
- data/spec/factory/union_domain/test_super_domain.rb +10 -0
- data/spec/factory/union_domain/test_super_domain_of.rb +18 -0
- data/spec/factory/union_domain/test_triple_equal.rb +15 -0
- data/spec/fixtures/boolean.rb +3 -0
- data/spec/fixtures/list.rb +6 -0
- data/spec/fixtures/neg_int.rb +3 -0
- data/spec/fixtures/point.rb +3 -0
- data/spec/fixtures/tuple.rb +3 -0
- data/spec/shared/a_domain_class.rb +11 -0
- data/spec/shared/a_value_object.rb +58 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/equalizer/test_new.rb +37 -0
- data/spec/support/test_equalizer.rb +95 -0
- data/spec/test_fixtures.rb +21 -0
- metadata +82 -4
data/lib/domain/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe Reuse, "new" do
|
4
|
+
|
5
|
+
it 'returns an instance when correct reused instance' do
|
6
|
+
List.new([1, 2, 3]).should be_a(List)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns an instance when correct reused instance and valid predicate' do
|
10
|
+
Tuple.new(:foo => "bar").should be_a(Tuple)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'raises an ArgumentError when not correct reused instance' do
|
14
|
+
lambda{
|
15
|
+
List.new("foo")
|
16
|
+
}.should raise_error(ArgumentError)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'raises an ArgumentError when the predicate is not satisfied' do
|
20
|
+
lambda{
|
21
|
+
Tuple.new("foo" => :bar)
|
22
|
+
}.should raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe Reuse, "recoat" do
|
4
|
+
|
5
|
+
let(:object){ List.new([1, 2, 3]) }
|
6
|
+
|
7
|
+
describe "map" do
|
8
|
+
subject{ object.map{|x| x*2} }
|
9
|
+
|
10
|
+
it{ should be_a(List) }
|
11
|
+
it{ should eq(List.new([2, 4, 6])) }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "reject" do
|
15
|
+
subject{ object.reject{|x| x%2 == 0} }
|
16
|
+
|
17
|
+
it{ should be_a(List) }
|
18
|
+
it{ should eq(List.new([1, 3])) }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe Reuse, "reuse" do
|
4
|
+
|
5
|
+
let(:object){ List.new([1, 2, 3]) }
|
6
|
+
|
7
|
+
describe "size" do
|
8
|
+
subject{ object.size }
|
9
|
+
|
10
|
+
it{ should eq(3) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "empty?" do
|
14
|
+
subject{ object.empty? }
|
15
|
+
|
16
|
+
it{ should be_false }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe SByC, "new" do
|
4
|
+
|
5
|
+
it 'returns the value when it satisfies the predicate' do
|
6
|
+
NegInt.new(-12).should eq(-12)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'raises an argument error when the value does not satisfy the predicate' do
|
10
|
+
lambda{
|
11
|
+
NegInt.new(12)
|
12
|
+
}.should raise_error(ArgumentError)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'raises an argument error when the value is not a superclazz value' do
|
16
|
+
lambda{
|
17
|
+
NegInt.new("bla")
|
18
|
+
}.should raise_error(ArgumentError)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe SByC, "sub_domains" do
|
4
|
+
|
5
|
+
it 'returns the sub domains passed at construction' do
|
6
|
+
Boolean.sub_domains.should eq([TrueClass, FalseClass])
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'defaults an empty array' do
|
10
|
+
NegInt.sub_domains.should eq([])
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe SByC, "super_domain_of?" do
|
4
|
+
|
5
|
+
it 'returns true when a super domain' do
|
6
|
+
Boolean.should be_super_domain_of(TrueClass)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns false on itself' do
|
10
|
+
Boolean.should_not be_super_domain_of(Boolean)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns false when not a super domain' do
|
14
|
+
Boolean.should_not be_super_domain_of(Integer)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe SByC, "===" do
|
4
|
+
|
5
|
+
it 'returns true when a proper value' do
|
6
|
+
(Boolean === true).should be_true
|
7
|
+
(Boolean === false).should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns false when not a value' do
|
11
|
+
(Boolean === 1).should be_false
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns false when a superclass value that satisfies the predicate' do
|
15
|
+
(NegInt === -1).should be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns false when a superclass value that do not satisfy the predicate' do
|
19
|
+
(NegInt === 1).should be_false
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe Scalar, "component reader" do
|
4
|
+
|
5
|
+
let(:point){ Point.new(1, 2) }
|
6
|
+
|
7
|
+
it 'has a `x` reader' do
|
8
|
+
point.x.should eq(1)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'has a `y` reader' do
|
12
|
+
point.y.should eq(2)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Domain, "sbyc" do
|
3
|
+
|
4
|
+
subject{ Domain.sbyc(Integer){|i| i > 0} }
|
5
|
+
|
6
|
+
it_should_behave_like 'a domain class'
|
7
|
+
|
8
|
+
it 'should recognize positive integers' do
|
9
|
+
(subject === 10).should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should not recognize negative integers' do
|
13
|
+
(subject === -10).should be_false
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Domain, "scalar" do
|
3
|
+
|
4
|
+
subject{ Domain.scalar(:x, :y) }
|
5
|
+
|
6
|
+
it_should_behave_like 'a domain class'
|
7
|
+
|
8
|
+
it 'should create a class that accepts two components' do
|
9
|
+
point = subject.new(1, 2)
|
10
|
+
point.x.should eq(1)
|
11
|
+
point.y.should eq(2)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Domain, "union" do
|
3
|
+
|
4
|
+
subject{ Domain.union(TrueClass, FalseClass) }
|
5
|
+
|
6
|
+
it_should_behave_like 'a domain class'
|
7
|
+
|
8
|
+
it 'should recognize true and false' do
|
9
|
+
(subject === true).should be_true
|
10
|
+
(subject === false).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should not recognize non booleans' do
|
14
|
+
(subject === -10).should be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe Union, "new" do
|
4
|
+
|
5
|
+
it 'returns the value when it satisfies the predicate' do
|
6
|
+
Boolean.new(true).should be(true)
|
7
|
+
Boolean.new(false).should be(false)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'raises an argument error when the value is not a superclazz value' do
|
11
|
+
lambda{
|
12
|
+
Boolean.new("12")
|
13
|
+
}.should raise_error(ArgumentError)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe Union, "predicate" do
|
4
|
+
|
5
|
+
it 'returns a Proc' do
|
6
|
+
Boolean.predicate.should be_a(Proc)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'is satisfied when a valid value' do
|
10
|
+
Boolean.predicate.call(true).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'is not satisfied when an invalid value' do
|
14
|
+
Boolean.predicate.call("12").should be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe Union, "super_domain_of?" do
|
4
|
+
|
5
|
+
it 'returns true when a super domain' do
|
6
|
+
Boolean.should be_super_domain_of(TrueClass)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns false on itself' do
|
10
|
+
Boolean.should_not be_super_domain_of(Boolean)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns false when not a super domain' do
|
14
|
+
Boolean.should_not be_super_domain_of(Integer)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Domain
|
3
|
+
describe Union, "===" do
|
4
|
+
|
5
|
+
it 'returns true when a proper value' do
|
6
|
+
(Boolean === true).should be_true
|
7
|
+
(Boolean === false).should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns false when not a value' do
|
11
|
+
(Boolean === 1).should be_false
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|