forked from technoweenie/model_stubbing
/
definition_spec.rb
95 lines (77 loc) · 2.42 KB
/
definition_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require File.join(File.dirname(__FILE__), 'spec_helper')
include ModelStubbing
describe Definition do
before :all do
@definition = ModelStubbing.definitions[:default]
end
it "defines as default definition" do
@definition.should be_kind_of(Definition)
end
it "sets #current_time" do
@definition.current_time.should == Time.utc(2007, 6, 1)
end
it "creates model instances" do
@definition.models[:users].should be_kind_of(Model)
end
it "retrieves default stubs" do
@definition.retrieve_record(:user).should == @definition.models[:users].default.record
end
it "retrieves stubs" do
@definition.retrieve_record(:admin_user).should == @definition.models[:users].stubs[:admin].record
end
end
describe Definition, "setup" do
before :all do
@definition = ModelStubbing.definitions[:default]
@tester = FakeTester.new
end
it "sets definition value" do
FakeTester.definition.should == @definition
end
it "retrieves default stubs" do
@tester.stubs(:user).should == @definition.models[:users].default.record
end
it "retrieves stubs" do
@tester.stubs(:admin_user).should == @definition.models[:users].stubs[:admin].record
end
it "retrieves default stubs with stub model method" do
@tester.users(:default).should == @definition.models[:users].default.record
end
it "retrieves stubs with stub model method" do
@tester.users(:admin).should == @definition.models[:users].stubs[:admin].record
end
end
describe Definition, "duping itself" do
before :all do
@defn = ModelStubbing.definitions[:default]
@copy = @defn.dup
end
it "dups @current_time" do
@defn.current_time.should == @copy.current_time
end
it "dups each model" do
@defn.models.each do |name, model|
duped_model = @copy.models[name]
model.should == duped_model
model.should_not be_equal(duped_model)
model.stubs.each do |key, stub|
duped_stub = @copy.models[name].stubs[key]
stub.should == duped_stub
stub.should_not be_equal(duped_stub)
end
end
end
it "dups each stub" do
@defn.stubs.each do |name, stub|
duped_stub = @copy.stubs[name]
stub.should == duped_stub
stub.should_not be_equal(duped_stub)
end
end
it "is not the same instance" do
@defn.object_id.should_not == @copy.object_id
end
it "is still be equal" do
@defn.should == @copy
end
end