require 'spec_helper' require 'timecop' module Nestene describe ScheduledMethod do describe '#new' do context "when DelayedMethod is passed as parameter" do let(:delayed_method) do method = DelayedMethod.new method.name = :some_method method.parameters = ['p1','p2'] method.uuid = 'some_uuid' method.scheduled_at = Time.now method end subject {described_class.new(delayed_method)} it "should copy method's uuid" do expect(subject.uuid).to eq(delayed_method.uuid) end it "should copy name" do expect(subject.name).to eq(delayed_method.name) end it "should copy parameters" do expect(subject.parameters).to eq(delayed_method.parameters) end end end end describe ExecutingMethod do describe :new do context "when ScheduledMethod is passed as parameter" do let (:callback) {Callback.new} let (:scheduled) do scheduled = ScheduledMethod.new scheduled.callback = callback scheduled end subject {ExecutingMethod.new(scheduled)} it "should copy callback" do expect(subject.callback).to eq(callback) end end end end describe ExecutedMethod do describe :new do context "when ExecutingMethod is passed as parameter" do let (:callback) {Callback.new} let (:executed) do executed = ExecutingMethod.new executed.callback = callback executed.started_at = Time.now executed end subject {ExecutedMethod.new(executed)} it "should copy callback" do expect(subject.callback).to eq(callback) end end end end describe ExecutionError do let(:exception) do begin raise Exception, "some message" rescue Exception => e e end end context "when no error is passed to constructur" do it "should have nil messsage" do expect(subject.message).to be_nil end it "should have nil type" do expect(subject.type).to be_nil end it "should have nil backtrace" do expect(subject.backtrace).to be_nil end end context 'when error is passed to constructor' do subject { described_class.new(exception) } it "should have message set" do expect(subject.message).to eq('some message') end it "should have type set" do expect(subject.type).to eq('Exception') end it "should have backtrace set" do expect(subject.backtrace).not_to be_empty end end describe :to_exception do subject { ExecutionError.new(exception).to_exception } it "should create" do expect(subject).to be_a(Exception) end it "should create exception with the stored messsage" do expect(subject.message).to eq("some message") end it "should create exception with a backtrace" do expect(subject.backtrace).not_to be_empty end end end end