J'essaye de tester l'action destroy d'un article avec capybara et rspec. Dans le fichier de vue j'inclure une alerte pour le lien de suppression et voici mon fichier spec:Echec du test avec capybara et rspec
# spec/features/article_view_spec.rb
require 'rails_helper'
describe 'the article view', type: :feature do
let(:article) do
Article.create(title: 'a title', body: 'This is a sample body for a sample article.')
end
before(:each) do
article.reload
visit root_path
end
.
.
.
it 'deletes an article', js: true do
visit article_path(article)
find(:xpath, '//link[@href="/articles/1"]').click
sleep 1.seconds
alert = page.driver.browser.switch_to.alert
expect { alert.accept }.to change(Article, :count).by(-1)
end
mais renvoie cette erreur:
Failures:
1) the article view deletes an article
Failure/Error: @article = Article.find(params[:id])
ActiveRecord::RecordNotFound:
Couldn't find Article with 'id'=1
# ./app/controllers/articles_controller.rb:9:in `show'
# ------------------
# --- Caused by: ---
# Capybara::ElementNotFound:
# Unable to find xpath "//link[@href=\"/articles/1\"]"
# ./spec/features/article_view_spec.rb:40:in `block (2 levels) in <top (required)>'
Finished in 4.68 seconds (files took 1.83 seconds to load)
5 examples, 1 failure
Failed examples:
rspec ./spec/features/article_view_spec.rb:38 # the article view deletes an article
par la façon dont j'utilise le sélénium WebDriver. quel est le problème?
Merci beaucoup. et j'ai trouvé une instruction pour configurer la spec/rails_helper.rb sur http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/ – Ahmad
Bienvenue. –