aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/data_modifier.rb2
-rw-r--r--spec/support/data_modifier/box.rb5
-rw-r--r--spec/support/data_modifier/hash.rb16
-rw-r--r--spec/support/random.rb8
4 files changed, 26 insertions, 5 deletions
diff --git a/spec/support/data_modifier.rb b/spec/support/data_modifier.rb
index 7fb0db6f6..2b3b00ac5 100644
--- a/spec/support/data_modifier.rb
+++ b/spec/support/data_modifier.rb
@@ -1,4 +1,5 @@
require_relative 'data_modifier/enum'
+require_relative 'data_modifier/hash'
module Support
module DataModifier
module InstanceMethods
@@ -48,4 +49,5 @@ end
RSpec.configure do | c |
c.include Support::DataModifier::InstanceMethods, type: :checksum
+ c.include Support::DataModifier::InstanceMethods, type: :model
end
diff --git a/spec/support/data_modifier/box.rb b/spec/support/data_modifier/box.rb
index 0fb95f743..0847b628c 100644
--- a/spec/support/data_modifier/box.rb
+++ b/spec/support/data_modifier/box.rb
@@ -1,3 +1,4 @@
+require_relative 'hash'
module Support
module DataModifier
module Box
@@ -7,9 +8,7 @@ module Support
class << self
def unbox atts
- atts.inject Hash.new do | h, (k,v) |
- h.merge(k => value_of(v))
- end
+ Hash.map_values(atts, method(:value_of))
end
def value_of v
self === v ? v.value : v
diff --git a/spec/support/data_modifier/hash.rb b/spec/support/data_modifier/hash.rb
new file mode 100644
index 000000000..05da3cf4f
--- /dev/null
+++ b/spec/support/data_modifier/hash.rb
@@ -0,0 +1,16 @@
+module Support
+ module DataModifier
+ module Hash extend self
+ def map_values hashy, f=nil, &fn
+ raise ArgumentError, "need block or function arg" unless f = fn || f
+ hashy.inject({}){ |h, (k,v)| h.merge(k => f.(v)) }
+ end
+ def first_values ary_hash
+ map_values(ary_hash, &:first)
+ end
+ def last_values ary_hash
+ map_values(ary_hash, &:last)
+ end
+ end
+ end
+end
diff --git a/spec/support/random.rb b/spec/support/random.rb
index f0168b9ef..59e1a1475 100644
--- a/spec/support/random.rb
+++ b/spec/support/random.rb
@@ -7,8 +7,12 @@ module Support
SecureRandom.hex
end
- def random_int
- (random_number * PRETTY_LARGE_INT).to_i
+ def random_element from
+ from[random_int(from.size)]
+ end
+
+ def random_int max_plus_one=PRETTY_LARGE_INT
+ (random_number * max_plus_one).to_i
end
def random_number