3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

rails_helper.rb に require 'capybara/rails' と require 'capybara/rspec' は書かなくていい

Posted at

capybara gem の README の SetupUsing Capybara with RSpec の段落には次のように、require 'capybara/rails'require 'capybara/rspec' を追記してねと書かれています。

If the application that you are testing is a Rails app, add this line to your test helper file:

require 'capybara/rails'

Load RSpec 3.5+ support by adding the following line (typically to your spec_helper.rb file):

require 'capybara/rspec'

なので、いつも rails_helper.rb に require 'capybara/rails'require 'capybara/rspec' を追記していました。
しかし、rspec-rails gem のコードを読んだところ、rails_helper.rb もしくは spec_helper.rb に require 'capybara/rails'require 'capybara/rspec' を書く必要はないということがわかりました。

なぜかというと、rails_helper.rb に書かれている require 'rspec/rails' の中の require 'rspec/rails/vendor/capybara'require 'capybara/rails'require 'capybara/rspec' が書かれているからです。

コードへのリンク

rails_helper.rb の7行目に require 'rspec/rails'

rspec-rails/lib/rspec/rails.rb の15行目に require 'rspec/rails/vendor/capybara'

rspec-rails/lib/rspec/rails/vendor/capybara.rb の2行目に require 'capybara/rspec' 、7行目に require 'capybara/rails'

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?