File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
spec/support/shared_examples Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33shared_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
449end
You can’t perform that action at this time.
0 commit comments