Sha256: 626eaa8128fdd23bae83decdb4b9415eb28b1786043e96ea3a20b920ae39d672

Contents?: true

Size: 1.94 KB

Versions: 17

Compression:

Stored size: 1.94 KB

Contents

Capybara::SpecHelper.spec "#choose" do
  before do
    @session.visit('/form')
  end

  it "should choose a radio button by id" do
    @session.choose("gender_male")
    @session.click_button('awesome')
    expect(extract_results(@session)['gender']).to eq('male')
  end

  it "should choose a radio button by label" do
    @session.choose("Both")
    @session.click_button('awesome')
    expect(extract_results(@session)['gender']).to eq('both')
  end

  it "casts to string" do
    @session.choose("Both")
    @session.click_button(:'awesome')
    expect(extract_results(@session)['gender']).to eq('both')
  end

  context "with a locator that doesn't exist" do
    it "should raise an error" do
      msg = "Unable to find radio button \"does not exist\""
      expect do
        @session.choose('does not exist')
      end.to raise_error(Capybara::ElementNotFound, msg)
    end
  end

  context "with a disabled radio button" do
    it "should raise an error" do
      expect do
        @session.choose('Disabled Radio')
      end.to raise_error(Capybara::ElementNotFound)
    end
  end

  context "with :exact option" do
    it "should accept partial matches when false" do
      @session.choose("Mal", :exact => false)
      @session.click_button('awesome')
      expect(extract_results(@session)['gender']).to eq('male')
    end

    it "should not accept partial matches when true" do
      expect do
        @session.choose("Mal", :exact => true)
      end.to raise_error(Capybara::ElementNotFound)
    end
  end

  context "with `option` option" do
    it "can check radio buttons by their value" do
      @session.choose('form[gender]', :option => "male")
      @session.click_button('awesome')
      expect(extract_results(@session)['gender']).to eq("male")
    end

    it "should raise an error if option not found" do
      expect do
        @session.choose('form[gender]', :option => "hermaphrodite")
      end.to raise_error(Capybara::ElementNotFound)
    end
  end
end

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/capybara-2.4.4/lib/capybara/spec/session/choose_spec.rb
capybara-2.6.2 lib/capybara/spec/session/choose_spec.rb
capybara-2.6.1 lib/capybara/spec/session/choose_spec.rb
capybara-2.6.0 lib/capybara/spec/session/choose_spec.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/capybara-2.4.4/lib/capybara/spec/session/choose_spec.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/capybara-2.4.4/lib/capybara/spec/session/choose_spec.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/capybara-2.4.4/lib/capybara/spec/session/choose_spec.rb
capybara-2.5.0 lib/capybara/spec/session/choose_spec.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/capybara-2.4.4/lib/capybara/spec/session/choose_spec.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/capybara-2.4.4/lib/capybara/spec/session/choose_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/capybara-2.4.4/lib/capybara/spec/session/choose_spec.rb
capybara-2.4.4 lib/capybara/spec/session/choose_spec.rb
capybara-2.4.3 lib/capybara/spec/session/choose_spec.rb
capybara-2.4.2 lib/capybara/spec/session/choose_spec.rb
capybara-2.4.1 lib/capybara/spec/session/choose_spec.rb
capybara-2.4.0 lib/capybara/spec/session/choose_spec.rb
capybara-2.3.0 lib/capybara/spec/session/choose_spec.rb