Add error description for style filter

This commit is contained in:
Thomas Walpole 2018-12-06 13:46:53 -08:00
parent 3da176039d
commit 00dfda0d6a
2 changed files with 21 additions and 0 deletions

View File

@ -50,6 +50,15 @@ module Capybara
end
desc << " with id #{options[:id]}" if options[:id]
desc << " with classes [#{Array(options[:class]).join(',')}]" if options[:class]
desc << case options[:style]
when String
" with style attribute #{options[:style].inspect}"
when Regexp
" with style attribute matching #{options[:style].inspect}"
when Hash
" with styles #{options[:style].inspect}"
else ''
end
desc << selector.description(node_filters: show_for[:node], **options)
desc << ' that also matches the custom filter block' if @filter_block && show_for[:node]
desc << " within #{@resolved_node.inspect}" if describe_within?

View File

@ -41,14 +41,26 @@ Capybara::SpecHelper.spec '#has_css?' do
context ':style option' do
it 'should support String' do
expect(@session).to have_css('p', style: 'line-height: 25px;')
expect do
expect(@session).to have_css('p', style: 'display: not_valid')
end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /style attribute "display: not_valid"/)
end
it 'should support Regexp' do
expect(@session).to have_css('p', style: /-height: 2/)
expect do
expect(@session).to have_css('p', style: /not_valid/)
end.to raise_error(RSpec::Expectations::ExpectationNotMetError, %r{style attribute matching /not_valid/})
end
it 'should support Hash', requires: [:css] do
expect(@session).to have_css('p', style: { 'line-height': '25px' })
expect do
expect(@session).to have_css('p', style: { 'line-height': '30px' })
end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /with styles \{:"line-height"=>"30px"\}/)
end
end