smptmhr / el-training

株式会社万葉の新入社員教育用カリキュラム
https://everyleaf.com/
2 stars 0 forks source link

Step10 テストの作成 #22

Closed smptmhr closed 2 years ago

smptmhr commented 2 years ago

rspecのインストール

RspecとFactorybotをGemfileに追加 Rspecを設定 【Rspec】RspecのインストールやRailsで使うための準備や実行方法

デフォルトのtestを削除

今後のテストはRSPCを使って行うため、使用しないデフォルトのtestディレクトリを削除する。

テストの実行

実行方法

bundle exec rspec -f d spec/○○/○○.rb

実際に動作してることが確認できる。 スクリーンショット 2022-06-09 14 14 55

smptmhr commented 2 years ago

~capybara-webkitのインストールでハマってる~

capybara-webkitは不要だった

selenium-webdriverのみでwebドライバーに必要な機能は十分なので capybara-webkitを使用する必要がなかった。

ハマった箇所(capybara-webkiを使用しないことで回避)

~system specを使用するのにcapybara-webkitなるgemが必要らしい。~ ~そしてcapybara-webkitをインストールするにはqtが必要らしい。~

~バージョンは5.5(qt@5.5)に指定するらしい。~ ~以下でqtのインストールを試した。~

cd $( brew --prefix )/Homebrew/Library/Taps/homebrew/homebrew-core
git checkout 9ba3d6ef8891e5c15dbdc9333f857b13711d4e97 Formula/qt@5.5.rb
brew install qt@5.5

ここでエラー

Warning: No available formula with the name "qt@5.5". Did you mean qt@5?
==> Searching for similarly named formulae...
This similarly named formula was found:
qt@5 ✔
To install it, run:
  brew install qt@5 ✔
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

qt@5.5は無いらしいのでqt@5をインストール

$ brew install qt@5
Warning: qt@5 5.15.3 is already installed and up-to-date.
To reinstall 5.15.3, run:
  brew reinstall qt@5

今はqt4がqmakeにリンクされているのでqt5にリンクし直す

brew unlink qt@4
brew link --force qt@5

これでbundle installの準備が整ったと思い作業ディレクトリに戻って Gemfileのgroup :development, :test do内に'capybara-webkit'を追加

  # Capybara本体
  gem 'capybara'
  # Capybaraが利用するドライバ
  gem 'selenium-webdriver'
  gem 'capybara-webkit'

bundle install

ここでまたエラー

An error occurred while installing capybara-webkit (1.15.1), and Bundler cannot continue.

In Gemfile:
  capybara-webkit

参考 https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit#homebrew https://obel.hatenablog.jp/entry/20200420/1587324600 https://qiita.com/morrr/items/0e24251c049180218db4

smptmhr commented 2 years ago

system spec

メモ

visit tasks_urlと書くと以下の様なエラーでspecがページに到達できない。

Failure/Error: visit tasks_url

Net::ReadTimeout:
  Net::ReadTimeout with #<Socket:(closed)>

visit tasks_pathと書くことによって解決。 (根本原因は不明)

参考

specのざっくりの書き方 specチートシート headless設定