class Fixturama::Changes
@private Registry of changes (stubs and seeds)
Constants
- TYPES
Match option keys to the type of an item
Public Class Methods
new()
click to toggle source
# File lib/fixturama/changes.rb 68 def initialize 69 @changes = [] 70 end
Public Instance Methods
add(options)
click to toggle source
Adds new change to the registry @param [Hash] options @return [Fixturama::Changes] @raise [Fixturama::FixtureError] if the options cannot be processed
# File lib/fixturama/changes.rb 42 def add(options) 43 options = Hash(options).transform_keys(&:to_sym) 44 types = options.keys.map { |key| TYPES[key] }.compact.uniq 45 raise "Wrong count" unless types.count == 1 46 47 @changes << types.first.new(options) 48 self 49 rescue FixtureError => err 50 raise err 51 rescue StandardError => err 52 raise FixtureError.new("an operation", options, err) 53 end
call(example)
click to toggle source
Apply all registered changes to the RSpec example @param [RSpec::Core::Example] example @return [self]
# File lib/fixturama/changes.rb 58 def call(example) 59 @changes 60 .group_by(&:key) 61 .values 62 .map { |changes| changes.reduce :merge } 63 .each { |change| change.call(example) } 64 end