factory_group 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/factory_group/group.rb +4 -1
- data/lib/factory_group/version.rb +1 -1
- data/spec/acceptance/factory_group_spec.rb +29 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f64df4359b221faf757b473d72d27900d9e66b1
|
4
|
+
data.tar.gz: ac5031d01f744261c4a331350cfa329081d8a0c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0ab513aa6b810faa7d13c3f3d9b1bd74f9c20bb2cb60c9d715ec9e12348daaa67b594ca108df4d46e6e3edd830945610fb9e290b32cc6ea7b511dfac0b857de
|
7
|
+
data.tar.gz: 9fe960d02264bdec4f3ec5ce545556de073fb7732b1122c83cd8258e0c53bf4c1133aff99fe214ff2953c20031fc0e6d694fa4bcd373b49808f37579f8e5b073
|
data/lib/factory_group/group.rb
CHANGED
@@ -13,7 +13,10 @@ module FactoryGroup
|
|
13
13
|
# Sets an instance variable with the name as the called method and
|
14
14
|
# assigns the args[0] passed to it.
|
15
15
|
def method_missing(name, *args, &block)
|
16
|
-
|
16
|
+
# If the args is empty, it means a variable is reused inside the group itself
|
17
|
+
evaluvated_result = args.empty? ? @factories.instance_eval(name.to_s) : args[0]
|
18
|
+
|
19
|
+
@factories.send("#{name.to_s}=", evaluvated_result)
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
@@ -1,21 +1,38 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe FactoryGroup do
|
4
|
-
before(:all) do
|
5
|
-
described_class.define(:user_group) do
|
6
|
-
user FactoryGirl.create(:user)
|
7
|
-
end
|
8
|
-
end
|
9
4
|
|
10
5
|
context "#create" do
|
11
|
-
|
12
|
-
|
6
|
+
describe "with a single basic factory" do
|
7
|
+
before do
|
8
|
+
described_class.define(:user_group) do
|
9
|
+
user FactoryGirl.create(:user)
|
10
|
+
end
|
11
|
+
|
12
|
+
@user_group = FactoryGroup.create(:user_group)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should create a factory_group with the factories" do
|
16
|
+
expect(@user_group).to be_a OpenStruct
|
17
|
+
expect(@user_group.user).to be_a User
|
18
|
+
expect(@user_group.user.name).to eq "sample"
|
19
|
+
expect(@user_group.user.age).to eq 20
|
20
|
+
end
|
13
21
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
22
|
+
|
23
|
+
describe "with a variable inside a group being reused inside the group itself" do
|
24
|
+
before do
|
25
|
+
described_class.define(:user_group) do
|
26
|
+
user FactoryGirl.create(:user)
|
27
|
+
name user.name
|
28
|
+
end
|
29
|
+
|
30
|
+
@user_group = FactoryGroup.create(:user_group)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should be able to access name attribute" do
|
34
|
+
expect(@user_group.name).to eq "sample"
|
35
|
+
end
|
19
36
|
end
|
20
37
|
end
|
21
38
|
end
|