duckpond 1.1.3 → 1.1.4
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 +18 -0
- data/lib/duckpond/clause/method_clause.rb +19 -1
- data/lib/duckpond/version.rb +1 -1
- data/spec/contract_spec.rb +11 -0
- data/spec/spec_helper.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b28a479d7cc232dbbd474d545caece0c5927ff8
|
4
|
+
data.tar.gz: ffd5f52ff703529d2c96ae47c680d85ab0367bde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ac93596986601000969400607f1cc2b2f57b78c0e539848a3df6f6cd55fbf11d5f170328a5b7daebf6493c37a27fc5b408f3f416d314b7d9e20df16ffa8ef71
|
7
|
+
data.tar.gz: 8af2817b6a54bd9954fc9b93a965b4699166ef898198283117e74b738d4291b873e48d2b84953aa49fe34681fe9a70bbb10eca9dca38e9e4d9e7c671533d2551
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -69,6 +69,24 @@ various other contracts. This ties in with the reccomendation of preferring comp
|
|
69
69
|
include_clauses_from MyOtherContract
|
70
70
|
end
|
71
71
|
|
72
|
+
Another feature of duckpond is the ability to specify what your expected result from a contract should be. For example,
|
73
|
+
the following contract expects a subject to have a method called "even" and for that method, when called, to return a
|
74
|
+
true value:
|
75
|
+
|
76
|
+
class MyEvenContract < DuckPond::Contract
|
77
|
+
has_method :even?, responds_with: true
|
78
|
+
end
|
79
|
+
|
80
|
+
If the method needs args, you can specify those too. This next contract will pass the string "Hell" to the #include? method,
|
81
|
+
and expect the value to be true. This contract will therefore be satisfied by strings containing the word "Hell" that are
|
82
|
+
five characters long (such as the word "Hello"):
|
83
|
+
|
84
|
+
class MyHellContract < DuckPond::Contract
|
85
|
+
has_method :include?, responds_with: true, given_args: "Hell"
|
86
|
+
has_method :length, responds_with: 5
|
87
|
+
end
|
88
|
+
|
89
|
+
Note: The method will only be *called* if you use the :reponds_with option. Otherwise, it just tests for the method's existence.
|
72
90
|
|
73
91
|
In the real world, a contract might look like this:
|
74
92
|
|
@@ -17,7 +17,25 @@ module DuckPond
|
|
17
17
|
# A subject satisfies a method clause if it responds to that method.
|
18
18
|
#
|
19
19
|
def satisfied_by?(subject)
|
20
|
-
|
20
|
+
|
21
|
+
# Check the method actually exists.
|
22
|
+
return false unless subject.respond_to? method_name
|
23
|
+
|
24
|
+
# If required, check the response from the method was what the user expected.
|
25
|
+
return false unless _responds_with?(subject, method_name, @options[:responds_with], @options[:given_args])
|
26
|
+
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
#
|
32
|
+
# _responds_with?
|
33
|
+
#
|
34
|
+
# if a method response expectation was passed in, this just calls the method (with the arguments
|
35
|
+
# if given) and does an == compare with the subject.
|
36
|
+
#
|
37
|
+
def _responds_with?(subject, method, expected_result, args = [])
|
38
|
+
return expected_result ? subject.send(method_name, *args) == expected_result : true
|
21
39
|
end
|
22
40
|
|
23
41
|
end
|
data/lib/duckpond/version.rb
CHANGED
data/spec/contract_spec.rb
CHANGED
@@ -50,6 +50,17 @@ module DuckPond
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
#
|
54
|
+
# see spec/classes/specific_length_contract.rb
|
55
|
+
#
|
56
|
+
describe SpecificLenghtContract do
|
57
|
+
it 'checks a methods response is correct' do
|
58
|
+
expect(SpecificLenghtContract.fulfills?("Hello")).to eq true
|
59
|
+
expect(SpecificLenghtContract.fulfills?("Yello")).to eq false
|
60
|
+
expect(SpecificLenghtContract.fulfills?("Goodbye")).to eq false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
53
64
|
#
|
54
65
|
# See spec/classes/composite_contract.rb
|
55
66
|
#
|
data/spec/spec_helper.rb
CHANGED
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.4
|
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-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
90
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.
|
91
|
+
rubygems_version: 2.1.10
|
92
92
|
signing_key:
|
93
93
|
specification_version: 4
|
94
94
|
summary: Explicit duck-typing for ruby
|
@@ -99,3 +99,4 @@ test_files:
|
|
99
99
|
- spec/contract_spec.rb
|
100
100
|
- spec/inspection_spec.rb
|
101
101
|
- spec/spec_helper.rb
|
102
|
+
has_rdoc:
|