@@ -1074,22 +1074,42 @@ def foo; end
1074
1074
end
1075
1075
1076
1076
context "private methods" do
1077
- before :each do
1078
- allow_any_instance_of ( klass ) . to receive ( :private_method ) . and_return ( :something )
1077
+ before ( :example ) { allow_any_instance_of ( klass ) . to receive ( :private_method ) . and_return ( :something ) }
1079
1078
1080
- verify_all
1079
+ let ( :object ) { klass . new }
1080
+
1081
+ it "maintains the method in the list of private_methods" do
1082
+ expect {
1083
+ verify_all
1084
+ } . to_not change { object . private_methods . include? ( :private_method ) } . from ( true )
1081
1085
end
1082
1086
1083
- it "cleans up the backed up method" do
1084
- expect ( klass . method_defined? ( :__existing_method_without_any_instance__ ) ) . to be_falsey
1087
+ it "maintains the methods exclusion from the list of public_methods" do
1088
+ expect {
1089
+ verify_all
1090
+ } . to_not change { object . public_methods . include? ( :private_method ) } . from ( false )
1085
1091
end
1086
1092
1087
- it "restores a stubbed private method after the spec is run" do
1093
+ it "maintains the methods visibility" do
1094
+ expect { klass . new . private_method } . to raise_error ( NoMethodError )
1095
+ expect ( klass . new . send ( :private_method ) ) . to eq ( :something )
1088
1096
expect ( klass . private_method_defined? ( :private_method ) ) . to be_truthy
1089
1097
end
1090
1098
1091
- it "ensures that the restored method behaves as it originally did" do
1092
- expect ( klass . new . send ( :private_method ) ) . to eq ( :private_method_return_value )
1099
+ context "after the spec has run" do
1100
+ before ( :example ) { verify_all }
1101
+
1102
+ it "cleans up the backed up method" do
1103
+ expect ( klass . method_defined? ( :__existing_method_without_any_instance__ ) ) . to be_falsey
1104
+ end
1105
+
1106
+ it "restores a stubbed private method after the spec is run" do
1107
+ expect ( klass . private_method_defined? ( :private_method ) ) . to be_truthy
1108
+ end
1109
+
1110
+ it "ensures that the restored method behaves as it originally did" do
1111
+ expect ( klass . new . send ( :private_method ) ) . to eq ( :private_method_return_value )
1112
+ end
1093
1113
end
1094
1114
end
1095
1115
end
@@ -1098,7 +1118,7 @@ def foo; end
1098
1118
context "private methods" do
1099
1119
before :each do
1100
1120
expect_any_instance_of ( klass ) . to receive ( :private_method ) . and_return ( :something )
1101
- klass . new . private_method
1121
+ klass . new . send ( : private_method)
1102
1122
1103
1123
verify_all
1104
1124
end
@@ -1109,6 +1129,7 @@ def foo; end
1109
1129
1110
1130
it "restores a stubbed private method after the spec is run" do
1111
1131
expect ( klass . private_method_defined? ( :private_method ) ) . to be_truthy
1132
+ expect ( klass . new . private_methods ) . to include :private_method
1112
1133
end
1113
1134
1114
1135
it "ensures that the restored method behaves as it originally did" do
0 commit comments