diff --git a/spec/workflow/state_spec.rb b/spec/workflow/state_spec.rb new file mode 100644 index 00000000..d340d896 --- /dev/null +++ b/spec/workflow/state_spec.rb @@ -0,0 +1,45 @@ +RSpec.describe Floe::Workflow::State do + let(:input) { {} } + let(:ctx) { Floe::Workflow::Context.new(:input => input) } + let(:state) { workflow.current_state } + # picked a state that doesn't instantly finish + let(:workflow) { make_workflow(ctx, {"WaitState" => {"Type" => "Wait", "Seconds" => 1, "Next" => "SuccessState"}, "SuccessState" => {"Type" => "Succeed"}}) } + + describe "#started?" do + it "is not started yet" do + expect(state.started?).to eq(false) + end + + it "is started" do + state.start(ctx.input) + expect(state.started?).to eq(true) + end + + it "is finished" do + state.start(ctx.input) + state.finish + + state.start(ctx.input) + expect(state.started?).to eq(true) + end + end + + describe "#finished?" do + it "is not started yet" do + expect(state.finished?).to eq(false) + end + + it "is started" do + state.start(ctx.input) + expect(state.finished?).to eq(false) + end + + it "is finished" do + state.start(ctx.input) + state.finish + + state.start(ctx.input) + expect(state.finished?).to eq(true) + end + end +end