Skip to content

Commit 0e4b010

Browse files
committed
Improve ActionCable tests
1 parent a011b3a commit 0e4b010

1 file changed

Lines changed: 86 additions & 106 deletions

File tree

sentry-rails/spec/sentry/rails/action_cable_spec.rb

Lines changed: 86 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,8 @@ def unsubscribed
4747
expect(transport.events.count).to eq(1)
4848

4949
event = transport.events.last.to_json_compatible
50-
expect(event).to include(
51-
"transaction" => "ChatChannel#subscribed",
52-
"contexts" => hash_including(
53-
"action_cable" => {
54-
"params" => { "room_id" => 42 }
55-
}
56-
)
57-
)
50+
expect(event["transaction"]).to eq("ChatChannel#subscribed")
51+
expect(event["contexts"]).to include("action_cable" => { "params" => { "room_id" => 42 } })
5852
end
5953
end
6054

@@ -67,14 +61,12 @@ def unsubscribed
6761

6862
event = transport.events.last.to_json_compatible
6963

70-
expect(event).to include(
71-
"transaction" => "AppearanceChannel#appear",
72-
"contexts" => hash_including(
73-
"action_cable" => {
74-
"params" => { "room_id" => 42 },
75-
"data" => { "action" => "appear", "foo" => "bar" }
76-
}
77-
)
64+
expect(event["transaction"]).to eq("AppearanceChannel#appear")
65+
expect(event["contexts"]).to include(
66+
"action_cable" => {
67+
"params" => { "room_id" => 42 },
68+
"data" => { "action" => "appear", "foo" => "bar" }
69+
}
7870
)
7971
end
8072

@@ -84,13 +76,11 @@ def unsubscribed
8476

8577
event = transport.events.last.to_json_compatible
8678

87-
expect(event).to include(
88-
"transaction" => "AppearanceChannel#unsubscribed",
89-
"contexts" => hash_including(
90-
"action_cable" => {
91-
"params" => { "room_id" => 42 }
92-
}
93-
)
79+
expect(event["transaction"]).to eq("AppearanceChannel#unsubscribed")
80+
expect(event["contexts"]).to include(
81+
"action_cable" => {
82+
"params" => { "room_id" => 42 }
83+
}
9484
)
9585
end
9686
end
@@ -110,28 +100,22 @@ def unsubscribed
110100

111101
event = transport.events.first.to_json_compatible
112102

113-
expect(event).to include(
114-
"transaction" => "ChatChannel#subscribed",
115-
"contexts" => hash_including(
116-
"action_cable" => {
117-
"params" => { "room_id" => 42 }
118-
}
119-
)
120-
)
103+
expect(event["transaction"]).to eq("ChatChannel#subscribed")
104+
expect(event["contexts"]).to include("action_cable" => { "params" => { "room_id" => 42 } })
121105

122106
transaction = transport.events.last.to_json_compatible
123107

124-
expect(transaction).to include(
125-
"type" => "transaction",
126-
"transaction" => "ChatChannel#subscribed",
127-
"contexts" => hash_including(
128-
"action_cable" => {
129-
"params" => { "room_id" => 42 }
130-
},
131-
"trace" => hash_including(
132-
"op" => "rails.action_cable",
133-
"status" => "internal_error"
134-
)
108+
expect(transaction["type"]).to eq("transaction")
109+
expect(transaction["transaction"]).to eq("ChatChannel#subscribed")
110+
expect(transaction["contexts"]).to include(
111+
"action_cable" => {
112+
"params" => { "room_id" => 42 }
113+
}
114+
)
115+
expect(transaction["contexts"]).to include(
116+
"trace" => hash_including(
117+
"op" => "rails.action_cable",
118+
"status" => "internal_error"
135119
)
136120
)
137121
end
@@ -146,47 +130,45 @@ def unsubscribed
146130

147131
subscription_transaction = transport.events[0].to_json_compatible
148132

149-
expect(subscription_transaction).to include(
150-
"type" => "transaction",
151-
"contexts" => hash_including(
152-
"trace" => hash_including(
153-
"op" => "rails.action_cable",
154-
"status" => "ok"
155-
),
156-
"action_cable" => {
157-
"params" => { "room_id" => 42 }
158-
}
159-
),
160-
"transaction" => "AppearanceChannel#subscribed"
133+
expect(subscription_transaction["type"]).to eq("transaction")
134+
expect(subscription_transaction["transaction"]).to eq("AppearanceChannel#subscribed")
135+
expect(subscription_transaction["contexts"]).to include(
136+
"action_cable" => {
137+
"params" => { "room_id" => 42 }
138+
}
139+
)
140+
expect(subscription_transaction["contexts"]).to include(
141+
"trace" => hash_including(
142+
"op" => "rails.action_cable",
143+
"status" => "ok"
144+
)
161145
)
162146

163147
event = transport.events[1].to_json_compatible
164148

165-
expect(event).to include(
166-
"transaction" => "AppearanceChannel#appear",
167-
"contexts" => hash_including(
168-
"action_cable" => {
169-
"params" => { "room_id" => 42 },
170-
"data" => { "action" => "appear", "foo" => "bar" }
171-
}
172-
)
149+
expect(event["transaction"]).to eq("AppearanceChannel#appear")
150+
expect(event["contexts"]).to include(
151+
"action_cable" => {
152+
"params" => { "room_id" => 42 },
153+
"data" => { "action" => "appear", "foo" => "bar" }
154+
}
173155
)
174156

175157
action_transaction = transport.events[2].to_json_compatible
176158

177-
expect(action_transaction).to include(
178-
"type" => "transaction",
179-
"contexts" => hash_including(
180-
"trace" => hash_including(
181-
"op" => "rails.action_cable",
182-
"status" => "internal_error"
183-
),
184-
"action_cable" => {
185-
"params" => { "room_id" => 42 },
186-
"data" => { "action" => "appear", "foo" => "bar" }
187-
}
188-
),
189-
"transaction" => "AppearanceChannel#appear"
159+
expect(action_transaction["type"]).to eq("transaction")
160+
expect(action_transaction["transaction"]).to eq("AppearanceChannel#appear")
161+
expect(action_transaction["contexts"]).to include(
162+
"action_cable" => {
163+
"params" => { "room_id" => 42 },
164+
"data" => { "action" => "appear", "foo" => "bar" }
165+
}
166+
)
167+
expect(action_transaction["contexts"]).to include(
168+
"trace" => hash_including(
169+
"op" => "rails.action_cable",
170+
"status" => "internal_error"
171+
)
190172
)
191173
end
192174

@@ -196,45 +178,43 @@ def unsubscribed
196178

197179
subscription_transaction = transport.events[0].to_json_compatible
198180

199-
expect(subscription_transaction).to include(
200-
"type" => "transaction",
201-
"contexts" => hash_including(
202-
"trace" => hash_including(
203-
"op" => "rails.action_cable",
204-
"status" => "ok"
205-
),
206-
"action_cable" => {
207-
"params" => { "room_id" => 42 }
208-
}
209-
),
210-
"transaction" => "AppearanceChannel#subscribed"
181+
expect(subscription_transaction["type"]).to eq("transaction")
182+
expect(subscription_transaction["transaction"]).to eq("AppearanceChannel#subscribed")
183+
expect(subscription_transaction["contexts"]).to include(
184+
"action_cable" => {
185+
"params" => { "room_id" => 42 }
186+
}
187+
)
188+
expect(subscription_transaction["contexts"]).to include(
189+
"trace" => hash_including(
190+
"op" => "rails.action_cable",
191+
"status" => "ok"
192+
)
211193
)
212194

213195
event = transport.events[1].to_json_compatible
214196

215-
expect(event).to include(
216-
"transaction" => "AppearanceChannel#unsubscribed",
217-
"contexts" => hash_including(
218-
"action_cable" => {
219-
"params" => { "room_id" => 42 }
220-
}
221-
)
197+
expect(event["transaction"]).to eq("AppearanceChannel#unsubscribed")
198+
expect(event["contexts"]).to include(
199+
"action_cable" => {
200+
"params" => { "room_id" => 42 }
201+
}
222202
)
223203

224204
transaction = transport.events[2].to_json_compatible
225205

226-
expect(transaction).to include(
227-
"type" => "transaction",
228-
"contexts" => hash_including(
229-
"trace" => hash_including(
230-
"op" => "rails.action_cable",
231-
"status" => "internal_error"
232-
),
233-
"action_cable" => {
234-
"params" => { "room_id" => 42 }
235-
}
236-
),
237-
"transaction" => "AppearanceChannel#unsubscribed"
206+
expect(transaction["type"]).to eq("transaction")
207+
expect(transaction["transaction"]).to eq("AppearanceChannel#unsubscribed")
208+
expect(transaction["contexts"]).to include(
209+
"action_cable" => {
210+
"params" => { "room_id" => 42 }
211+
}
212+
)
213+
expect(transaction["contexts"]).to include(
214+
"trace" => hash_including(
215+
"op" => "rails.action_cable",
216+
"status" => "internal_error"
217+
)
238218
)
239219
end
240220
end

0 commit comments

Comments
 (0)