[rspec-devel] [ rspec-Bugs-10260 ] Spec::Mocks::Mock#inspect returns way too much data

noreply at rubyforge.org noreply at rubyforge.org
Sun Apr 22 07:34:30 EDT 2007


Bugs item #10260, was opened at 2007-04-20 11:47
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=10260&group_id=797

Category: runner module
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 3
Submitted By: François Beausoleil (fbos)
Assigned to: Nobody (None)
Summary: Spec::Mocks::Mock#inspect returns way too much data

Initial Comment:
Hi!

This is the failure I get:

1)
Spec::Mocks::MockExpectationError in 'A POST to /v1/mongrel/heap/free?observed_at=... &data=241 should create a measurement'
Measurement expected :new with ({:node=>#<Spec::Mocks::Mock:0xb7a2a118 @name="Node_1000", @mock_handler=#<Spec::Mocks::MockHandler:0xb7a2a0f0 @proxied_methods=[:id, :to_param], @name="Node_1000",

... 85 lines elided ...

@expected_params=nil, @args=[:any_args]>, @method_block=nil>], @expectations=[], @target=#<Spec::Mocks::Mock:0xb7a25b2c ...>, @error_generator=#<Spec::Mocks::ErrorGenerator:0xb7a25a8c @name="Category_1001", @opts={}, @target=#<Spec::Mocks::Mock:0xb7a25b2c ...>>, @options={:null_object=>false, :auto_verify=>true}, @messages_received=[]>, @options={}>, :observed_at=>Fri Apr 20 15:37:37 UTC 2007, :feature=>nil})
/home/francois/src/florian/hibiscus/app/controllers/observations_controller.rb:14:in `create_v1'
./spec/controllers/observations_controller_spec.rb:67:in `do_post'
./spec/controllers/observations_controller_spec.rb:77:

My expectation is (@node and @category are mocks):
    Measurement.should_receive(:new).with(
      :node => @node, :category => @category, :feature => nil,
      :observed_at => Time.xmlschema(@time),
      :numerical_data => 241.to_f
    ).and_return(measurement = mock("observation", :save => true))

Implementing #inspect on Spec::Mocks::Mock to return a bit less data:

def inspect
  "\#<#{self.class.name} #{object_id.to_s(16)} ...>"
end

results in the following message instead:

1)
Spec::Mocks::MockExpectationError in 'A POST to /v1/mongrel/heap/free?observed_at=... &data=241 should create a measurement'
Measurement expected :new with ({:node=>#<Node -606759218 ...>, :observed_at=>Fri Apr 20 15:41:46 UTC 2007, :category=>#<Category -606783598 ...>, :feature=>nil, :numerical_data=>241.0}) but received it with ({:node=>#<Node -606759218 ...>, :textual_data=>nil, :category=>#<Category -606783598 ...>, :observed_at=>Fri Apr 20 15:41:46 UTC 2007, :feature=>nil})

Ah, so my problem is with :textual_data...  Interesting !

Bye !
François Beausoleil


----------------------------------------------------------------------

>Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2007-04-22 07:34

Message:
Applied in r1795, with minor modifications:
* Added the missing spec for this
* Used sprintf

----------------------------------------------------------------------

Comment By: Scott Taylor (smtlaissezfaire)
Date: 2007-04-21 23:16

Message:
One way to output less information on a mock is to use the --diff option (in the spec command or in your spec.opts).  Does this help your problem?

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=10260&group_id=797


More information about the rspec-devel mailing list