Created
January 21, 2012 15:52
-
-
Save sevos/1653127 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
require 'timebacus/use_cases/report_activity' | |
describe Timebacus::ReportActivity do | |
context 'with valid data' do | |
let(:activity) { mock(id: 5, duration: 1800, description: 'remote work') } | |
mock_const Timebacus::ReportActivity, 'Activity' do |activity_class| | |
activity_class.stub(new: activity) | |
end | |
mock_const Timebacus::ReportActivity, 'ActivityRepository' do |repository_class| | |
repository_class.stub(store: activity) | |
end | |
subject { Timebacus::ReportActivity.new 1800, 'remote work' } | |
it 'returns id of new activity' do | |
subject.execute.should eq(5) | |
end | |
it 'stores activity to repository' do | |
ActivityRepository.should_receive(:store). | |
with(activity) | |
subject.execute | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MockConst | |
def mock_const(scope, const, &block) | |
before do | |
const_val = mock | |
instance_exec(const_val, &block) | |
scope.send(:const_set, const, const_val) | |
self.class.const_set(const, const_val) | |
end | |
after do | |
scope.send(:remove_const, const) | |
self.class.send(:remove_const, const) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment