Rspec stuff we use over and over again
Add this line to your application's Gemfile:
gem 'utensils', :group => :test
- Create
spec/support/utensils.rb
- Add whichever bits you need:
require 'utensils/capybara_extensions'
require 'utensils/capybara_javascript'
require 'utensils/database_cleaner'
require 'utensils/email'
require 'utensils/factory_bot'
require 'utensils/omniauth'
require 'utensils/upload_macros'
Allows you to use active record objects with capybara finders
page.within(post) { click_link('Edit') }
page.find(book_2).drag_to(page.find(book_1))
Switches javascript driver to poltergeist, and blacklists slow external JS
To use Poltegeist with remote debugging, run test with POLTERGEIST_DEBUG
set.
POLTERGEIST_DEBUG=1 rspec spec/features/broken_feature_spec.rb
Sets up rspec to use database_cleaner instead of transactional fixtures
Clears ActionMailer::Base.deliveries
before each spec and
includes https://github.com/bmabey/email-spec helpers.
Use shorthand for FactoryBot, ie:
# instead of:
FactoryBot.create(:post)
# use:
create(:post)
Puts ominauth in test mode and provides the following macros:
stub_oauth(:facebook, info: { name: 'Bob' })
stub_oauth_error(:facebook)
login(user)
Resets timecop after each spec
Provides fixture_file and fixture_file_path helper pointing to spec/fixtures directory
fixture_file_path('dummy.jpg') # 'spec/fixtures/dummy.jpg'
Photo.create(:file => fixture_file('dummy.jpg')) # attaches File spec/fixtures/dummy.jpg