File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -1084,6 +1084,7 @@ they will retry the match for given timeout allowing you to test ajax actions.
1084
1084
end
1085
1085
` ` `
1086
1086
1087
+
1087
1088
* Use ` its` when possible
1088
1089
1089
1090
` ` ` Ruby
@@ -1103,6 +1104,44 @@ they will retry the match for given timeout allowing you to test ajax actions.
1103
1104
end
1104
1105
` ` `
1105
1106
1107
+
1108
+ * Use ` shared_examples` if you want to create a spec group that can be shared by many other tests.
1109
+
1110
+ ` ` ` Ruby
1111
+ # bad
1112
+ describe Array do
1113
+ subject { Array.new [7, 2, 4] }
1114
+
1115
+ context "initialized with 3 items" do
1116
+ its(:size) { should eq(3) }
1117
+ end
1118
+ end
1119
+
1120
+ describe Set do
1121
+ subject { Set.new [7, 2, 4] }
1122
+
1123
+ context "initialized with 3 items" do
1124
+ its(:size) { should eq(3) }
1125
+ end
1126
+ end
1127
+
1128
+ #good
1129
+ shared_examples "a collection" do
1130
+ subject { described_class.new([7, 2, 4]) }
1131
+
1132
+ context "initialized with 3 items" do
1133
+ its(:size) { should eq(3) }
1134
+ end
1135
+ end
1136
+
1137
+ describe Array do
1138
+ it_behaves_like "a collection"
1139
+ end
1140
+
1141
+ describe Set do
1142
+ it_behaves_like "a collection"
1143
+ end
1144
+
1106
1145
### Views
1107
1146
1108
1147
* The directory structure of the view specs ` spec/ views` matches the
You can’t perform that action at this time.
0 commit comments