-
-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If == matcher fails with empty Diff, error notice should be more helpful. #123
Comments
Using == we get this:
Using eq we get this:
These have the same information, just formatted differently. What is it that you would like to see? |
Why it fails. ;) Please read this again with a 100000 miles perspective: Expected A What should this mean? Whats the failure? If one expects that A equals A and it fails with: "Hey you expected A but got A with a difference of none" its not very helpful, isn't it? ;) I think a little bit more explaination would be helpful.
|
I understand the goal and the motivation. I was asking you for a recommendation on wording. How about "A == A returns true, but the objects do not report any difference." |
Call me stupid, but I think I really don't get it. The test fails, because "A == A returns true, but the objects do not report any difference."? What am I missing? |
That should have been "A == A returns false ..." |
Phew, and I thought I am loosing my mind. :) What about: "A == A haven't any difference, but returns false. Are you comparing new instances of ActiveRecord Models? Try to save them first." Or is this too specific? |
Right track but yes, too specific. How about something like: "A.==(B) returned false even though the diff between A and B is empty. Check the implementation of A.==." |
It's ok for me. But maybe some more people could share their thoughts on this. |
That just slows things down. We can always iterate on @dchelimsky's suggestion after it's released. P.S. I think @dchelimsky suggestion is plenty good enough. |
I like @dchelimsky's suggestion, too. |
@tvdeyen would you like to implement this? |
Ok, why not. But you have to guide me the right way. |
I'm having the same failure message in a spec and I would like to know what it exactly means. |
@Agis-, it's likely due to an object that overrides |
These are the actual specs: https://gist.github.com/3744048 |
Ah, that's ActiveRecord. If two ActiveRecord objects are being compared and both of their tldr: it doesn't look like |
FWIW, the message that was added here gets printed in some cases where it makes no sense. See #143. |
I see, thanks @alindeman. |
Same problem here. Inside rspec [hash] == [hash] returns false. In terminal it returns true. Looks like the implementation is working, but the spec test says otherwise. Terminal: race = Race.first
teams = race.teams.map(&:attributes)
RaceExportation.new(race).to_hash[:teams] == teams # true Inside rspec require 'spec_helper'
describe RaceExportation do
let(:race) { category.race }
let(:team) { create(:team, race: race) }
describe "#to_hash" do
subject { RaceExportation.new(race).to_hash }
it "sets :teams key" do
subject[:teams].should == [team.attributes]
end
end
end
|
Turns out it is something related to Time. As my time stubbing didnt work I did that workaround (im not very proud of it). describe RaceExportation do
def remove_times(object)
if object.class == Array
object.map{|e| remove_times(e)}
else
object.except('created_at', 'updated_at')
end
end
# let(){}..
it "sets :teams key" do
remove_times(subject[:teams]).should == remove_times([team.attributes])
end
end |
Sorry to reopen this issue but I am facing the empty diff message again...
I even checked that the created_at and updated_at times where identical to the millisecond. |
Are the times equal in ruby? Regardless of clock equalness. |
Not sure if I understand what you asked for but this returns true :
json_1 being the json created with the as_json method of stat_1. stat_1 is a mongoid entity I create at the beginning of the test. |
Same for updated_at and gist how you're comparing json_1 with stat_1? |
Here is the gist with the prints in a |
I'd guess id is a string in one and a Bson::ObjectId in another... |
No because the method is as follows :
As you may see here, I give to the method |
If the diff is empty but they are not equal it's a symptom of something being printed to_s in the diff thats not in the object, time is the usual culprit but there are others. |
Well if I fail to remove the Bson id from the Stat object in the test, I get an error but with an explicit diff that I can use :
So I guess the culprit is not in the BSON id this time, no ? |
I was thinking maybe the diff is not empty but is actually some white spaces but I have no idea what could create that and how to check that. |
Getting something similar at the moment... `Failure/Error: expect(ExpandedCompany.find(@company.id)).to eq(@expanded_company)
` Not sure why these objects are not == ? Edit: I'm using SimpleDelegator, if that could be the issue. |
@ryanwanger you have to specifically delegate 2.2.3 :001 > require 'delegate'
=> true
2.2.3 :002 > object = Object.new
=> #<Object:0x007fc8921de8b0>
2.2.3 :003 > klass = Class.new(SimpleDelegator)
=> #<Class:0x007fc89221c700>
2.2.3 :004 > klass.new(object) == klass.new(object)
=> false
2.2.3 :005 > klass.new(object).inspect
=> "#<Object:0x007fc8921de8b0>" |
It seems to depend on what is delegated: > file = File.open('/etc/passwd')
=> #<File:/etc/passwd>
> file == file
=> true
> SimpleDelegator.new(1) == SimpleDelegator.new(1)
=> true
> SimpleDelegator.new(file) == SimpleDelegator.new(file)
=> false This seems like a flaw in SimpleDelegator.new(file).__getobj__ == SimpleDelegator.new(file).__getobj__
=> true |
…cts is empty. Fixes rspec/rspec-expectations#123 This commit was imported from rspec/rspec-expectations@e12a2d9.
Comparing two objects via == that are not equal, but have no differences make rspec fail. The error notice shown is:
It would be helpful if an explanation of what's the problem shows up. Like the comparing with eq notice!
The text was updated successfully, but these errors were encountered: