Class: RSpec::Core::Ordering::ConfigurationManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/core/ordering.rb

Overview

Note:

This is not intended to be used externally. Use the APIs provided by `RSpec::Core::Configuration` instead.

Manages ordering configuration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigurationManager



110
111
112
113
114
115
# File 'lib/rspec/core/ordering.rb', line 110

def initialize
  @ordering_registry = Registry.new(self)
  @seed = rand(0xFFFF)
  @seed_forced = false
  @order_forced = false
end

Instance Attribute Details

#ordering_registryObject (readonly)

Returns the value of attribute ordering_registry



108
109
110
# File 'lib/rspec/core/ordering.rb', line 108

def ordering_registry
  @ordering_registry
end

#seedObject

Returns the value of attribute seed



108
109
110
# File 'lib/rspec/core/ordering.rb', line 108

def seed
  @seed
end

Instance Method Details

#force(hash) ⇒ Object



140
141
142
143
144
145
146
147
148
149
# File 'lib/rspec/core/ordering.rb', line 140

def force(hash)
  if hash.key?(:seed)
    self.seed = hash[:seed]
    @seed_forced  = true
    @order_forced = true
  elsif hash.key?(:order)
    self.order = hash[:order]
    @order_forced = true
  end
end

#order=(type) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/rspec/core/ordering.rb', line 127

def order=(type)
  order, seed = type.to_s.split(':')
  @seed = seed.to_i if seed

  ordering_name = if order.include?('rand')
                    :random
                  elsif order == 'defined'
                    :defined
                  end

  register_ordering(:global, ordering_registry.fetch(ordering_name)) if ordering_name
end

#register_ordering(name, strategy = Custom.new(Proc.new { |l| yield l })) ⇒ Object



151
152
153
154
# File 'lib/rspec/core/ordering.rb', line 151

def register_ordering(name, strategy=Custom.new(Proc.new { |l| yield l }))
  return if @order_forced && name == :global
  ordering_registry.register(name, strategy)
end

#seed_used?Boolean



117
118
119
# File 'lib/rspec/core/ordering.rb', line 117

def seed_used?
  ordering_registry.used_random_seed?
end