duckpond 1.1.2 → 1.1.3
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/lib/duckpond/clause/method_clause.rb +3 -11
- data/lib/duckpond/clause.rb +5 -5
- data/lib/duckpond/contract.rb +13 -3
- data/lib/duckpond/version.rb +1 -1
- data/spec/clauses/method_clause_spec.rb +5 -17
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff44bdc5c03c542af79ff6a7a6c525ad67ca2b81
|
4
|
+
data.tar.gz: 8fda27a470b7ef9cd6744fa1a054a2bd96163b85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 338d11de6f3c7439d27c92937a150dcd6b2fb2346d556f874bad94a9609fd6cca31f2a6e08e6c6a1e39f35f11e3b9f41e8543d2dceb61af2ae66efa1b3621760
|
7
|
+
data.tar.gz: 5d6c89b8cdc59b2569a2816b422e2ea302ea7c2f70c08ae2229d8817081e44afd74938453a40f0cf26616d3d95da8a68b53b1157c03d9219d76f1c676b2916c0
|
@@ -7,16 +7,8 @@
|
|
7
7
|
module DuckPond
|
8
8
|
class MethodClause < Clause
|
9
9
|
|
10
|
-
|
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
|
10
|
+
def method_name
|
11
|
+
@options[:method_name]
|
20
12
|
end
|
21
13
|
|
22
14
|
#
|
@@ -25,7 +17,7 @@ module DuckPond
|
|
25
17
|
# A subject satisfies a method clause if it responds to that method.
|
26
18
|
#
|
27
19
|
def satisfied_by?(subject)
|
28
|
-
subject.respond_to?
|
20
|
+
subject.respond_to? method_name
|
29
21
|
end
|
30
22
|
|
31
23
|
end
|
data/lib/duckpond/clause.rb
CHANGED
data/lib/duckpond/contract.rb
CHANGED
@@ -32,13 +32,23 @@ module DuckPond
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
#
|
36
|
+
# has_clause
|
37
|
+
#
|
38
|
+
# add a clause to the contract's list of clauses
|
39
|
+
#
|
40
|
+
def has_clause(clause_klass, opts = {})
|
41
|
+
clauses << clause_klass.new(opts)
|
42
|
+
end
|
43
|
+
|
44
|
+
|
35
45
|
#
|
36
46
|
# has_method
|
37
47
|
#
|
38
|
-
# Adds a method
|
48
|
+
# Adds a method clause to the contract
|
39
49
|
#
|
40
|
-
def has_method(method_name)
|
41
|
-
|
50
|
+
def has_method(method_name, opts = {})
|
51
|
+
has_clause MethodClause, opts.merge(:method_name => method_name)
|
42
52
|
end
|
43
53
|
|
44
54
|
#
|
data/lib/duckpond/version.rb
CHANGED
@@ -9,30 +9,18 @@ module DuckPond
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe 'Constructor' do
|
12
|
-
context 'when
|
13
|
-
it '
|
14
|
-
|
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)
|
12
|
+
context 'when constructed with a method name option' do
|
13
|
+
it 'adds that method name as an attribute' do
|
14
|
+
clause = MethodClause.new(:method_name => :foo)
|
20
15
|
expect(clause.method_name).to eq :foo
|
21
|
-
expect(clause.options[:my]).to eq :options
|
22
16
|
end
|
23
17
|
end
|
24
18
|
end
|
25
19
|
|
26
20
|
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
|
-
|
21
|
+
|
34
22
|
describe '#satisfied_by?' do
|
35
|
-
let(:clause) { MethodClause.new(:length) }
|
23
|
+
let(:clause) { MethodClause.new(:method_name => :length) }
|
36
24
|
|
37
25
|
context 'when the subject responds to the clauses method' do
|
38
26
|
it 'returns true' do
|