Sha256: 557af9eac193157f7787b8e74f508097c8282e37ff90bb26b9a2e8ddd00e199e

Contents?: true

Size: 1.48 KB

Versions: 6

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

Capybara::SpecHelper.spec '#matches_style?', requires: [:css] do
  before do
    @session.visit('/with_html')
  end

  it 'should be true if the element has the given style' do
    expect(@session.find(:css, '#first')).to match_style(display: 'block')
    expect(@session.find(:css, '#first').matches_style?(display: 'block')).to be true
    expect(@session.find(:css, '#second')).to match_style('display' => 'inline')
    expect(@session.find(:css, '#second').matches_style?('display' => 'inline')).to be true
  end

  it 'should be false if the element does not have the given style' do
    expect(@session.find(:css, '#first').matches_style?('display' => 'inline')).to be false
    expect(@session.find(:css, '#second').matches_style?(display: 'block')).to be false
  end

  it 'allows Regexp for value matching' do
    expect(@session.find(:css, '#first')).to match_style(display: /^bl/)
    expect(@session.find(:css, '#first').matches_style?('display' => /^bl/)).to be true
    expect(@session.find(:css, '#first').matches_style?(display: /^in/)).to be false
  end

  # rubocop:disable Capybara/MatchStyle
  it 'deprecated has_style?' do
    expect { have_style(display: /^bl/) }.to \
      output(/have_style is deprecated/).to_stderr

    el = @session.find(:css, '#first')
    allow(Capybara::Helpers).to receive(:warn).and_return(nil)
    el.has_style?('display' => /^bl/)
    expect(Capybara::Helpers).to have_received(:warn)
  end
  # rubocop:enable Capybara/MatchStyle
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/capybara-3.40.0/lib/capybara/spec/session/matches_style_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/capybara-3.40.0/lib/capybara/spec/session/matches_style_spec.rb
capybara-3.40.0 lib/capybara/spec/session/matches_style_spec.rb
capybara-3.39.2 lib/capybara/spec/session/matches_style_spec.rb
capybara-3.39.1 lib/capybara/spec/session/matches_style_spec.rb
capybara-3.39.0 lib/capybara/spec/session/matches_style_spec.rb