lawyer 0.0.9 → 0.0.10
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/lawyer/clause.rb +1 -1
- data/lib/lawyer/rspec/contract_double.rb +13 -3
- data/lib/lawyer/version.rb +1 -1
- data/spec/lib/lawyer/rspec/contract_double_spec.rb +11 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3062b83c1c5bbeb21863262126a7afcb6e37ab07
|
4
|
+
data.tar.gz: 247c01b04f5697db94c50cd64a2330f3fad1df32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7eef40d9e8a151f0b100ccbff525e03e20ffdd319fe83d9e77687e6b8b2a1779a233734494904d1fa1f6b10bb861e724ffb762b450fe656229a8225f67430764
|
7
|
+
data.tar.gz: e32ac2b0b2ffba928301b813cae5c5586ec18abcfeb9e5b7e193d40a9565b25ea7d17878de30ef43510eae36698a293ea8dd97a92a679d80675d09da7c129040
|
data/lib/lawyer/clause.rb
CHANGED
@@ -2,7 +2,8 @@ module Lawyer
|
|
2
2
|
module RSpec
|
3
3
|
module ContractDouble
|
4
4
|
def contract_double(contract, return_values = {})
|
5
|
-
|
5
|
+
the_double = double(contract.name)
|
6
|
+
|
6
7
|
contract.clauses.each do |clause|
|
7
8
|
next if clause.name.to_sym == :initialize
|
8
9
|
|
@@ -11,9 +12,18 @@ module Lawyer
|
|
11
12
|
else
|
12
13
|
true
|
13
14
|
end
|
14
|
-
|
15
|
+
|
16
|
+
with = if clause.arity
|
17
|
+
clause.arity.times.map { anything }
|
18
|
+
elsif clause.signature
|
19
|
+
clause.signature.inject({}) { |acc, name| acc[name] = anything }
|
20
|
+
else
|
21
|
+
anything
|
22
|
+
end
|
23
|
+
|
24
|
+
allow(the_double).to receive(clause.name).with(with).and_return(return_value)
|
15
25
|
end
|
16
|
-
|
26
|
+
the_double
|
17
27
|
end
|
18
28
|
end
|
19
29
|
end
|
data/lib/lawyer/version.rb
CHANGED
@@ -2,14 +2,24 @@ require 'lawyer/rspec'
|
|
2
2
|
|
3
3
|
class DoublableContract < Lawyer::Contract
|
4
4
|
confirm :ping
|
5
|
+
confirm :arity => 2
|
6
|
+
confirm :named => [:arg]
|
5
7
|
end
|
6
8
|
|
7
9
|
describe Lawyer::RSpec::ContractDouble do
|
8
10
|
include Lawyer::RSpec::ContractDouble
|
9
11
|
|
10
|
-
subject { contract_double(DoublableContract) }
|
12
|
+
subject(:the_double) { contract_double(DoublableContract) }
|
11
13
|
|
12
14
|
it { should be_a(RSpec::Mocks::Mock) }
|
13
15
|
it { should respond_to(:ping) }
|
14
16
|
it { should_not respond_to(:pong) }
|
17
|
+
|
18
|
+
it "checks method arity" do
|
19
|
+
expect { the_double.arity(1) }.to raise_error(RSpec::Mocks::MockExpectationError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "checks named arguments" do
|
23
|
+
expect { the_double.named }.to raise_error(RSpec::Mocks::MockExpectationError)
|
24
|
+
end
|
15
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lawyer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Cinnamond
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|