ruby on rails - Replace method implementation when stubbing with mocha -
ruby on rails - Replace method implementation when stubbing with mocha -
i'm used rspec in can stub method implementation block evalueted lazily.
now i'm working pull request project uses test::unit , mocha mocking library.
i need able similar rspec example, i.e. replace method implementation dynamic 1 depends on object state, can not utilize static calls provided mocha #returns
method.
is there way same functionality mocha, wasn't able find documentation on this?
i need implement similar (rspec 2.14 syntax)
class somecontroller < applicationcontroller before_filter :authenticate def authenticate # original method need replace end def some_other_method :bar end end describe somecontroller before controller.stub :authenticate redirect_to root_path if some_other_method == :foo end end 'should test something' controller.stub(some_other_method: :foo) :index response.should redirect_to root_path end 'should test else' :index response.should be_successful end end
can't utilize def
on controller
instance?
def controller.some_other_method :foo end
ruby-on-rails ruby testing rspec stubbing
Comments
Post a Comment