tdd - rails, how to stub :user_id in session with mocha? -



tdd - rails, how to stub :user_id in session with mocha? -

how stub :user_id in session using mocha framework spec test ?

i tried following:

session.stubs(:user_id).returns(1)

session.stub!(:user_id).and_return(1)

session.expects(:[]).with(has_entries('user_id' => 1))

but got nil session[:user_id] in above tries!

all examples shows how stub object, session hash array, how stub or mock key :user_id, or :page_id .. etc in session ??

i think may have new session instance on every request, have stub every single one.

?> session.class => actioncontroller::session::abstractstore::sessionhash

so have stub is

actioncontroller::session::abstractstore::sessionhash.any_instance.stubs(:user_id).returns(1)

ruby-on-rails-3.1 tdd rspec-rails mocha

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -