fakes 0.4.1 → 1.0.0
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/lib/core/version.rb +1 -1
- data/lib/fakes.rb +6 -4
- data/spec/specs/extensions_spec.rb +16 -1
- metadata +2 -2
data/lib/core/version.rb
CHANGED
data/lib/fakes.rb
CHANGED
@@ -15,14 +15,16 @@ require 'core/method_stub'
|
|
15
15
|
require 'singleton'
|
16
16
|
|
17
17
|
class Object
|
18
|
-
def fake
|
19
|
-
|
18
|
+
def fake(invocations = {})
|
19
|
+
item = Fakes::Fake.new
|
20
|
+
invocations.each{|method,return_value| item.stub(method).and_return(return_value)}
|
21
|
+
item
|
20
22
|
end
|
21
23
|
def arg_match
|
22
24
|
return Fakes::Matches
|
23
25
|
end
|
24
|
-
def fake_class(klass)
|
25
|
-
item = fake
|
26
|
+
def fake_class(klass,invocations = {})
|
27
|
+
item = fake(invocations)
|
26
28
|
Fakes::ClassSwaps.instance.add_fake_for(klass,item)
|
27
29
|
item
|
28
30
|
end
|
@@ -4,6 +4,11 @@ describe Object do
|
|
4
4
|
it "should be able to create a new fake" do
|
5
5
|
fake.class.should == Fakes::Fake
|
6
6
|
end
|
7
|
+
it "should be able to create a new fake and specify return values for methods" do
|
8
|
+
item = fake :hello => 'World', :age => 33
|
9
|
+
item.hello.should == 'World'
|
10
|
+
item.age.should == 33
|
11
|
+
end
|
7
12
|
|
8
13
|
context "when specifying a fake for a class" do
|
9
14
|
let(:swaps){fake}
|
@@ -21,7 +26,17 @@ describe Object do
|
|
21
26
|
it "should return the newly created fake" do
|
22
27
|
@result.should_not be_nil
|
23
28
|
end
|
24
|
-
|
29
|
+
end
|
30
|
+
context "when faking a class and specifying return values" do
|
31
|
+
before (:each) do
|
32
|
+
fake_class Dir,:exist? => true
|
33
|
+
end
|
34
|
+
after (:each) do
|
35
|
+
reset_fake_classes
|
36
|
+
end
|
37
|
+
it "should replace the class with the fake return to return the values specified" do
|
38
|
+
Dir.exist?('hello').should be_true
|
39
|
+
end
|
25
40
|
end
|
26
41
|
|
27
42
|
context "resetting fake classes" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|