diff --git a/lib/crono.rb b/lib/crono.rb index 6744e57..ccf9ced 100644 --- a/lib/crono.rb +++ b/lib/crono.rb @@ -4,5 +4,6 @@ end require "active_support/all" require "crono/version.rb" require "crono/period.rb" +require "crono/schedule.rb" require "crono/config.rb" require "crono/performer_proxy.rb" diff --git a/lib/crono/cli.rb b/lib/crono/cli.rb index 747e2e2..332ff20 100644 --- a/lib/crono/cli.rb +++ b/lib/crono/cli.rb @@ -7,7 +7,7 @@ module Crono def run load_rails print_banner - # start_working_loop + start_working_loop end private diff --git a/lib/crono/config.rb b/lib/crono/config.rb index 55cbbfc..809965e 100644 --- a/lib/crono/config.rb +++ b/lib/crono/config.rb @@ -5,7 +5,7 @@ module Crono attr_accessor :schedule def initialize - self.schedule = [] + self.schedule = Schedule.new end end end diff --git a/lib/crono/performer_proxy.rb b/lib/crono/performer_proxy.rb index 30fca3d..bd95a38 100644 --- a/lib/crono/performer_proxy.rb +++ b/lib/crono/performer_proxy.rb @@ -5,7 +5,7 @@ module Crono end def every(period, *args) - Config.instance.schedule += [@performer, Period.new(period, *args)] + Config.instance.schedule.add(@performer, Period.new(period, *args)) end end diff --git a/lib/crono/schedule.rb b/lib/crono/schedule.rb new file mode 100644 index 0000000..79e841b --- /dev/null +++ b/lib/crono/schedule.rb @@ -0,0 +1,10 @@ +module Crono + class Schedule + def initialize + @schedule = [] + end + + def add(peformer, period) + end + end +end diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index 7d4197d..113928f 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -9,8 +9,9 @@ describe Crono::CLI do let(:cli) { Crono::CLI.instance } describe "#run" do - it "should try to initialize rails with #load_rails" do + it "should try to initialize rails with #load_rails and start working loop" do expect(cli).to receive(:load_rails) + expect(cli).to receive(:start_working_loop) cli.run end end @@ -21,4 +22,8 @@ describe Crono::CLI do expect(thread).to be_stop end end + + describe "#start_working_loop" do + it "should start working loop" + end end diff --git a/spec/config_spec.rb b/spec/config_spec.rb index bb25b4f..32e7c1f 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -2,9 +2,9 @@ require "spec_helper" describe Crono::Config do describe "#initialize" do - it "should initialize schedule with an empty array" do + it "should initialize schedule" do @config = Crono::Config.instance - expect(@config.schedule).to eql([]) + expect(@config.schedule).to be_a(Crono::Schedule) end end end diff --git a/spec/performer_proxy_spec.rb b/spec/performer_proxy_spec.rb index c38534c..920cefe 100644 --- a/spec/performer_proxy_spec.rb +++ b/spec/performer_proxy_spec.rb @@ -6,7 +6,7 @@ end describe Crono::PerformerProxy do it "should add job and period to schedule" do + expect(Crono::Config.instance.schedule).to receive(:add).with(TestJob, kind_of(Crono::Period)) Crono.perform(TestJob).every(2.days, at: "15:30") - expect(Crono::Config.instance.schedule).to_not be_empty end end diff --git a/spec/schedule_spec.rb b/spec/schedule_spec.rb new file mode 100644 index 0000000..6e6bee7 --- /dev/null +++ b/spec/schedule_spec.rb @@ -0,0 +1,15 @@ +require "spec_helper" + +class TestJob + def perform;end +end + +describe Crono::Schedule do + describe "#add" do + it "should add an entry to schedule" do + @schedule = Crono::Schedule.new + @period = Crono::Period.new(1.day) + @schedule.add(TestJob, @period) + end + end +end