Skip to content

Commit

Permalink
made struct hashlike fuzz testing optional (use FULL_SPECS=1 to run)
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip (flip) Kromer committed Jun 7, 2011
1 parent 8f6af3d commit 301f1ec
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 58 deletions.
1 change: 0 additions & 1 deletion lib/gorillib/hashlike.rb
Expand Up @@ -821,4 +821,3 @@ def self.included(base)

end
end

25 changes: 1 addition & 24 deletions lib/gorillib/receiver/acts_as_hash.rb
Expand Up @@ -119,30 +119,6 @@ def delete(key, &block)
end
end

# # Hashlike#==
# #
# # Equality -- Two hashes are equal if they contain the same number of keys,
# # and the value corresponding to each key in the first hash is equal (using
# # <tt>==</tt>) to the value for the same key in the second. If +obj+ is not a
# # Hashlike, attempt to convert it using +to_hash+ and return <tt>obj ==
# # hsh</tt>.
# #
# # Does not take a default value comparion into account.
# #
# # @example
# # h1 = { :a => 1, :c => 2 }
# # h2 = { 7 => 35, :c => 2, :a => 1 }
# # h3 = { :a => 1, :c => 2, 7 => 35 }
# # h4 = { :a => 1, :d => 2, :f => 35 }
# # h1 == h2 # => false
# # h2 == h3 # => true
# # h3 == h4 # => false
# #
# def ==(other_hash)
# (length == other_hash.length) &&
# all?{|k,v| v == other_hash[k] }
# end

# Hashlike#keys
#
# Returns a new array populated with the keys from this hashlike.
Expand Down Expand Up @@ -186,6 +162,7 @@ def convert_key(key)

def self.included base
base.extend ClassMethods
base.send(:include, Gorillib::Hashlike)
end
end
end
70 changes: 37 additions & 33 deletions spec/struct/acts_as_hash_fuzz_spec.rb
Expand Up @@ -16,51 +16,55 @@
Enumerable.public_instance_methods.map(&:to_sym) +
HashlikeHelper::HASH_METHODS_MISSING_FROM_VERSION

include HashlikeFuzzingHelper
describe Gorillib::Struct::ActsAsHash do
if ENV['FULL_SPECS']
include HashlikeFuzzingHelper

describe "Hash vs Gorillib::Struct::ActsAsHash" do
before do
@total = 0
@hsh = HashlikeHelper::HASH_TO_TEST_HASHLIKE_STRUCT.dup
@hshlike = StructUsingHashlike.new.merge(HashlikeHelper::HASH_TO_TEST_HASHLIKE_STRUCT)
end
describe "vs Hash" do
before do
@total = 0
@hsh = HashlikeHelper::HASH_TO_TEST_HASHLIKE_STRUCT.dup
@hshlike = StructUsingHashlike.new.merge(HashlikeHelper::HASH_TO_TEST_HASHLIKE_STRUCT)
end

( HashlikeHelper::METHODS_TO_TEST - STRUCT_HASHLIKE_METHODS_TO_SKIP ).each do |method_to_test|
describe "##{method_to_test}" do
( HashlikeHelper::METHODS_TO_TEST - STRUCT_HASHLIKE_METHODS_TO_SKIP ).each do |method_to_test|
describe "##{method_to_test}" do

(HashlikeFuzzingHelper::INPUTS_FOR_ALL_HASHLIKES).each do |input|
next if HashlikeFuzzingHelper::SPECIAL_CASES_FOR_HASHLIKE_STRUCT[method_to_test].include?(input)
(HashlikeFuzzingHelper::INPUTS_FOR_ALL_HASHLIKES).each do |input|
next if HashlikeFuzzingHelper::SPECIAL_CASES_FOR_HASHLIKE_STRUCT[method_to_test].include?(input)

it "on #{input.inspect}" do
behaves_the_same(@hsh, @hshlike, method_to_test, input)
it "on #{input.inspect}" do
behaves_the_same(@hsh, @hshlike, method_to_test, input)
end
end
end
end
end
end
end

describe "Gorillib::HashWithIndifferentSymbolKeys vs Gorillib::Struct::ActsAsHash" do
before do
@total = 0
@hsh = Gorillib::HashWithIndifferentSymbolKeys.new_from_hash_copying_default(
HashlikeHelper::HASH_TO_TEST_HASHLIKE_STRUCT)
@hshlike = StructUsingHashlike.new.merge(
HashlikeHelper::HASH_TO_TEST_HASHLIKE_STRUCT)
end
describe "vs Gorillib::HashWithIndifferentSymbolKeys" do
before do
@total = 0
@hsh = Gorillib::HashWithIndifferentSymbolKeys.new_from_hash_copying_default(
HashlikeHelper::HASH_TO_TEST_HASHLIKE_STRUCT)
@hshlike = StructUsingHashlike.new.merge(
HashlikeHelper::HASH_TO_TEST_HASHLIKE_STRUCT)
end

( HashlikeHelper::METHODS_TO_TEST - STRUCT_HASHLIKE_METHODS_TO_SKIP
).each do |method_to_test|
describe "##{method_to_test}" do
( HashlikeHelper::METHODS_TO_TEST - STRUCT_HASHLIKE_METHODS_TO_SKIP
).each do |method_to_test|
describe "##{method_to_test}" do

( HashlikeFuzzingHelper::INPUTS_WHEN_INDIFFERENT_ACCESS +
HashlikeFuzzingHelper::INPUTS_FOR_ALL_HASHLIKES
).each do |input|
next if HashlikeFuzzingHelper::SPECIAL_CASES_FOR_HASHLIKE_STRUCT[method_to_test].include?(input)
( HashlikeFuzzingHelper::INPUTS_WHEN_INDIFFERENT_ACCESS +
HashlikeFuzzingHelper::INPUTS_FOR_ALL_HASHLIKES
).each do |input|
next if HashlikeFuzzingHelper::SPECIAL_CASES_FOR_HASHLIKE_STRUCT[method_to_test].include?(input)

it "on #{input.inspect}" do
behaves_the_same(@hsh, @hshlike, method_to_test, input)
end
it "on #{input.inspect}" do
behaves_the_same(@hsh, @hshlike, method_to_test, input)
end

end
end
end
end
end
Expand Down

0 comments on commit 301f1ec

Please sign in to comment.