This file is indexed.

/usr/lib/ruby/vendor_ruby/capybara/spec/session/first_spec.rb is in ruby-capybara 2.5.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
Capybara::SpecHelper.spec '#first' do
  before do
    @session.visit('/with_html')
  end

  it "should find the first element using the given locator" do
    expect(@session.first('//h1').text).to eq('This is a test')
    expect(@session.first("//input[@id='test_field']")[:value]).to eq('monkey')
  end

  it "should return nil when nothing was found" do
    expect(@session.first('//div[@id="nosuchthing"]')).to be_nil
  end

  it "should accept an XPath instance" do
    @session.visit('/form')
    @xpath = XPath::HTML.fillable_field('First Name')
    expect(@session.first(@xpath).value).to eq('John')
  end

  context "with css selectors" do
    it "should find the first element using the given selector" do
      expect(@session.first(:css, 'h1').text).to eq('This is a test')
      expect(@session.first(:css, "input[id='test_field']")[:value]).to eq('monkey')
    end
  end

  context "with xpath selectors" do
    it "should find the first element using the given locator" do
      expect(@session.first(:xpath, '//h1').text).to eq('This is a test')
      expect(@session.first(:xpath, "//input[@id='test_field']")[:value]).to eq('monkey')
    end
  end

  context "with css as default selector" do
    before { Capybara.default_selector = :css }
    it "should find the first element using the given locator" do
      expect(@session.first('h1').text).to eq('This is a test')
      expect(@session.first("input[id='test_field']")[:value]).to eq('monkey')
    end
  end

  context "with visible filter" do
    it "should only find visible nodes when true" do
      expect(@session.first(:css, "a#invisible", :visible => true)).to be_nil
    end

    it "should find nodes regardless of whether they are invisible when false" do
      expect(@session.first(:css, "a#invisible", :visible => false)).not_to be_nil
      expect(@session.first(:css, "a#visible", :visible => false)).not_to be_nil
    end

    it "should find nodes regardless of whether they are invisible when :all" do
      expect(@session.first(:css, "a#invisible", :visible => :all)).not_to be_nil
      expect(@session.first(:css, "a#visible", :visible => :all)).not_to be_nil
    end

    it "should find only hidden nodes when :hidden" do
      expect(@session.first(:css, "a#invisible", :visible => :hidden)).not_to be_nil
      expect(@session.first(:css, "a#visible", :visible => :hidden)).to be_nil
    end

    it "should find only visible nodes when :visible" do
      expect(@session.first(:css, "a#invisible", :visible => :visible)).to be_nil
      expect(@session.first(:css, "a#visible", :visible => :visible)).not_to be_nil
    end

    it "should default to Capybara.ignore_hidden_elements" do
      Capybara.ignore_hidden_elements = true
      expect(@session.first(:css, "a#invisible")).to be_nil
      Capybara.ignore_hidden_elements = false
      expect(@session.first(:css, "a#invisible")).not_to be_nil
      expect(@session.first(:css, "a")).not_to be_nil
    end
  end

  context "within a scope" do
    before do
      @session.visit('/with_scope')
    end

    it "should find the first element using the given locator" do
      @session.within(:xpath, "//div[@id='for_bar']") do
        expect(@session.first('.//form')).not_to be_nil
      end
    end
  end

  context "with Capybara.wait_on_first_by_default", requires: [:js] do
    before do
      @session.visit('/with_js')
    end

    it "should not wait if false" do
      Capybara.wait_on_first_by_default = false
      @session.click_link('clickable')
      expect(@session.first(:css, 'a#has-been-clicked')).to be_nil
    end

    it "should wait for at least one match if true" do
      Capybara.wait_on_first_by_default = true
      @session.click_link('clickable')
      expect(@session.first(:css, 'a#has-been-clicked')).not_to be_nil
    end

    it "should return nil after waiting if no match" do
      Capybara.wait_on_first_by_default = true
      @session.click_link('clickable')
      expect(@session.first(:css, 'a#not-a-real-link')).to be_nil
    end
  end
end