Skip to content

Commit

Permalink
Added equality for Pickle::Ref, to enable more robust specs in the Api
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwhite committed Aug 26, 2010
1 parent 9008cab commit c1041c6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/pickle/ref.rb
Expand Up @@ -32,6 +32,10 @@ def inspect
"#<Pickle::Ref '#{to_s}'>"
end

def ==(other)
[factory, index, label] == [other.factory, other.index, other.label]
end

protected
def validate!
raise InvalidPickleRefError, "#{inspect} requires a factory or label" if factory.blank? && label.blank?
Expand Down
24 changes: 24 additions & 0 deletions spec/pickle/ref_spec.rb
Expand Up @@ -13,6 +13,30 @@
end
end

describe "equality: two pickle refs are equal when their index, factory, label are equal. ie:" do
[
['the user: "fred"', {:label => "fred", :factory => 'user'}],
['user', 'another user'],
['the 2nd user', {:index => 1, :factory => 'user'}]
].each do |pair|
describe Pickle::Ref.new(pair.first).inspect do
subject { Pickle::Ref.new(pair.first) }
it { should == Pickle::Ref.new(pair.last) }
end
end

[
['the user: "geoff"', {:label => "fred", :factory => 'user'}],
['user', '1st user'],
['the 2nd user', {:index => 1, :factory => 'project'}]
].each do |pair|
describe Pickle::Ref.new(pair.first).inspect do
subject { Pickle::Ref.new(pair.first) }
it { should_not == Pickle::Ref.new(pair.last) }
end
end
end

describe "(factory) " do
shared_examples_for 'pickle ref with :factory => "colour"' do
its(:index) { should be_nil }
Expand Down

0 comments on commit c1041c6

Please sign in to comment.