quacky 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -35,7 +35,7 @@ module Quacky
35
35
  end
36
36
 
37
37
  def duck_type_object
38
- return @duck_type_object if @duck_type_object
38
+ return @duck_type_object if @duck_type_object
39
39
  duck_type_class = Class.new
40
40
  duck_type_class.send :include, duck_type
41
41
  @duck_type_object = duck_type_class.new
@@ -4,8 +4,8 @@ module Quacky
4
4
  class NoMethodError < RuntimeError; end
5
5
 
6
6
  module Expectations
7
- def quacky_stub method_name
8
- setup_expectation method_name
7
+ def quacky_stub method_name, &block
8
+ setup_expectation method_name, &block
9
9
  end
10
10
 
11
11
  def should_receive method_name
@@ -20,11 +20,11 @@ module Quacky
20
20
  @expectations ||= {}
21
21
  end
22
22
 
23
- def setup_expectation method_name
23
+ def setup_expectation method_name, &block
24
24
  method_name = method_name.to_sym
25
- raise Quacky::NoMethodError unless respond_to? method_name
25
+ raise Quacky::NoMethodError, "#{inspect} does not define `#{method_name}'" unless respond_to?(method_name)
26
26
 
27
- quacky_expectations[method_name] = Stub.new(public_method(method_name))
27
+ quacky_expectations[method_name] = Stub.new(public_method(method_name), &block)
28
28
  sanitized_name, postpend = parse_method_name method_name
29
29
 
30
30
  eval <<-EVAL
@@ -4,8 +4,9 @@ module Quacky
4
4
  class MethodSignatureMismatch < ArgumentError; end
5
5
 
6
6
  class Stub
7
- def initialize method
7
+ def initialize method, &block
8
8
  @method = method
9
+ @return_block = block
9
10
  end
10
11
 
11
12
  def with *args
@@ -33,7 +34,7 @@ module Quacky
33
34
  end
34
35
 
35
36
  def validate_satisfaction!
36
- if expected_args
37
+ if expected_args
37
38
  if called_args == expected_args
38
39
  true
39
40
  else
@@ -54,7 +55,7 @@ module Quacky
54
55
  def validate_expectation
55
56
  if expected_args && called_args != expected_args
56
57
  raise(
57
- Quacky::UnexpectedArguments,
58
+ Quacky::UnexpectedArguments,
58
59
  "#{@method.name} was called with unexpected arguments: #{called_args.map(&:inspect).join ", "}. expected: #{expected_args.map(&:inspect).join ", "}"
59
60
  )
60
61
  end
@@ -35,7 +35,7 @@ describe Quacky::DuckTypeVerifier do
35
35
  end
36
36
 
37
37
  it "should raise a Quacky::DuckTypeVerificationFailure" do
38
- expect { verifier.verify! non_conforming_object }.to raise_exception Quacky::DuckTypeVerificationFailure, "definitions of method `quack` differ in parameters accepted."
38
+ expect { verifier.verify! non_conforming_object }.to raise_exception Quacky::DuckTypeVerificationFailure, "definitions of method `quack` differ in parameters accepted."
39
39
  end
40
40
  end
41
41
  end
@@ -24,7 +24,7 @@ describe "Quacky::Double created with Quacky.double" do
24
24
  end
25
25
 
26
26
  it "should support methods ending in !, ?, and regular letters" do
27
- q_double = Quacky.double(:quacky_double, Module.new do
27
+ q_double = Quacky.double(:quacky_double, Module.new do
28
28
  def bang!; end
29
29
  def question?; end
30
30
  def regular; end
@@ -52,7 +52,7 @@ describe "Quacky::Double created with Quacky.double" do
52
52
 
53
53
  it "should add the generated expectation to the list of required expectations" do
54
54
  Quacky::Stub.stub(:new).with(q_double.public_method(:duck!)).and_return expectation
55
- q_double.should_receive(:duck!)
55
+ q_double.should_receive(:duck!)
56
56
  Quacky.expectations.should include expectation
57
57
  end
58
58
  end
@@ -1,7 +1,7 @@
1
1
  module MiniTest; end
2
2
 
3
- require_relative '../../../lib/quacky/minitest_setup'
4
3
  require_relative '../../../lib/quacky/quacky'
4
+ require_relative '../../../lib/quacky/minitest_setup'
5
5
 
6
6
  describe Quacky do
7
7
  describe ".mock" do
@@ -27,10 +27,20 @@ module Quacky
27
27
  end
28
28
 
29
29
  context "block return value" do
30
- it "should return the value returned by the block" do
31
- return_value = double :return_value
32
- q_expectation.and_return { return_value }
33
- q_expectation.call(double :argument).should == return_value
30
+ context "explicit" do
31
+ it "should return the value returned by the block" do
32
+ return_value = double :return_value
33
+ q_expectation.and_return { return_value }
34
+ q_expectation.call(double :argument).should == return_value
35
+ end
36
+ end
37
+
38
+ context "implicit" do
39
+ it "should return the value returned by the block" do
40
+ return_value = double :return_value
41
+ q_expectation = Quacky::Stub.new(object.public_method(:duck!)) { return_value }
42
+ q_expectation.call(double :argument).should == return_value
43
+ end
34
44
  end
35
45
  end
36
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quacky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2012-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70144887114120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: 3.2.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 3.2.5
24
+ version_requirements: *70144887114120
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: rspec
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &70144887113420 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,15 +32,10 @@ dependencies:
37
32
  version: '0'
38
33
  type: :development
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
35
+ version_requirements: *70144887113420
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: cucumber
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &70144887112560 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
41
  - - ! '>='
@@ -53,15 +43,10 @@ dependencies:
53
43
  version: '0'
54
44
  type: :development
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
46
+ version_requirements: *70144887112560
62
47
  - !ruby/object:Gem::Dependency
63
48
  name: specdown
64
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &70144887111700 !ruby/object:Gem::Requirement
65
50
  none: false
66
51
  requirements:
67
52
  - - ! '>='
@@ -69,15 +54,10 @@ dependencies:
69
54
  version: '0'
70
55
  type: :development
71
56
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
57
+ version_requirements: *70144887111700
78
58
  - !ruby/object:Gem::Dependency
79
59
  name: rake
80
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &70144887110980 !ruby/object:Gem::Requirement
81
61
  none: false
82
62
  requirements:
83
63
  - - ! '>='
@@ -85,12 +65,7 @@ dependencies:
85
65
  version: '0'
86
66
  type: :development
87
67
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
68
+ version_requirements: *70144887110980
94
69
  description:
95
70
  email: moonmaster9000@gmail.com
96
71
  executables: []
@@ -135,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
110
  version: '0'
136
111
  requirements: []
137
112
  rubyforge_project:
138
- rubygems_version: 1.8.24
113
+ rubygems_version: 1.8.17
139
114
  signing_key:
140
115
  specification_version: 3
141
116
  summary: Ensure your test doubles quack like the real thing.
@@ -147,4 +122,3 @@ test_files:
147
122
  - spec/lib/quacky_spec.rb
148
123
  - spec/lib/stub_spec.rb
149
124
  - spec/spec_helper.rb
150
- has_rdoc: