duckpond 1.1.1 → 1.1.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/duckpond/clause/method_clause.rb +32 -0
- data/lib/duckpond/clause.rb +19 -0
- data/lib/duckpond/contract.rb +2 -2
- data/lib/duckpond/inspection.rb +1 -1
- data/lib/duckpond/version.rb +1 -1
- data/lib/duckpond.rb +3 -0
- data/spec/clauses/method_clause_spec.rb +51 -0
- data/spec/contract_spec.rb +4 -4
- metadata +7 -5
- data/docs/.the_solution.txt.swp +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b810fdeab5df4f4ec189e29564679ca36a5def0
|
4
|
+
data.tar.gz: 2155f5a7e386b93b23b528681cf6e42434428372
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db69cd0d990921af13bc9f20074ccbe3cad89820b70a7337e32061a10c21adab8da60f5ae9d6d0956040a8f4454b6f71372f128123086314d965dc25a220d3a0
|
7
|
+
data.tar.gz: 9c388f4d94bb16176f8dcfe33def905b3df7a053bc4a537160130b2aed2c9bb3d26dc1b29d31c2aa06070efcea465295bb4b419a7a34f59cc52c03d0968f9064
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -65,8 +65,8 @@ Contracts can be combined into composite "super contracts" - contracts which are
|
|
65
65
|
various other contracts. This ties in with the reccomendation of preferring composition over inheritance:
|
66
66
|
|
67
67
|
class MyCompositeConrtact < DuckPond::Contract
|
68
|
-
|
69
|
-
|
68
|
+
include_clauses_from MyContract
|
69
|
+
include_clauses_from MyOtherContract
|
70
70
|
end
|
71
71
|
|
72
72
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# MethodClause
|
3
|
+
#
|
4
|
+
# Satisfied if the subject responds to the method represented
|
5
|
+
# by this clause.
|
6
|
+
#
|
7
|
+
module DuckPond
|
8
|
+
class MethodClause < Clause
|
9
|
+
|
10
|
+
attr_reader :method_name
|
11
|
+
|
12
|
+
#
|
13
|
+
# initialize
|
14
|
+
#
|
15
|
+
# Initialize method clauses with the method name as a symbol.
|
16
|
+
#
|
17
|
+
def initialize(method_name, opts = {})
|
18
|
+
@method_name = method_name
|
19
|
+
@options = opts
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# satisfied_by?
|
24
|
+
#
|
25
|
+
# A subject satisfies a method clause if it responds to that method.
|
26
|
+
#
|
27
|
+
def satisfied_by?(subject)
|
28
|
+
subject.respond_to? @method_name
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/duckpond/contract.rb
CHANGED
@@ -38,7 +38,7 @@ module DuckPond
|
|
38
38
|
# Adds a method expectation to the contract
|
39
39
|
#
|
40
40
|
def has_method(method_name)
|
41
|
-
clauses << method_name
|
41
|
+
clauses << MethodClause.new(method_name)
|
42
42
|
end
|
43
43
|
|
44
44
|
#
|
@@ -48,7 +48,7 @@ module DuckPond
|
|
48
48
|
#
|
49
49
|
def include_clauses_from(other_contract)
|
50
50
|
other_contract.each_clause do |other_clause|
|
51
|
-
has_method other_clause
|
51
|
+
has_method other_clause.method_name
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
data/lib/duckpond/inspection.rb
CHANGED
data/lib/duckpond/version.rb
CHANGED
data/lib/duckpond.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module DuckPond
|
4
|
+
describe MethodClause do
|
5
|
+
describe 'Class' do
|
6
|
+
it 'inherits from Clause' do
|
7
|
+
expect(described_class.ancestors).to include Clause
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'Constructor' do
|
12
|
+
context 'when passed a method name' do
|
13
|
+
it 'constructs a clause with that method name' do
|
14
|
+
expect(MethodClause.new(:foo).method_name).to eq :foo
|
15
|
+
end
|
16
|
+
end
|
17
|
+
context 'when passed a method name and some options' do
|
18
|
+
it 'constructs a clause with that method name and those options' do
|
19
|
+
clause = MethodClause.new(:foo, :my => :options)
|
20
|
+
expect(clause.method_name).to eq :foo
|
21
|
+
expect(clause.options[:my]).to eq :options
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'Instance Methods' do
|
27
|
+
|
28
|
+
describe '#method_name' do
|
29
|
+
it 'returns the method name the clause was constructed with' do
|
30
|
+
expect(MethodClause.new(:foo).method_name).to eq :foo
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#satisfied_by?' do
|
35
|
+
let(:clause) { MethodClause.new(:length) }
|
36
|
+
|
37
|
+
context 'when the subject responds to the clauses method' do
|
38
|
+
it 'returns true' do
|
39
|
+
expect(clause.satisfied_by? 'Hello').to eq true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
context 'when the subject responds to the clauses method' do
|
43
|
+
it 'returns false' do
|
44
|
+
expect(clause.satisfied_by? 42).to eq false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/spec/contract_spec.rb
CHANGED
@@ -12,7 +12,6 @@ module DuckPond
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
15
|
#
|
17
16
|
# see spec/classes/length_contract.rb
|
18
17
|
#
|
@@ -28,6 +27,7 @@ module DuckPond
|
|
28
27
|
end
|
29
28
|
end
|
30
29
|
end
|
30
|
+
|
31
31
|
describe 'fulfills!' do
|
32
32
|
context 'when the object is fulfilled by the contract' do
|
33
33
|
it 'returns true' do
|
@@ -45,7 +45,7 @@ module DuckPond
|
|
45
45
|
it 'returns the clauses for this contract' do
|
46
46
|
clauses = LengthContract.clauses
|
47
47
|
expect(clauses.length).to eq 1
|
48
|
-
expect(clauses).to include :length
|
48
|
+
expect(clauses.map(&:method_name)).to include :length
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -57,8 +57,8 @@ module DuckPond
|
|
57
57
|
it 'retains its parents quackings' do
|
58
58
|
clauses = CompositeContract.clauses
|
59
59
|
expect(clauses.length).to eq 2
|
60
|
-
expect(clauses).to include :length
|
61
|
-
expect(clauses).to include :chunky_bacon
|
60
|
+
expect(clauses.map(&:method_name)).to include :length
|
61
|
+
expect(clauses.map(&:method_name)).to include :chunky_bacon
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duckpond
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikey Hogarth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,16 +53,18 @@ files:
|
|
53
53
|
- LICENSE
|
54
54
|
- README.md
|
55
55
|
- Rakefile
|
56
|
-
- docs/.the_solution.txt.swp
|
57
56
|
- docs/the_problem.txt
|
58
57
|
- docs/the_solution.txt
|
59
58
|
- duckpond.gemspec
|
60
59
|
- lib/duckpond.rb
|
60
|
+
- lib/duckpond/clause.rb
|
61
|
+
- lib/duckpond/clause/method_clause.rb
|
61
62
|
- lib/duckpond/contract.rb
|
62
63
|
- lib/duckpond/inspection.rb
|
63
64
|
- lib/duckpond/version.rb
|
64
65
|
- spec/classes/contracts/composite_contract.rb
|
65
66
|
- spec/classes/contracts/length_contract.rb
|
67
|
+
- spec/clauses/method_clause_spec.rb
|
66
68
|
- spec/contract_spec.rb
|
67
69
|
- spec/inspection_spec.rb
|
68
70
|
- spec/spec_helper.rb
|
@@ -86,14 +88,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
88
|
version: '0'
|
87
89
|
requirements: []
|
88
90
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.
|
91
|
+
rubygems_version: 2.2.2
|
90
92
|
signing_key:
|
91
93
|
specification_version: 4
|
92
94
|
summary: Explicit duck-typing for ruby
|
93
95
|
test_files:
|
94
96
|
- spec/classes/contracts/composite_contract.rb
|
95
97
|
- spec/classes/contracts/length_contract.rb
|
98
|
+
- spec/clauses/method_clause_spec.rb
|
96
99
|
- spec/contract_spec.rb
|
97
100
|
- spec/inspection_spec.rb
|
98
101
|
- spec/spec_helper.rb
|
99
|
-
has_rdoc:
|
data/docs/.the_solution.txt.swp
DELETED
Binary file
|