@@ -1074,22 +1074,43 @@ 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
+ # The map(&:to_sym) is for legacy Ruby compatability and can be dropped in RSpec 4
1082
+ it "maintains the method in the list of private_methods" do
1083
+ expect {
1084
+ verify_all
1085
+ } . to_not change { object . private_methods . map ( &:to_sym ) . include? ( :private_method ) } . from ( true )
1081
1086
end
1082
1087
1083
- it "cleans up the backed up method" do
1084
- expect ( klass . method_defined? ( :__existing_method_without_any_instance__ ) ) . to be_falsey
1088
+ it "maintains the methods exclusion from the list of public_methods" do
1089
+ expect {
1090
+ verify_all
1091
+ } . to_not change { object . public_methods . map ( &:to_sym ) . include? ( :private_method ) } . from ( false )
1085
1092
end
1086
1093
1087
- it "restores a stubbed private method after the spec is run" do
1094
+ it "maintains the methods visibility" do
1095
+ expect { klass . new . private_method } . to raise_error ( NoMethodError )
1096
+ expect ( klass . new . send ( :private_method ) ) . to eq ( :something )
1088
1097
expect ( klass . private_method_defined? ( :private_method ) ) . to be_truthy
1089
1098
end
1090
1099
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 )
1100
+ context "after the spec has run" do
1101
+ before ( :example ) { verify_all }
1102
+
1103
+ it "cleans up the backed up method" do
1104
+ expect ( klass . method_defined? ( :__existing_method_without_any_instance__ ) ) . to be_falsey
1105
+ end
1106
+
1107
+ it "restores a stubbed private method after the spec is run" do
1108
+ expect ( klass . private_method_defined? ( :private_method ) ) . to be_truthy
1109
+ end
1110
+
1111
+ it "ensures that the restored method behaves as it originally did" do
1112
+ expect ( klass . new . send ( :private_method ) ) . to eq ( :private_method_return_value )
1113
+ end
1093
1114
end
1094
1115
end
1095
1116
end
@@ -1098,7 +1119,7 @@ def foo; end
1098
1119
context "private methods" do
1099
1120
before :each do
1100
1121
expect_any_instance_of ( klass ) . to receive ( :private_method ) . and_return ( :something )
1101
- klass . new . private_method
1122
+ klass . new . send ( : private_method)
1102
1123
1103
1124
verify_all
1104
1125
end
@@ -1109,6 +1130,7 @@ def foo; end
1109
1130
1110
1131
it "restores a stubbed private method after the spec is run" do
1111
1132
expect ( klass . private_method_defined? ( :private_method ) ) . to be_truthy
1133
+ expect ( klass . new . private_methods . map ( &:to_sym ) ) . to include :private_method
1112
1134
end
1113
1135
1114
1136
it "ensures that the restored method behaves as it originally did" do
0 commit comments