stub not working

16 views
Skip to first unread message

Aashish Kiran

unread,
May 24, 2013, 8:07:45 AM5/24/13
to rubyonra...@googlegroups.com
Hi,
I am testing views. I dont understand why stubs are not working.
Can anyone help.

view code :

before(:all) do
@current_user = stub("User")
assigns[:message] = @current_user
end

output:
NoMethodError:
undefined method `stub' for #<RSpec::Cor

--
Posted via http://www.ruby-forum.com/.

Andy Lindeman

unread,
May 24, 2013, 12:13:26 PM5/24/13
to rubyonra...@googlegroups.com
On Fri, May 24, 2013 at 8:07 AM, Aashish Kiran <li...@ruby-forum.com> wrote:
> Hi,
> I am testing views. I dont understand why stubs are not working.
> Can anyone help.
>
> view code :
>
> before(:all) do
> @current_user = stub("User")
> assigns[:message] = @current_user
> end
>
> output:
> NoMethodError:
> undefined method `stub' for #<RSpec::Cor

Mocks and stubs are not meant to be used in `before(:all)`. Mocks and
stubs are reset after every example; therefore, using them in
`before(:all)` does not make too much sense.

I suggest you switch to using `before(:each)` (or just `before` which
is the same thing). In general, use `before(:each)` and avoid
`before(:all)` unless you know exactly what you're doing. Tests that
bleed state or use global state are a big smell.

--
Andy Lindeman
http://www.andylindeman.com/
Reply all
Reply to author
Forward
0 new messages