@@ -85,69 +85,69 @@ class AnotherTestError < StandardError; end
85
85
expect {
86
86
expect {
87
87
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" )
89
89
} . 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"}/ )
90
90
end
91
91
92
92
it "identifies partial attribute mismatches correctly" do
93
93
expect {
94
94
expect {
95
95
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
97
97
} . to fail_with ( /got these mismatches: {user_id: 456}/ )
98
98
end
99
99
100
100
it "handles RSpec matcher mismatches in failure messages" do
101
101
expect {
102
102
expect {
103
103
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" ) )
105
105
} . to fail_with ( /Expected error attributes to match/ )
106
106
end
107
107
108
108
it "shows actual context values when attributes don't match" do
109
109
expect {
110
110
expect {
111
111
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 )
113
113
} . to fail_with ( /actual values are {"user_id" => 123, "context" => "actual"}/ )
114
114
end
115
115
end
116
116
117
- describe "#with " do
117
+ describe "#with_context " do
118
118
it "passes when attributes match exactly" do
119
119
expect {
120
120
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" )
122
122
end
123
123
124
124
it "passes with partial attribute matching" do
125
125
expect {
126
126
Rails . error . report (
127
127
StandardError . new ( "test" ) , context : { user_id : 123 , context : "test" , extra : "data" }
128
128
)
129
- } . to have_reported_error . with ( user_id : 123 )
129
+ } . to have_reported_error . with_context ( user_id : 123 )
130
130
end
131
131
132
132
it "passes with hash matching using RSpec matchers" do
133
133
expect {
134
134
Rails . error . report (
135
135
StandardError . new ( "test" ) , context : { params : { foo : "bar" , baz : "qux" } }
136
136
)
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" ) )
138
138
end
139
139
140
140
it "fails when attributes do not match" do
141
141
expect {
142
142
expect {
143
143
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" )
145
145
} . 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"}/ )
146
146
end
147
147
148
148
it "fails when no error is reported but attributes are expected" do
149
149
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 )
151
151
} . to fail_with ( /Expected the block to report an error, but none was reported./ )
152
152
end
153
153
end
0 commit comments