@@ -1074,22 +1074,42 @@ def foo; end
10741074 end
10751075
10761076 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 ) }
10791078
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 )
10811085 end
10821086
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 )
10851091 end
10861092
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 )
10881096 expect ( klass . private_method_defined? ( :private_method ) ) . to be_truthy
10891097 end
10901098
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
10931113 end
10941114 end
10951115 end
@@ -1098,7 +1118,7 @@ def foo; end
10981118 context "private methods" do
10991119 before :each do
11001120 expect_any_instance_of ( klass ) . to receive ( :private_method ) . and_return ( :something )
1101- klass . new . private_method
1121+ klass . new . send ( : private_method)
11021122
11031123 verify_all
11041124 end
@@ -1109,6 +1129,7 @@ def foo; end
11091129
11101130 it "restores a stubbed private method after the spec is run" do
11111131 expect ( klass . private_method_defined? ( :private_method ) ) . to be_truthy
1132+ expect ( klass . new . private_methods ) . to include :private_method
11121133 end
11131134
11141135 it "ensures that the restored method behaves as it originally did" do
0 commit comments