Add error description for style filter
This commit is contained in:
parent
3da176039d
commit
00dfda0d6a
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue