Skip to content
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

Simplify mockery and add check to include state in failure message #449

Closed
wants to merge 13 commits into from
Closed
9 changes: 6 additions & 3 deletions lib/mocha/mockery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ def state_machines

def mocha_inspect
message = ''
message << "unsatisfied expectations:\n- #{unsatisfied_expectations.map(&:mocha_inspect).join("\n- ")}\n" unless unsatisfied_expectations.empty?
message << "satisfied expectations:\n- #{satisfied_expectations.map(&:mocha_inspect).join("\n- ")}\n" unless satisfied_expectations.empty?
message << "states:\n- #{state_machines.map(&:mocha_inspect).join("\n- ")}\n" unless state_machines.empty?
[
['unsatisfied expectations', unsatisfied_expectations], ['satisfied expectations', satisfied_expectations],
['states', state_machines]
].each do |label, list|
message << "#{label}:\n- #{list.map(&:mocha_inspect).join("\n- ")}\n" unless list.empty?
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While removing the duplication here is good, I'm not convinced that the resultant code is very easy to follow.

message
end

Expand Down