Hi Sam
You solution is helpful. But actually I have modified your solution as
per my need. So I have done like this:
`````
Project.accessed_projects(current_resource) #
`````
I have stubbed as below
Project.stub(:accessed_projects).with(current_resource).and_return([FactoryGirl.create(:project)])
and I used expectation message as
expect(Project).to
have_received(:accessed_projects).with(user.resource)
Till above it's fine. However if I use 'should_receive' it throws
error as
Project.should_receive(:accessed_projects).with(user.resource) #
<Project (class)> expected to have received accessed_projects, but that
method has been mocked instead of stubbed
As per my knowledge both expectations message should pass but it
didn't. Could you please explain the reason?
On Tuesday, 7 January 2014 19:26:27 UTC+5:30, Sam Phippen wrote:
>
> Hi Siva,
>
> Have you tried
>
> ```
> allow(MyController).to
> receive(:method).with(the_arguments_you_expect).and_return(the_return_value_you_expect)
> ```
>
> you can drop the with, and the and_return as necessary.
>
> Does that answer the question?
>
> Thanks
> —
> Sam Phippen
>
> On 7 Jan 2014, at 13:41, siva <[email protected] <javascript:>> wrote:
>
>
>
> Hi Everyone
>
> I am using a model class method on my controller. How can I stub the
> class method on my controller?
>
> Thanks
> Siva
>
> --
> You received this message because you are subscribed to the Google Groups
> "rspec" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected] <javascript:>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rspec/d4246290-e544-421b-b94f-109a0b66801f%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/bd1d5a0a-1973-4acd-9375-528b217b0059%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.