diff --git a/spec/shared/workflow_base_shared.rb b/spec/shared/workflow_base_shared.rb new file mode 100644 index 00000000..53e33b42 --- /dev/null +++ b/spec/shared/workflow_base_shared.rb @@ -0,0 +1,25 @@ +shared_examples_for "WorkflowBase" do + it "raises an exception for missing States field" do + payload = {"StartAt" => "Missing"} + expect { described_class.new(payload, ["Map"]) } + .to raise_error(Floe::InvalidWorkflowError, "Map does not have required field \"States\"") + end + + it "raises an exception for missing StartAt field" do + payload = {"States" => {"First" => {"Type" => "Succeed"}}} + expect { described_class.new(payload, ["Map"]) } + .to raise_error(Floe::InvalidWorkflowError, "Map does not have required field \"StartAt\"") + end + + it "raises an exception if StartAt isn't in States" do + payload = {"StartAt" => "First", "States" => {"Second" => {"Type" => "Succeed"}}} + expect { described_class.new(payload, ["Map"]) } + .to raise_error(Floe::InvalidWorkflowError, "Map field \"StartAt\" value \"First\" is not found in \"States\"") + end + + it "raises an exception if a Next state isn't in States" do + payload = {"StartAt" => "First", "States" => {"First" => {"Type" => "Pass", "Next" => "Last"}}} + expect { described_class.new(payload, ["Map"]) } + .to raise_error(Floe::InvalidWorkflowError, "States.First field \"Next\" value \"Last\" is not found in \"States\"") + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e0044d97..5146a7b0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,6 +19,7 @@ end Dir['./spec/support/**/*.rb'].sort.each { |f| require f } +Dir['./spec/shared/**/*.rb'].sort.each { |f| require f } # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| diff --git a/spec/workflow/branch_spec.rb b/spec/workflow/branch_spec.rb new file mode 100644 index 00000000..8751462d --- /dev/null +++ b/spec/workflow/branch_spec.rb @@ -0,0 +1,3 @@ +RSpec.describe Floe::Workflow::Branch do + include_examples "WorkflowBase" +end diff --git a/spec/workflow/item_processor_spec.rb b/spec/workflow/item_processor_spec.rb index 0dd52dbc..c00c8610 100644 --- a/spec/workflow/item_processor_spec.rb +++ b/spec/workflow/item_processor_spec.rb @@ -1,25 +1,3 @@ RSpec.describe Floe::Workflow::ItemProcessor do - it "raises an exception for missing States field" do - payload = {"StartAt" => "Missing"} - expect { described_class.new(payload, ["Map"]) } - .to raise_error(Floe::InvalidWorkflowError, "Map does not have required field \"States\"") - end - - it "raises an exception for missing StartAt field" do - payload = {"States" => {"First" => {"Type" => "Succeed"}}} - expect { described_class.new(payload, ["Map"]) } - .to raise_error(Floe::InvalidWorkflowError, "Map does not have required field \"StartAt\"") - end - - it "raises an exception if StartAt isn't in States" do - payload = {"StartAt" => "First", "States" => {"Second" => {"Type" => "Succeed"}}} - expect { described_class.new(payload, ["Map"]) } - .to raise_error(Floe::InvalidWorkflowError, "Map field \"StartAt\" value \"First\" is not found in \"States\"") - end - - it "raises an exception if a Next state isn't in States" do - payload = {"StartAt" => "First", "States" => {"First" => {"Type" => "Pass", "Next" => "Last"}}} - expect { described_class.new(payload, ["Map"]) } - .to raise_error(Floe::InvalidWorkflowError, "States.First field \"Next\" value \"Last\" is not found in \"States\"") - end + include_examples "WorkflowBase" end