0
0

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 3 years have passed since last update.

しておくと便利かもしれないRailsの設定

Posted at

備忘録。Railsのバージョンは6.1。環境はWSL

開発環境周り

ログをターミナルに出力する

config/environments/development.rb
config.logger = Logger.new(STDOUT)

編集を開発サーバーに即反映

config/environments/development.rb
config.file_watcher = ActiveSupport::FileUpdateChecker

js更新しても勝手にコンパイルしない

WSLだと重い

config/webpacker.yml
development:
  <<: *default
  compile: false

assets(css)のデバッグモードオフ

何故かcssが開発途中で反映されなくなるため

config/environments/development.rb
config.assets.debug = false

View周り

formのlocal(remote)をデフォルトでtrue

基本的にvalidationエラーとか非同期で返すため

config/application.rb
class Application < Rails::Application
  config.action_view.form_with_generates_remote_forms = true
end

テスト周り

逆マッチャーの定義

spec/rails_helper.rb
RSpec::Matchers.define_negated_matcher :not_change, :change
RSpec::Matchers.define_negated_matcher :not_match, :match

selenium chrome

spec/rails_helper.rb
Capybara.server = :puma
Capybara.javascript_driver = :selenium_chrome

Capybara.register_driver :selenium_chrome_headless do |app|
  options = ::Selenium::WebDriver::Chrome::Options.new
  options.add_argument '--no-sandbox'
  options.add_argument '--headless'
  options.add_argument '--window-size=1400,1400'
  options.add_argument '--disable-dev-shm-usage'
  Capybara::Selenium::Driver.new app, browser: :chrome, options: options
end

RSpec.configure do |config|
  config.before(:each, type: :system) do
    driven_by :selenium_chrome_headless
  end
end

factoryの生成場所指定

rails g factory_bot:modelするときの

config/application.rb
class Application < Rails::Application
  config.generators do |g|
    g.factory_bot dir: 'spec/factories'
  end
end
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?