@@ -177,16 +177,17 @@ def test_to_s_with_media_filter_preserves_list_when_applicable
177177 css = '@media screen, print { body { color: red; } } @media handheld { p { margin: 0; } }'
178178 sheet = Cataract ::Stylesheet . parse ( css )
179179
180- # When filtering to :screen, should only output the screen rule
181- # But since original was "screen, print", we might serialize as just "@media screen"
182- # This is acceptable - we only preserve the list when ALL members are included
183180 output = sheet . to_s ( media : :screen )
181+ reparsed = Cataract ::Stylesheet . parse ( output )
184182
185- # Should contain screen rule but NOT handheld
186- assert_match ( /@media screen/ , output )
187- assert_match ( /body \{ color: red; \} / , output )
188- refute_match ( /handheld/ , output )
189- refute_match ( /p \{ margin: 0; \} / , output )
183+ # Filtering to :screen keeps the rule, and its "screen, print" list is
184+ # carried through intact rather than narrowed to just the media asked for.
185+ assert_has_selector 'body' , reparsed , media : :screen
186+ assert_has_selector 'body' , reparsed , media : :print
187+ assert_has_property ( { color : 'red' } , reparsed . with_media ( :screen ) . with_selector ( 'body' ) . first )
188+
189+ # The handheld rule is dropped entirely.
190+ assert_empty reparsed . with_selector ( 'p' ) . to_a
190191 end
191192
192193 def test_to_s_with_multiple_media_filter_preserves_list
0 commit comments