quacky 0.1.1 → 0.1.2
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.
- data/VERSION +1 -1
- data/lib/quacky/quacky.rb +24 -6
- data/spec/lib/quacky_spec.rb +32 -14
- metadata +10 -10
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/quacky/quacky.rb
CHANGED
@@ -139,27 +139,45 @@ module Quacky
|
|
139
139
|
end
|
140
140
|
|
141
141
|
private
|
142
|
+
|
143
|
+
def quacky_expectations
|
144
|
+
@expectations ||= {}
|
145
|
+
end
|
146
|
+
|
142
147
|
def setup_expectation method_name
|
148
|
+
method_name = method_name.to_sym
|
143
149
|
raise Quacky::NoMethodError unless respond_to? method_name
|
144
|
-
|
150
|
+
|
151
|
+
quacky_expectations[method_name] = Stub.new(public_method(method_name))
|
152
|
+
sanitized_name, postpend = parse_method_name method_name
|
145
153
|
|
146
154
|
eval <<-EVAL
|
147
155
|
class << self
|
148
|
-
define_method("#{
|
149
|
-
|
156
|
+
define_method("#{sanitized_name}_with_expectation#{postpend}") do |*args|
|
157
|
+
quacky_expectations[:#{method_name}].call *args
|
150
158
|
end
|
151
159
|
|
152
160
|
alias_method_chain :#{method_name}, :expectation
|
153
161
|
end
|
154
162
|
EVAL
|
155
163
|
|
156
|
-
|
164
|
+
quacky_expectations[method_name]
|
165
|
+
end
|
166
|
+
|
167
|
+
def parse_method_name method_name
|
168
|
+
method_name = method_name.to_s
|
169
|
+
eol_matcher = /([\!\?])$/
|
170
|
+
method_name_postpend = method_name.to_s.match(eol_matcher) ? $1 : ""
|
171
|
+
method_name_minus_postpend = method_name.to_s.gsub eol_matcher, ""
|
172
|
+
[method_name_minus_postpend, method_name_postpend]
|
157
173
|
end
|
158
174
|
end
|
159
175
|
|
160
|
-
def double
|
176
|
+
def double(*duck_types)
|
161
177
|
Double.new.tap do |object|
|
162
|
-
|
178
|
+
duck_types.each do |duck_type|
|
179
|
+
object.extend duck_type
|
180
|
+
end
|
163
181
|
object.extend Quacky::Expectations
|
164
182
|
end
|
165
183
|
end
|
data/spec/lib/quacky_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative '../../lib/quacky/quacky'
|
2
2
|
|
3
3
|
module Duck
|
4
|
-
def duck arg; end
|
4
|
+
def duck! arg; end
|
5
5
|
end
|
6
6
|
|
7
7
|
describe Quacky::DuckTypeVerifier do
|
@@ -70,11 +70,20 @@ describe Quacky do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
describe "#double" do
|
73
|
-
|
73
|
+
context "with a single included module" do
|
74
|
+
let(:eigenclass) { class << Quacky.double(Duck); self; end }
|
74
75
|
|
75
|
-
|
76
|
+
subject { eigenclass }
|
76
77
|
|
77
|
-
|
78
|
+
its(:included_modules) { should include Duck }
|
79
|
+
end
|
80
|
+
|
81
|
+
context "with multiple included modules" do
|
82
|
+
let(:another_mod) { Module.new }
|
83
|
+
let(:eigenclass) { class << Quacky.double(Duck, another_mod); self; end }
|
84
|
+
subject { eigenclass }
|
85
|
+
its(:included_modules) { should include Duck, another_mod }
|
86
|
+
end
|
78
87
|
end
|
79
88
|
|
80
89
|
describe "#class_double" do
|
@@ -118,17 +127,26 @@ describe Quacky do
|
|
118
127
|
end
|
119
128
|
|
120
129
|
it "should initialize and return a new Quacky::Stub otherwise" do
|
121
|
-
Quacky::Stub.should_receive(:new).with(q_double.public_method(:duck)).and_return expectation
|
122
|
-
q_double.stub(:duck).should == expectation
|
130
|
+
Quacky::Stub.should_receive(:new).with(q_double.public_method(:duck!)).and_return expectation
|
131
|
+
q_double.stub(:duck!).should == expectation
|
123
132
|
end
|
124
133
|
|
125
134
|
it "should reroute calls to the original method to call the expectation's call method" do
|
126
|
-
Quacky::Stub.stub(:new).with(q_double.public_method(:duck)).and_return expectation
|
127
|
-
q_double.stub(:duck)
|
135
|
+
Quacky::Stub.stub(:new).with(q_double.public_method(:duck!)).and_return expectation
|
136
|
+
q_double.stub(:duck!)
|
128
137
|
|
129
138
|
argument = double :argument
|
130
139
|
expectation.should_receive(:call).with argument
|
131
|
-
q_double.duck(argument)
|
140
|
+
q_double.duck!(argument)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should support methods ending in !, ?, and regular letters" do
|
144
|
+
new_return = double :new_arg
|
145
|
+
question_return = double :question_arg
|
146
|
+
regular_return = double :regular_arg
|
147
|
+
Quacky::Stub.stub(:bang!).and_return new_return
|
148
|
+
Quacky::Stub.stub(:question!).and_return question_return
|
149
|
+
Quacky::Stub.stub(:regular).and_return regular_return
|
132
150
|
end
|
133
151
|
end
|
134
152
|
|
@@ -138,13 +156,13 @@ describe Quacky do
|
|
138
156
|
end
|
139
157
|
|
140
158
|
it "should initialize and return a new QuackyStub otherwise" do
|
141
|
-
Quacky::Stub.should_receive(:new).with(q_double.public_method(:duck)).and_return expectation
|
142
|
-
q_double.should_receive(:duck).should == expectation
|
159
|
+
Quacky::Stub.should_receive(:new).with(q_double.public_method(:duck!)).and_return expectation
|
160
|
+
q_double.should_receive(:duck!).should == expectation
|
143
161
|
end
|
144
162
|
|
145
163
|
it "should add the generated expectation to the list of required expectations" do
|
146
|
-
Quacky::Stub.stub(:new).with(q_double.public_method(:duck)).and_return expectation
|
147
|
-
q_double.should_receive(:duck)
|
164
|
+
Quacky::Stub.stub(:new).with(q_double.public_method(:duck!)).and_return expectation
|
165
|
+
q_double.should_receive(:duck!)
|
148
166
|
Quacky.expectations.should include expectation
|
149
167
|
end
|
150
168
|
end
|
@@ -160,7 +178,7 @@ module Quacky
|
|
160
178
|
end
|
161
179
|
|
162
180
|
describe Stub do
|
163
|
-
let(:q_expectation) { Quacky::Stub.new(object.public_method(:duck)) }
|
181
|
+
let(:q_expectation) { Quacky::Stub.new(object.public_method(:duck!)) }
|
164
182
|
|
165
183
|
describe "#with" do
|
166
184
|
it "should raise an exception if the original method's signature mismatches" do
|
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.1.
|
4
|
+
version: 0.1.2
|
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-06-
|
12
|
+
date: 2012-06-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &70244437807500 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.2.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70244437807500
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70244437807100 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70244437807100
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: cucumber
|
38
|
-
requirement: &
|
38
|
+
requirement: &70244437806640 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70244437806640
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &70244437806220 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70244437806220
|
58
58
|
description:
|
59
59
|
email: moonmaster9000@gmail.com
|
60
60
|
executables: []
|