Skip to content

Commit 1f586c6

Browse files
committed
Add specific integration test for ActionDispatch::TestResponse
1 parent 3ca82f5 commit 1f586c6

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,49 @@
11
# frozen_string_literal: true
22

33
shared_examples_for 'integration with ActionDispatch' do
4+
context 'when testing attributes of an ActionDispatch::TestResponse' do
5+
it 'produces the correct failure message when used in the positive' do
6+
as_both_colored_and_uncolored do |color_enabled|
7+
snippet = <<~RUBY
8+
request = ActionDispatch::TestRequest.create
9+
response = ActionDispatch::TestResponse.new(200, {}, []).tap do |response|
10+
response.request = request
11+
end
12+
13+
# The other attributes of TestResponse differ across Rails versions. We don't care about them
14+
# for the purposes of this test.
15+
ActionDispatch::TestResponse.define_method(:attributes_for_super_diff) { {request: request} }
16+
17+
expect(response).to be_bad_request
18+
RUBY
19+
program =
20+
make_rspec_action_dispatch_program(snippet, color_enabled: color_enabled)
21+
22+
expected_output =
23+
build_expected_output(
24+
color_enabled: color_enabled,
25+
snippet: 'expect(response).to be_bad_request',
26+
newline_before_expectation: true,
27+
expectation:
28+
proc do
29+
line do
30+
plain ' Expected '
31+
actual '#<ActionDispatch::TestResponse request: #<ActionDispatch::TestRequest GET "http://test.host/" for 0.0.0.0>>'
32+
end
33+
34+
line do
35+
plain 'to return a truthy result for '
36+
expected 'bad_request?'
37+
plain ' or '
38+
expected 'bad_requests?'
39+
end
40+
end
41+
)
42+
43+
expect(program).to produce_output_when_run(expected_output).in_color(
44+
color_enabled
45+
)
46+
end
47+
end
48+
end
449
end

0 commit comments

Comments
 (0)