ruby - When specing a namespaced class how do I stub the parent class? -
# models/event.rb class event < activerecord::base # ... end # models/event/timeline.rb class event::timeline # ... end # spec/event/timeline_spec.rb require 'spec_helper' require 'models/event/timeline' # <- fails since "event" not required describe event::timeline '' # ... end end
i not want require 'event'
since mean requiring of dependencies not nessesary spec.
you use stub_const
method rspec:
https://www.relishapp.com/rspec/rspec-mocks/v/2-13/docs/mutating-constants
but simpler use class event; end
marian suggested.
in response comment, need declared above describe
block? if not perhaps try
describe event::timeline let(:fake_class) { class.new } before stub_const("event", fake_class) end '' end end
Comments
Post a Comment