Skip to content

Instantly share code, notes, and snippets.

@sevos
Created January 21, 2012 15:52
Show Gist options
  • Save sevos/1653127 to your computer and use it in GitHub Desktop.
Save sevos/1653127 to your computer and use it in GitHub Desktop.
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
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