Verify message receive on an object using stubs

89 views
Skip to first unread message

siva subrahmanyam

unread,
Jan 21, 2014, 7:42:18 AM1/21/14
to minites...@googlegroups.com
 

   Hi all

   I have model class as below.

   # app/models/user.rb

     class user < ActiveRecord::Base

        def new_method
           foo
           bar
        end
      end
       
    # In test file I have written as:

    #  test/models/user_test.rb

    it "stubbing known method" do
        user = User.new
        user.stub(:foo, "Return from test foo") do
         expect(user.new_method).to_equal "Executes bar"
    end

    When I run this works fine but when I remove 'foo' method it doesn't throws any error.  Could we have any method to verify message received on user object like 'should_receive' in 'rspec'? Thanks in advance.

Mike Moore

unread,
Jan 21, 2014, 8:37:21 AM1/21/14
to minites...@googlegroups.com
You are looking for a partial mock, which is intentionally difficult in straight Minitest::Mock. Check out the following SO question:

--
-- You received this message because you are subscribed to the Google Groups minitest-rails group. To post to this group, send email to minites...@googlegroups.com. To unsubscribe from this group, send email to minitest-rail...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/minitest-rails?hl=en
---
You received this message because you are subscribed to the Google Groups "minitest-rails" group.
To unsubscribe from this group and stop receiving emails from it, send an email to minitest-rail...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages