@@ -85,69 +85,69 @@ class AnotherTestError < StandardError; end
8585 expect {
8686 expect {
8787 Rails . error . report ( StandardError . new ( "test" ) , context : { user_id : 123 , context : "actual" } )
88- } . to have_reported_error . with ( user_id : 456 , context : "expected" )
88+ } . to have_reported_error . with_context ( user_id : 456 , context : "expected" )
8989 } . to fail_with ( /Expected error attributes to match {user_id: 456, context: "expected"}, but got these mismatches: {user_id: 456, context: "expected"} and actual values are {"user_id" => 123, "context" => "actual"}/ )
9090 end
9191
9292 it "identifies partial attribute mismatches correctly" do
9393 expect {
9494 expect {
9595 Rails . error . report ( StandardError . new ( "test" ) , context : { user_id : 123 , status : "active" , role : "admin" } )
96- } . to have_reported_error . with ( user_id : 456 , status : "active" ) # user_id wrong, status correct
96+ } . to have_reported_error . with_context ( user_id : 456 , status : "active" ) # user_id wrong, status correct
9797 } . to fail_with ( /got these mismatches: {user_id: 456}/ )
9898 end
9999
100100 it "handles RSpec matcher mismatches in failure messages" do
101101 expect {
102102 expect {
103103 Rails . error . report ( StandardError . new ( "test" ) , context : { params : { foo : "different" } } )
104- } . to have_reported_error . with ( params : a_hash_including ( foo : "bar" ) )
104+ } . to have_reported_error . with_context ( params : a_hash_including ( foo : "bar" ) )
105105 } . to fail_with ( /Expected error attributes to match/ )
106106 end
107107
108108 it "shows actual context values when attributes don't match" do
109109 expect {
110110 expect {
111111 Rails . error . report ( StandardError . new ( "test" ) , context : { user_id : 123 , context : "actual" } )
112- } . to have_reported_error . with ( user_id : 456 )
112+ } . to have_reported_error . with_context ( user_id : 456 )
113113 } . to fail_with ( /actual values are {"user_id" => 123, "context" => "actual"}/ )
114114 end
115115 end
116116
117- describe "#with " do
117+ describe "#with_context " do
118118 it "passes when attributes match exactly" do
119119 expect {
120120 Rails . error . report ( StandardError . new ( "test" ) , context : { user_id : 123 , context : "test" } )
121- } . to have_reported_error . with ( user_id : 123 , context : "test" )
121+ } . to have_reported_error . with_context ( user_id : 123 , context : "test" )
122122 end
123123
124124 it "passes with partial attribute matching" do
125125 expect {
126126 Rails . error . report (
127127 StandardError . new ( "test" ) , context : { user_id : 123 , context : "test" , extra : "data" }
128128 )
129- } . to have_reported_error . with ( user_id : 123 )
129+ } . to have_reported_error . with_context ( user_id : 123 )
130130 end
131131
132132 it "passes with hash matching using RSpec matchers" do
133133 expect {
134134 Rails . error . report (
135135 StandardError . new ( "test" ) , context : { params : { foo : "bar" , baz : "qux" } }
136136 )
137- } . to have_reported_error . with ( params : a_hash_including ( foo : "bar" ) )
137+ } . to have_reported_error . with_context ( params : a_hash_including ( foo : "bar" ) )
138138 end
139139
140140 it "fails when attributes do not match" do
141141 expect {
142142 expect {
143143 Rails . error . report ( StandardError . new ( "test" ) , context : { user_id : 123 , context : "actual" } )
144- } . to have_reported_error . with ( user_id : 456 , context : "expected" )
144+ } . to have_reported_error . with_context ( user_id : 456 , context : "expected" )
145145 } . to fail_with ( /Expected error attributes to match {user_id: 456, context: "expected"}, but got these mismatches: {user_id: 456, context: "expected"} and actual values are {"user_id" => 123, "context" => "actual"}/ )
146146 end
147147
148148 it "fails when no error is reported but attributes are expected" do
149149 expect {
150- expect { "no error" } . to have_reported_error . with ( user_id : 123 )
150+ expect { "no error" } . to have_reported_error . with_context ( user_id : 123 )
151151 } . to fail_with ( /Expected the block to report an error, but none was reported./ )
152152 end
153153 end
0 commit comments