[rspec-users] Making Rspec errors with anything less verbose.

Joseph Wilk josephwilk at joesniff.co.uk
Wed Oct 8 11:43:19 EDT 2008


Hello,

I was doing some work on cucumber and it hit me that this error message 
from a failed spec was a little too verbose.

The spec test is:

Cucumber::Tree::RowScenario.should_receive(:new).with(anything, 
anything, ['I can have spaces'], anything)

And when the test fails the output is:
---
Spec::Mocks::MockExpectationError in 
'Cucumber::TreetopParser::FeatureParser should allow backslashed | in 
FIT values'
Mock 'Class' expected :new with 
(#<Spec::Mocks::ArgumentConstraints::AnyArgConstraint:0x11c5a4c>, 
#<Spec::Mocks::ArgumentConstraints::AnyArgConstraint:0x11c4e94>, ["I can 
have | and its ok"], 
#<Spec::Mocks::ArgumentConstraints::AnyArgConstraint:0x11c4de0>) but 
received it with (#<Cucumber::Tree::Feature:0x11b5cc8 @header="Some 
title", @scenarios=[#<Cucumber::Tree::Scenario:0x11b5bd8 @name="second", 
@feature=#<Cucumber::Tree::Feature:0x11b5cc8 ...>, 
@steps_and_given_scenarios=[#<Cucumber::Tree::Step:0x11b5a70 
@name="'bind me please'", @keyword="Given", @line=4, 
@scenario=#<Cucumber::Tree::Scenario:0x11b5bd8 ...>>], 
@table_header=["c"]>]>, #<Cucumber::Tree::Scenario:0x11b5bd8 
@name="second", @feature=#<Cucumber::Tree::Feature:0x11b5cc8 
@header="Some title", @scenarios=[#<Cucumber::Tree::Scenario:0x11b5bd8 
...>]>, @steps_and_given_scenarios=[#<Cucumber::Tree::Step:0x11b5a70 
@name="'bind me please'", @keyword="Given", @line=4, 
@scenario=#<Cucumber::Tree::Scenario:0x11b5bd8 ...>>], 
@table_header=["c"]>, ["I can have \\", "and its ok"], 7)
---

Its a little hard to read! What I think might be more helpful is to 
replace arguments that match 'anything' with a wild card such as '_'. 
This would give me the much easier to read error message:

---
Spec::Mocks::MockExpectationError in 
'Cucumber::TreetopParser::FeatureParser should allow backslashed | in 
FIT values'
Mock 'Class' expected :new with (_, _, ["I can have | and its ok"], _) 
but received it with (_, _, ["I can have \\", "and its ok"], _)
---

So what I'm suggesting is

1. Replace:
#<Spec::Mocks::ArgumentConstraints::AnyArgConstraint:0x11c5a4c>
With: '_'

2. Replace received with parameters which are marked in the expectation 
as anything with '_'

Does that seem sensible?
Is there value to seeing arguments received when you have marked them as 
'anything'?

--
Joseph Wilk
http://www.joesniff.co.uk


More information about the rspec-users mailing list