Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
Revert "Improve change mather detection of objects that have change…
Browse files Browse the repository at this point in the history
…d. (#1132)"

This reverts commit 443212a.
  • Loading branch information
JonRowe committed Oct 24, 2020
1 parent d2e3649 commit b0d3a4a
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 68 deletions.
50 changes: 0 additions & 50 deletions benchmarks/hashing_large_objects.rb

This file was deleted.

15 changes: 1 addition & 14 deletions lib/rspec/matchers/built_in/change.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,13 @@ def value_representation
def perform_change(event_proc)
@actual_before = evaluate_value_proc
@before_hash = @actual_before.hash
@before_attribute_hashes = calculate_attribute_hashes(@actual_before)

yield @actual_before if block_given?

return false unless Proc === event_proc
event_proc.call

@actual_after = evaluate_value_proc
@actual_hash = @actual_after.hash
@after_attribute_hashes = calculate_attribute_hashes(@actual_after)
true
end

Expand All @@ -393,9 +390,7 @@ def changed?
# possible for two values to be unequal (and of different classes)
# but to return the same hash value. Also, some objects may change
# their hash after being compared with `==`/`!=`.
@actual_before != @actual_after ||
@before_hash != @actual_hash ||
@before_attribute_hashes != @after_attribute_hashes
@actual_before != @actual_after || @before_hash != @actual_hash
end

def actual_delta
Expand All @@ -404,14 +399,6 @@ def actual_delta

private

# methods are stashed to ensure we get access to variables on modified classes / BasicObject
OBJECT_VARIABLES = Object.instance_method(:instance_variables)
OBJECT_VARIABLE_GET = Object.instance_method(:instance_variable_get)

def calculate_attribute_hashes(object)
OBJECT_VARIABLES.bind(object).call.map { |name| OBJECT_VARIABLE_GET.bind(object).call(name).hash }
end

def evaluate_value_proc
@value_proc ? @value_proc.call : @receiver.__send__(@message)
end
Expand Down
4 changes: 0 additions & 4 deletions spec/rspec/matchers/built_in/change_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,6 @@ def self.to_s
expect { @instance.some_value = 6 }.to change { @instance.some_value }
end

it "passes when actual has a value modified" do
expect { @instance.some_value = 6 }.to change { @instance }
end

it "fails when actual is not modified by the block" do
expect do
expect {}.to change { @instance.some_value }
Expand Down

0 comments on commit b0d3a4a

Please sign in to comment.