vendredi 10 juillet 2020

Rails - Minitest + Capybara + Selenium - Test destroy action

I am new to Minitest / Capybara / Selenium. But I want to test my destroy Controller action. I an trying the following and it is failing

test "destroy" do
  companies_count = Company.count
  visit company_path(@company)
  click_on "Delete"
  page.driver.browser.switch_to.alert.accept
  assert_equal (companies_count - 1), Company.count
end

OUTPUT:

    test_destroy                                                    FAIL (2.17s)
    Expected: 6
      Actual: 7

Tried this way also.

test "destroy" do
    assert_difference('Company.count', -1) do
      delete company_url(@company)
    end
end

OUTPUT:

Minitest::UnexpectedError:         NoMethodError: undefined method `delete' for #<CompaniesControllerTest:0x000056171e550038>

Can someone help me in testing my destroy action?

Aucun commentaire:

Enregistrer un commentaire