[rspec-users] Rspec: How to mock class method

Bas Vodde basv at odd-e.com
Fri Jul 27 06:04:20 UTC 2012


Hi,

How about:

Message.should_receive(:Message.method_a).with(xxx).and_return(true)

Bas

On 27-Jul-2012, at 1:31 PM, bill gate wrote:

> Hi, I have two model: Message, User
> 
> message.rb
> ```
> class Message < ActiveRecord::Base
>  class << self
>    def method_a(args)
>      [1,2]
>    end
>  end
> end
> ```
> 
> user.rb
> ```
> class User < ActiveRecord::Base
>  def method_user
>    if Message.method_a('anythings')
>      #... some code
>    end
>  end
> end
> ```
> I want to test method_user,but I don't want to test Message#method_a
> How I can mock Message with method_a?
> 
> Thanks!
> 
> -- 
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list