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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4dbbfd3ee37e37672ccc73e5ef501e88db69321
4
- data.tar.gz: ec171d5980b1301545ebf03eda89fcdb6e294199
3
+ metadata.gz: 3062b83c1c5bbeb21863262126a7afcb6e37ab07
4
+ data.tar.gz: 247c01b04f5697db94c50cd64a2330f3fad1df32
5
5
  SHA512:
6
- metadata.gz: ce307fc1467871f51be728fcaa1320ef4be5203467ab99405e26f34de76236f259e4b63bfdb91c2861cde8c3afe8ef9bd5534147896278f02a3c93ba0dd9cafd
7
- data.tar.gz: a0c54a40b9d872988afb698c8d1d8cdc5228932c3f89c0b12fa29be4ebefdc2fdc56d5c0489d490860ac0f2ac61d31af46934fdcb1a7db484a13d09149b3721a
6
+ metadata.gz: 7eef40d9e8a151f0b100ccbff525e03e20ffdd319fe83d9e77687e6b8b2a1779a233734494904d1fa1f6b10bb861e724ffb762b450fe656229a8225f67430764
7
+ data.tar.gz: e32ac2b0b2ffba928301b813cae5c5586ec18abcfeb9e5b7e193d40a9565b25ea7d17878de30ef43510eae36698a293ea8dd97a92a679d80675d09da7c129040
data/lib/lawyer/clause.rb CHANGED
@@ -4,7 +4,7 @@ require 'lawyer/wrong_signature_violation'
4
4
 
5
5
  module Lawyer
6
6
  class Clause
7
- attr_reader :name
7
+ attr_reader :name, :arity, :signature
8
8
 
9
9
  def initialize(params)
10
10
  @arity = nil
@@ -2,7 +2,8 @@ module Lawyer
2
2
  module RSpec
3
3
  module ContractDouble
4
4
  def contract_double(contract, return_values = {})
5
- methods = {}
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
- methods[clause.name] = return_value
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
- double(contract.name, methods)
26
+ the_double
17
27
  end
18
28
  end
19
29
  end
@@ -1,3 +1,3 @@
1
1
  module Lawyer
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -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.9
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-02-17 00:00:00.000000000 Z
11
+ date: 2014-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler