できる!Rails
Usefull Helper methods for Ruby on Rails
Rails version support
Rails 5.1 は ~> 0.1.0
Installation
Add this line to your application's Gemfile:
gem 'dekiru'
And then execute:
$ bundle
Or install it yourself as:
$ gem install dekiru
Capybara Helpers
以下の設定をすると Capybara 用のヘルパーメソッドが使えるようになる。
require 'dekiru/capybara/helpers'
RSpec.configure do |config|
config.include Dekiru::Capybara::Helpers, type: :feature
end
examples
# Ajax処理の終了待ち
click_link 'Ajax link!'
wait_for_ajax
expect(page).to have_content 'created element!'
# Bootstrap3 のモーダルの出現終了待ち(待たないとモーダル内のノードのクリックに失敗することがある)
wait_for_event('shown.bs.modal') do
click_link 'Open bootstrap3 modal'
end
click_on 'Button in modal'
Capybara Matchers
以下の設定をすると Capybara 用のマッチャーが使えるようになる。
require 'dekiru/capybara/matchers'
RSpec.configure do |config|
config.include Dekiru::Capybara::Matchers, type: :feature
end
examples
# javascriptエラーがあったらテスト失敗するように
RSpec.configure do |config|
config.after(:each, type: :feature) do |example|
if example.[:js] == true
expect(page).to have_no_js_errors
end
end
end
Rake Task
以下の設定をすると Rake タスクの実行前後にログ出力されるようになる。(Ruby2.4 以降が必要)
In Rakefile:
require_relative 'config/application'
require 'dekiru/task_with_logger'
Rails.application.load_tasks
In myapp.rake:
using TaskWithLogger
namespace :myapp do
desc 'dekiru'
task dekiru: :environment do
puts 'dekiru'
end
end
以下の設定をすると db:migrate タスクの実行前に競合がチェックされる。
In Rakefile:
require_relative 'config/application'
Rails.application.load_tasks
Rake::Task['db:migrate'].enhance(['db:migrate:check_conflict']) if Rails.env.development?
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request