/
parent_spec.rb
49 lines (41 loc) · 1.47 KB
/
parent_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
require 'spec_helper'
describe "an instance generated by a factory that inherits from another factory" do
before do
define_model("User", :name => :string, :admin => :boolean, :email => :string, :upper_email => :string, :login => :string)
FactoryGirl.define do
factory :user do
name "John"
email { "#{name.downcase}@example.com" }
login { email }
factory :admin do
name "admin"
admin true
upper_email { email.upcase }
end
factory :guest do
email { "#{name}-guest@example.com" }
end
end
end
end
describe "the parent class" do
subject { FactoryGirl.create(:user) }
it { should_not be_admin }
its(:email) { should == "john@example.com" }
end
describe "the child class redefining parent's static method used by a dynamic method" do
subject { FactoryGirl.create(:admin) }
it { should be_kind_of(User) }
it { should be_admin }
its(:name) { should == "admin" }
its(:email) { should == "admin@example.com" }
its(:upper_email) { should == "ADMIN@EXAMPLE.COM"}
end
describe "the child class redefining parent's dynamic method" do
subject { FactoryGirl.create(:guest) }
it { should_not be_admin }
its(:name) { should == "John" }
its(:email) { should eql "John-guest@example.com" }
its(:login) { should == "John-guest@example.com" }
end
end