Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

In a Rails app using minitest and capybara, how do I assert that a html table element…

  1. User

    In a Rails app using minitest and capybara, how do I assert that a html table element has properly been rendered on the page?

  2. Assistant

    You can use Capybara's built-in has_table? method to check if a specific table exists on the page. Here's an example test that checks if a table with the id "products-table" has been rendered:

    require "test_helper"
    
    class ProductsPageTest < Capybara::Rails::TestCase
      test "displays products table" do
        visit products_path
        assert has_table?("products-table")
      end
    end
    

    If you also want to check the contents of the table, you can use Capybara's within_table method to scope your assertions. For example, to check if a table row with the text "Product A" exists in the "products-table", you can do:

    assert within_table("products-table") { has_content?("Product A") }