Forum: RSpec Expectation ordering

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2ce9c0106b5851b2294ba5eb9f5c04bd?d=identicon&s=25 Ashley Moran (Guest)
on 2008-10-07 15:00
(Received via mailing list)
Hi

Can I still rely on this RSpec behaviour?

I've got a spec for a TCP socket client:

       it "should do things in a sane order" do
         @socket.should_receive(:write) do
           @socket.should_receive(:read) do
             @socket.should_receive(:close)
           end
         end
         @client.update_news_feeds
       end

But this passes, where I was expecting it to fail:

     def update_news_feeds
       socket = TCPSocket.new(@server, @port)
       socket.read
       socket.write("UPDATE\n")
       socket.close
     end

Has this form of expectation ordering been removed?

Thanks
Ashley

--
http://www.patchspace.co.uk/
http://aviewfromafar.net/
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2008-10-07 16:15
(Received via mailing list)
On Tue, Oct 7, 2008 at 7:59 AM, Ashley Moran
<ashley.moran@patchspace.co.uk> wrote:
>          end
>      socket.close
>    end
>
> Has this form of expectation ordering been removed?

As far as I know this form of expectation ordering was never
supported. If you've seen documentation that suggests it should be,
please point me to it so I can resolve the discrepancy.

Ordering in rspec mocks is managed with the #ordered method:

@socket.should_receive(:write).ordered
@socket.should_receive(:read).ordered
@socket.should_receive(:close).ordered

See http://rspec.info/documentation/mocks/message_expe... -
almost all the way down the page.

Cheers,
David
2ce9c0106b5851b2294ba5eb9f5c04bd?d=identicon&s=25 Ashley Moran (Guest)
on 2008-10-07 16:42
(Received via mailing list)
On 7 Oct 2008, at 15:15, David Chelimsky wrote:

> As far as I know this form of expectation ordering was never
> supported. If you've seen documentation that suggests it should be,
> please point me to it so I can resolve the discrepancy.

Aslak told me himself... on this list :o)


> Ordering in rspec mocks is managed with the #ordered method:
>
> @socket.should_receive(:write).ordered
> @socket.should_receive(:read).ordered
> @socket.should_receive(:close).ordered

I forgot about that.  When I asked on the list before it was because I
needed a way to do inter-mock ordering.  Thanks for the link, it
solved the problem in the example I gave.  Unfortunately looks like
I've lost the ability to do this:

       it "should migrate the database (after initialising it)" do
         DataMapper.should_receive(:setup) do
           Database::Migrator.should_receive(:migrate_up!)
         end
         @server.start
       end

Maybe I was the only person taking advantage of this?

Ashley

--
http://www.patchspace.co.uk/
http://aviewfromafar.net/
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2008-10-07 17:02
(Received via mailing list)
On Tue, Oct 7, 2008 at 9:40 AM, Ashley Moran
<ashley.moran@patchspace.co.uk> wrote:
>> Ordering in rspec mocks is managed with the #ordered method:
>      it "should migrate the database (after initialising it)" do
>        DataMapper.should_receive(:setup) do
>          Database::Migrator.should_receive(:migrate_up!)
>        end
>        @server.start
>      end
>
> Maybe I was the only person taking advantage of this?

Is the block no longer being executed? If so, then we have a problem
:) Please report this at http://rspec.lighthouseapp.com.

Thanks,
David
2ce9c0106b5851b2294ba5eb9f5c04bd?d=identicon&s=25 Ashley Moran (Guest)
on 2008-10-07 18:18
(Received via mailing list)
On 7 Oct 2008, at 15:55, David Chelimsky wrote:

> Is the block no longer being executed? If so, then we have a problem
> :) Please report this at http://rspec.lighthouseapp.com.

Bizarrely, my little test...

   require 'spec'

   describe "Blocks" do
     it "should be called" do
       b = mock(Object)

       b.should_receive(:this) do
         b.should_receive(:that)
       end

       b.that
       b.this
     end
   end

Works as expected (the above fails)

I'll have to investigate further...

Ashley

--
http://www.patchspace.co.uk/
http://aviewfromafar.net/
This topic is locked and can not be replied to.