module RailsStuff::TestHelpers
Collection of RSpec configurations and helpers for better experience.
Public Instance Methods
big_decimal()
click to toggle source
Make BigDecimal`s more readable.
# File lib/rails_stuff/test_helpers.rb, line 27 def big_decimal require 'bigdecimal' BigDecimal.class_eval do alias_method :inspect_orig, :inspect alias_method :inspect, :to_s end end
i18n()
click to toggle source
Raise all translation errors, to not miss any of translations. Make sure to set `config.action_view.raise_on_missing_translations = true` in `config/environments/test.rb` yourself.
# File lib/rails_stuff/test_helpers.rb, line 43 def i18n return unless defined?(I18n) I18n.config.exception_handler = ->(exception, _locale, _key, _options) do raise exception.respond_to?(:to_exception) ? exception.to_exception : exception end end
setup(only: nil, except: nil)
click to toggle source
# File lib/rails_stuff/test_helpers.rb, line 8 def setup(only: nil, except: nil) items = instance_methods.map(&:to_s) - %w[setup] items -= Array.wrap(except).map(&:to_s) if except if only only = Array.wrap(only).map(&:to_s) items &= only items += only end items.each { |item| public_send(item) } end
thread()
click to toggle source
Raise errors from failed threads.
# File lib/rails_stuff/test_helpers.rb, line 36 def thread Thread.abort_on_exception = true end