rspec-rails
インストール
code:Gemfile
group :development, :test do
gem 'rspec-rails', '~> 4.0.1'
end
2. 以下のコマンドを実行する
code:shell
$ bundle install
$ rails generate rspec:install
テストの実行
code:shell
$ bundle exec rspec
# テスト結果をいい感じに整形する
$ bundle exec rspec --format documentation
Model specs
Request specs
インストール
code:Gemfile
group :development, :test do
gem 'factory_bot_rails'
end
spec/rails_helper.rbあたりに以下の記述を追加する
code:ruby
RSpec.configure do |config|
...
config.include FactoryBot::Syntax::Methods
...
end
Factoryの定義
spec/factories.rbかspec/factories/*.rbあたりで定義しておくと、自動的に読み込んでくれる
code:ruby
FactoryBot.define do
factory :user, class: User do
name "hoge"
end
end
参考