Giter Site home page Giter Site logo

rails_exam01_bugfix's People

Contributors

tadao050707 avatar yuji91 avatar yukitamura14 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rails_exam01_bugfix's Issues

Rspecの設定(SystemSpecの導入、実行時にブラウザ表示、非表示の切り替え設定)

FeatureSpecではなく、SystemSpecを利用する

[参考URL] https://blog.jnito.com/entry/2018/03/12/053153

※ 2017年10月にRspec 3.7でリリースされた様です。
http://rspec.info/ja/blog/2017/10/rspec-3-7-has-been-released/


手順1. gem rspec-rails を追加し、rails generate rspec:install でファイルを初期化
[参考URL] https://github.com/rspec/rspec-rails

手順2. SystemSpecは rails generate 非対応なので、手動でファイルを生成する
[参考URL] https://everydayrails.com/2018/01/08/rspec-3.7-system-tests.html

手順3. テスト実行時に発生する警告への対応
selenium-webdriverとchromedriver-helperのgemは実行時に警告が出る。
SeleniumHQ/selenium#7125
webdriversに統合されたので入れ替える。
https://stackoverflow.com/questions/55970418/capyabra-selenium-chrome-driver-settings
スクリーンショット 2019-07-07 午後4 37 14
スクリーンショット 2019-07-07 午後4 34 33

手順4. テスト実行時に使用するwebdriverの設定を追加
(rails_helperに記載すると、どこに設定があるのか分かりづらい。
spec/support以下を読み込む様にして、別途設定を定義したファイルを作成する)

・driven_by(:selenium_chrome) 
--> テスト実行時にブラウザが起動されます。byebugやsleepで停止して画面の要素を確認できます。

・driven_by(:selenium_chrome_headless)
--> ブラウザを起動せずにテストが実施されます。

手順5. その他の設定を追加
・focus: trueの設定を入れる
https://kossy-web-engineer.hatenablog.com/entry/2019/01/16/071517

・specの実行結果をドキュメント形式で出力する設定を .rspec に追加
https://shinkufencer.hateblo.jp/entry/2019/01/21/233000

.rspec -format

手順6. FactoryBotを使用するためgemを追加
・rails consoleでも動作確認できるように、gemfileでは :testだけでなく :developmentにも定義
・rails_helperに config.include FactoryBot::Syntax::Methods を追加
FactoryBot.build(:blog)build(:blog) と省略して記載できる様にした)


[詰まったところ]
・EverydayRailsのSystemSpecのサンプルコードに誤りがあった
https://everydayrails.com/2018/01/08/rspec-3.7-system-tests.html
スクリーンショット 2019-07-07 午後3 59 56

RSpec.system だと NoMethodError: systemになるので、RSpec.describe で使用すること

require 'rails_helper'

RSpec.describe "Test name", type: :system do
  it "does something" do
    # ... your test
  end
end

・specの実行結果をドキュメント形式で出力する .rspec が見当たらない
--> .gitignore で管理対象外になっていたので、新規作成して対応

Rubocopの設定

.rubocop.yml の設定について

・railsの公式Rubocop設定(20190602時点)
https://github.com/rails/rails/blob/master/.rubocop.yml
--> [注意点1] Error: The Layout/FirstParameterIndentation cop has been renamed to Layout/IndentFirstArgument が発生するので1点Renameする必要あり
--> [注意点2] performanceを検証しないのであれば require: rubocop-performance を削除する必要あり

--> rubocop実行時の結果の差分は、下記のfrozen_string_literalのチェックくらいだった。
(詳しくは未検証)

# frozen_string_literal: true のチェックを入れるべきか?
https://teratail.com/questions/74592

入れた方が良いという意見もあるが、入れないことでクリティカルな問題になるとは思えないし、内容の複雑さが増してしまうことから今回は導入しない。(方がいいのかな、という個人的意見です。)


rubocopの使用gemについて

現状: bundle install実行時に "gem rubocop-rails" が推奨される

https://github.com/toshimaru/rubocop-rails
--> 下記に移管した旨がREADMEに記載されている

https://github.com/toshimaru/rubocop-rails_config
--> 下記の内容を記載する必要がある
inherit_gem:
rubocop-rails_config:
- config/rails.yml

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.