Skip to content

Commit

Permalink
define equality
Browse files Browse the repository at this point in the history
  • Loading branch information
gladtocode committed Feb 11, 2016
1 parent 0050794 commit 7e3e87c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/strict_open_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ def method_missing(method_name, *args, &block)
fail NoMethodError, "undefined method `#{method_name}' for #{self}"
end
end

def ==(other)
@open_struct == other.instance_variable_get("@open_struct")
end
end
2 changes: 1 addition & 1 deletion strict_open_struct.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = "strict_open_struct"
spec.version = "0.0.1"
spec.version = "0.0.1.1"
spec.authors = ["Nathan Wenneker"]
spec.email = ["[email protected]"]
spec.summary = %q{Thin layer on top of OpenStruct to raise exceptions for undefined keys.}
Expand Down
13 changes: 13 additions & 0 deletions test/basic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,18 @@ def first_name
end
end

describe "#==" do
specify "equal if insantiated with same data" do
assert_equal StrictOpenStruct.new(a: 'a'), StrictOpenStruct.new(a: 'a')
end

specify "equal if has same data" do
sos1 = StrictOpenStruct.new
sos1.a = 'a'
sos2 = StrictOpenStruct.new(a: 'a')
assert_equal sos1, sos2
end
end

end

0 comments on commit 7e3e87c

Please sign in to comment.